blob: 01deec1975923ed20052415ae52eca90b7487fc5 [file] [log] [blame]
Ted Kremenekdbdbaaf2010-03-20 21:06:02 +00001//=- AnalysisBasedWarnings.cpp - Sema warnings based on libAnalysis -*- C++ -*-=//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file defines analysis_warnings::[Policy,Executor].
11// Together they are used by Sema to issue warnings based on inexpensive
12// static analysis algorithms in libAnalysis.
13//
14//===----------------------------------------------------------------------===//
15
Douglas Gregore737f502010-08-12 20:07:10 +000016#include "clang/Sema/AnalysisBasedWarnings.h"
John McCall2d887082010-08-25 22:03:47 +000017#include "clang/Sema/SemaInternal.h"
Ted Kremenek351ba912011-02-23 01:52:04 +000018#include "clang/Sema/ScopeInfo.h"
Ted Kremenekd068aab2010-03-20 21:11:09 +000019#include "clang/Basic/SourceManager.h"
Caitlin Sadowski75f23ae2011-09-09 16:04:02 +000020#include "clang/Basic/SourceLocation.h"
Ted Kremenekfbb178a2011-01-21 19:41:46 +000021#include "clang/Lex/Preprocessor.h"
John McCall7cd088e2010-08-24 07:21:54 +000022#include "clang/AST/DeclObjC.h"
John McCall384aff82010-08-25 07:42:41 +000023#include "clang/AST/DeclCXX.h"
Ted Kremenekdbdbaaf2010-03-20 21:06:02 +000024#include "clang/AST/ExprObjC.h"
25#include "clang/AST/ExprCXX.h"
26#include "clang/AST/StmtObjC.h"
27#include "clang/AST/StmtCXX.h"
Ted Kremenek6f417152011-04-04 20:56:00 +000028#include "clang/AST/EvaluatedExprVisitor.h"
Caitlin Sadowski3ac1fbc2011-08-23 18:46:34 +000029#include "clang/AST/StmtVisitor.h"
Richard Smithe0d3b4c2012-05-03 18:27:39 +000030#include "clang/AST/RecursiveASTVisitor.h"
Ted Kremenekdbdbaaf2010-03-20 21:06:02 +000031#include "clang/Analysis/AnalysisContext.h"
32#include "clang/Analysis/CFG.h"
33#include "clang/Analysis/Analyses/ReachableCode.h"
Ted Kremenek351ba912011-02-23 01:52:04 +000034#include "clang/Analysis/Analyses/CFGReachabilityAnalysis.h"
Caitlin Sadowski402aa062011-09-09 16:11:56 +000035#include "clang/Analysis/Analyses/ThreadSafety.h"
Ted Kremenek351ba912011-02-23 01:52:04 +000036#include "clang/Analysis/CFGStmtMap.h"
Ted Kremenek6f342132011-03-15 03:17:07 +000037#include "clang/Analysis/Analyses/UninitializedValues.h"
Ted Kremenekdbdbaaf2010-03-20 21:06:02 +000038#include "llvm/ADT/BitVector.h"
Caitlin Sadowski3ac1fbc2011-08-23 18:46:34 +000039#include "llvm/ADT/FoldingSet.h"
40#include "llvm/ADT/ImmutableMap.h"
41#include "llvm/ADT/PostOrderIterator.h"
42#include "llvm/ADT/SmallVector.h"
Caitlin Sadowski75f23ae2011-09-09 16:04:02 +000043#include "llvm/ADT/StringRef.h"
Ted Kremenekdbdbaaf2010-03-20 21:06:02 +000044#include "llvm/Support/Casting.h"
Caitlin Sadowski3ac1fbc2011-08-23 18:46:34 +000045#include <algorithm>
Richard Smithe0d3b4c2012-05-03 18:27:39 +000046#include <iterator>
Caitlin Sadowski3ac1fbc2011-08-23 18:46:34 +000047#include <vector>
Richard Smithe0d3b4c2012-05-03 18:27:39 +000048#include <deque>
Ted Kremenekdbdbaaf2010-03-20 21:06:02 +000049
50using namespace clang;
51
52//===----------------------------------------------------------------------===//
53// Unreachable code analysis.
54//===----------------------------------------------------------------------===//
55
56namespace {
57 class UnreachableCodeHandler : public reachable_code::Callback {
58 Sema &S;
59 public:
60 UnreachableCodeHandler(Sema &s) : S(s) {}
61
62 void HandleUnreachable(SourceLocation L, SourceRange R1, SourceRange R2) {
63 S.Diag(L, diag::warn_unreachable) << R1 << R2;
64 }
65 };
66}
67
68/// CheckUnreachable - Check for unreachable code.
Ted Kremenek1d26f482011-10-24 01:32:45 +000069static void CheckUnreachable(Sema &S, AnalysisDeclContext &AC) {
Ted Kremenekdbdbaaf2010-03-20 21:06:02 +000070 UnreachableCodeHandler UC(S);
71 reachable_code::FindUnreachableCode(AC, UC);
72}
73
74//===----------------------------------------------------------------------===//
75// Check for missing return value.
76//===----------------------------------------------------------------------===//
77
John McCall16565aa2010-05-16 09:34:11 +000078enum ControlFlowKind {
79 UnknownFallThrough,
80 NeverFallThrough,
81 MaybeFallThrough,
82 AlwaysFallThrough,
83 NeverFallThroughOrReturn
84};
Ted Kremenekdbdbaaf2010-03-20 21:06:02 +000085
86/// CheckFallThrough - Check that we don't fall off the end of a
87/// Statement that should return a value.
88///
89/// \returns AlwaysFallThrough iff we always fall off the end of the statement,
90/// MaybeFallThrough iff we might or might not fall off the end,
91/// NeverFallThroughOrReturn iff we never fall off the end of the statement or
92/// return. We assume NeverFallThrough iff we never fall off the end of the
93/// statement but we may return. We assume that functions not marked noreturn
94/// will return.
Ted Kremenek1d26f482011-10-24 01:32:45 +000095static ControlFlowKind CheckFallThrough(AnalysisDeclContext &AC) {
Ted Kremenekdbdbaaf2010-03-20 21:06:02 +000096 CFG *cfg = AC.getCFG();
John McCall16565aa2010-05-16 09:34:11 +000097 if (cfg == 0) return UnknownFallThrough;
Ted Kremenekdbdbaaf2010-03-20 21:06:02 +000098
99 // The CFG leaves in dead things, and we don't want the dead code paths to
100 // confuse us, so we mark all live things first.
Ted Kremenekdbdbaaf2010-03-20 21:06:02 +0000101 llvm::BitVector live(cfg->getNumBlockIDs());
Ted Kremenek0f3b4ca2011-08-23 23:05:11 +0000102 unsigned count = reachable_code::ScanReachableFromBlock(&cfg->getEntry(),
Ted Kremenekdbdbaaf2010-03-20 21:06:02 +0000103 live);
104
105 bool AddEHEdges = AC.getAddEHEdges();
106 if (!AddEHEdges && count != cfg->getNumBlockIDs())
107 // When there are things remaining dead, and we didn't add EH edges
108 // from CallExprs to the catch clauses, we have to go back and
109 // mark them as live.
110 for (CFG::iterator I = cfg->begin(), E = cfg->end(); I != E; ++I) {
111 CFGBlock &b = **I;
112 if (!live[b.getBlockID()]) {
113 if (b.pred_begin() == b.pred_end()) {
114 if (b.getTerminator() && isa<CXXTryStmt>(b.getTerminator()))
115 // When not adding EH edges from calls, catch clauses
116 // can otherwise seem dead. Avoid noting them as dead.
Ted Kremenek0f3b4ca2011-08-23 23:05:11 +0000117 count += reachable_code::ScanReachableFromBlock(&b, live);
Ted Kremenekdbdbaaf2010-03-20 21:06:02 +0000118 continue;
119 }
120 }
121 }
122
123 // Now we know what is live, we check the live precessors of the exit block
124 // and look for fall through paths, being careful to ignore normal returns,
125 // and exceptional paths.
126 bool HasLiveReturn = false;
127 bool HasFakeEdge = false;
128 bool HasPlainEdge = false;
129 bool HasAbnormalEdge = false;
Ted Kremenek90b828a2010-09-09 00:06:07 +0000130
131 // Ignore default cases that aren't likely to be reachable because all
132 // enums in a switch(X) have explicit case statements.
133 CFGBlock::FilterOptions FO;
134 FO.IgnoreDefaultsWithCoveredEnums = 1;
135
136 for (CFGBlock::filtered_pred_iterator
137 I = cfg->getExit().filtered_pred_start_end(FO); I.hasMore(); ++I) {
138 const CFGBlock& B = **I;
Ted Kremenekdbdbaaf2010-03-20 21:06:02 +0000139 if (!live[B.getBlockID()])
140 continue;
Ted Kremenek5811f592011-01-26 04:49:52 +0000141
Chandler Carruthe05ee6d2011-09-13 09:53:58 +0000142 // Skip blocks which contain an element marked as no-return. They don't
143 // represent actually viable edges into the exit block, so mark them as
144 // abnormal.
145 if (B.hasNoReturnElement()) {
146 HasAbnormalEdge = true;
147 continue;
148 }
149
Ted Kremenek5811f592011-01-26 04:49:52 +0000150 // Destructors can appear after the 'return' in the CFG. This is
151 // normal. We need to look pass the destructors for the return
152 // statement (if it exists).
153 CFGBlock::const_reverse_iterator ri = B.rbegin(), re = B.rend();
Ted Kremenekc9f8f5a2011-03-02 20:32:29 +0000154
Chandler Carruthe05ee6d2011-09-13 09:53:58 +0000155 for ( ; ri != re ; ++ri)
156 if (isa<CFGStmt>(*ri))
Ted Kremenek5811f592011-01-26 04:49:52 +0000157 break;
Chandler Carruthe05ee6d2011-09-13 09:53:58 +0000158
Ted Kremenek5811f592011-01-26 04:49:52 +0000159 // No more CFGElements in the block?
160 if (ri == re) {
Ted Kremenekdbdbaaf2010-03-20 21:06:02 +0000161 if (B.getTerminator() && isa<CXXTryStmt>(B.getTerminator())) {
162 HasAbnormalEdge = true;
163 continue;
164 }
Ted Kremenekdbdbaaf2010-03-20 21:06:02 +0000165 // A labeled empty statement, or the entry block...
166 HasPlainEdge = true;
167 continue;
168 }
Ted Kremenekf39e6a32011-01-25 22:50:47 +0000169
Ted Kremenek5811f592011-01-26 04:49:52 +0000170 CFGStmt CS = cast<CFGStmt>(*ri);
Ted Kremenekf1d10d92011-08-23 23:05:04 +0000171 const Stmt *S = CS.getStmt();
Ted Kremenekdbdbaaf2010-03-20 21:06:02 +0000172 if (isa<ReturnStmt>(S)) {
173 HasLiveReturn = true;
174 continue;
175 }
176 if (isa<ObjCAtThrowStmt>(S)) {
177 HasFakeEdge = true;
178 continue;
179 }
180 if (isa<CXXThrowExpr>(S)) {
181 HasFakeEdge = true;
182 continue;
183 }
184 if (const AsmStmt *AS = dyn_cast<AsmStmt>(S)) {
185 if (AS->isMSAsm()) {
186 HasFakeEdge = true;
187 HasLiveReturn = true;
188 continue;
189 }
190 }
191 if (isa<CXXTryStmt>(S)) {
192 HasAbnormalEdge = true;
193 continue;
194 }
Chandler Carruthe05ee6d2011-09-13 09:53:58 +0000195 if (std::find(B.succ_begin(), B.succ_end(), &cfg->getExit())
196 == B.succ_end()) {
197 HasAbnormalEdge = true;
198 continue;
Ted Kremenekdbdbaaf2010-03-20 21:06:02 +0000199 }
Chandler Carruthe05ee6d2011-09-13 09:53:58 +0000200
201 HasPlainEdge = true;
Ted Kremenekdbdbaaf2010-03-20 21:06:02 +0000202 }
203 if (!HasPlainEdge) {
204 if (HasLiveReturn)
205 return NeverFallThrough;
206 return NeverFallThroughOrReturn;
207 }
208 if (HasAbnormalEdge || HasFakeEdge || HasLiveReturn)
209 return MaybeFallThrough;
210 // This says AlwaysFallThrough for calls to functions that are not marked
211 // noreturn, that don't return. If people would like this warning to be more
212 // accurate, such functions should be marked as noreturn.
213 return AlwaysFallThrough;
214}
215
Dan Gohman3c46e8d2010-07-26 21:25:24 +0000216namespace {
217
Ted Kremenekdbdbaaf2010-03-20 21:06:02 +0000218struct CheckFallThroughDiagnostics {
219 unsigned diag_MaybeFallThrough_HasNoReturn;
220 unsigned diag_MaybeFallThrough_ReturnsNonVoid;
221 unsigned diag_AlwaysFallThrough_HasNoReturn;
222 unsigned diag_AlwaysFallThrough_ReturnsNonVoid;
223 unsigned diag_NeverFallThroughOrReturn;
Douglas Gregor793cd1c2012-02-15 16:20:15 +0000224 enum { Function, Block, Lambda } funMode;
Argyrios Kyrtzidis08274082010-12-15 18:44:22 +0000225 SourceLocation FuncLoc;
Ted Kremenekd064fdc2010-03-23 00:13:23 +0000226
Douglas Gregorca7eaee2010-04-16 23:28:44 +0000227 static CheckFallThroughDiagnostics MakeForFunction(const Decl *Func) {
Ted Kremenekdbdbaaf2010-03-20 21:06:02 +0000228 CheckFallThroughDiagnostics D;
Argyrios Kyrtzidis08274082010-12-15 18:44:22 +0000229 D.FuncLoc = Func->getLocation();
Ted Kremenekdbdbaaf2010-03-20 21:06:02 +0000230 D.diag_MaybeFallThrough_HasNoReturn =
231 diag::warn_falloff_noreturn_function;
232 D.diag_MaybeFallThrough_ReturnsNonVoid =
233 diag::warn_maybe_falloff_nonvoid_function;
234 D.diag_AlwaysFallThrough_HasNoReturn =
235 diag::warn_falloff_noreturn_function;
236 D.diag_AlwaysFallThrough_ReturnsNonVoid =
237 diag::warn_falloff_nonvoid_function;
Douglas Gregorca7eaee2010-04-16 23:28:44 +0000238
239 // Don't suggest that virtual functions be marked "noreturn", since they
240 // might be overridden by non-noreturn functions.
241 bool isVirtualMethod = false;
242 if (const CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(Func))
243 isVirtualMethod = Method->isVirtual();
244
Douglas Gregorfcdd2cb2011-10-10 18:15:57 +0000245 // Don't suggest that template instantiations be marked "noreturn"
246 bool isTemplateInstantiation = false;
Ted Kremenek75df4ee2011-12-01 00:59:17 +0000247 if (const FunctionDecl *Function = dyn_cast<FunctionDecl>(Func))
248 isTemplateInstantiation = Function->isTemplateInstantiation();
Douglas Gregorfcdd2cb2011-10-10 18:15:57 +0000249
250 if (!isVirtualMethod && !isTemplateInstantiation)
Douglas Gregorca7eaee2010-04-16 23:28:44 +0000251 D.diag_NeverFallThroughOrReturn =
252 diag::warn_suggest_noreturn_function;
253 else
254 D.diag_NeverFallThroughOrReturn = 0;
255
Douglas Gregor793cd1c2012-02-15 16:20:15 +0000256 D.funMode = Function;
Ted Kremenekdbdbaaf2010-03-20 21:06:02 +0000257 return D;
258 }
Ted Kremenekd064fdc2010-03-23 00:13:23 +0000259
Ted Kremenekdbdbaaf2010-03-20 21:06:02 +0000260 static CheckFallThroughDiagnostics MakeForBlock() {
261 CheckFallThroughDiagnostics D;
262 D.diag_MaybeFallThrough_HasNoReturn =
263 diag::err_noreturn_block_has_return_expr;
264 D.diag_MaybeFallThrough_ReturnsNonVoid =
265 diag::err_maybe_falloff_nonvoid_block;
266 D.diag_AlwaysFallThrough_HasNoReturn =
267 diag::err_noreturn_block_has_return_expr;
268 D.diag_AlwaysFallThrough_ReturnsNonVoid =
269 diag::err_falloff_nonvoid_block;
270 D.diag_NeverFallThroughOrReturn =
271 diag::warn_suggest_noreturn_block;
Douglas Gregor793cd1c2012-02-15 16:20:15 +0000272 D.funMode = Block;
273 return D;
274 }
275
276 static CheckFallThroughDiagnostics MakeForLambda() {
277 CheckFallThroughDiagnostics D;
278 D.diag_MaybeFallThrough_HasNoReturn =
279 diag::err_noreturn_lambda_has_return_expr;
280 D.diag_MaybeFallThrough_ReturnsNonVoid =
281 diag::warn_maybe_falloff_nonvoid_lambda;
282 D.diag_AlwaysFallThrough_HasNoReturn =
283 diag::err_noreturn_lambda_has_return_expr;
284 D.diag_AlwaysFallThrough_ReturnsNonVoid =
285 diag::warn_falloff_nonvoid_lambda;
286 D.diag_NeverFallThroughOrReturn = 0;
287 D.funMode = Lambda;
Ted Kremenekdbdbaaf2010-03-20 21:06:02 +0000288 return D;
289 }
Ted Kremenekd064fdc2010-03-23 00:13:23 +0000290
David Blaikied6471f72011-09-25 23:23:43 +0000291 bool checkDiagnostics(DiagnosticsEngine &D, bool ReturnsVoid,
Ted Kremenekdbdbaaf2010-03-20 21:06:02 +0000292 bool HasNoReturn) const {
Douglas Gregor793cd1c2012-02-15 16:20:15 +0000293 if (funMode == Function) {
Argyrios Kyrtzidis08274082010-12-15 18:44:22 +0000294 return (ReturnsVoid ||
295 D.getDiagnosticLevel(diag::warn_maybe_falloff_nonvoid_function,
David Blaikied6471f72011-09-25 23:23:43 +0000296 FuncLoc) == DiagnosticsEngine::Ignored)
Argyrios Kyrtzidis08274082010-12-15 18:44:22 +0000297 && (!HasNoReturn ||
298 D.getDiagnosticLevel(diag::warn_noreturn_function_has_return_expr,
David Blaikied6471f72011-09-25 23:23:43 +0000299 FuncLoc) == DiagnosticsEngine::Ignored)
Argyrios Kyrtzidis08274082010-12-15 18:44:22 +0000300 && (!ReturnsVoid ||
301 D.getDiagnosticLevel(diag::warn_suggest_noreturn_block, FuncLoc)
David Blaikied6471f72011-09-25 23:23:43 +0000302 == DiagnosticsEngine::Ignored);
Ted Kremenekdbdbaaf2010-03-20 21:06:02 +0000303 }
Ted Kremenekd064fdc2010-03-23 00:13:23 +0000304
Douglas Gregor793cd1c2012-02-15 16:20:15 +0000305 // For blocks / lambdas.
306 return ReturnsVoid && !HasNoReturn
307 && ((funMode == Lambda) ||
Argyrios Kyrtzidis08274082010-12-15 18:44:22 +0000308 D.getDiagnosticLevel(diag::warn_suggest_noreturn_block, FuncLoc)
David Blaikied6471f72011-09-25 23:23:43 +0000309 == DiagnosticsEngine::Ignored);
Ted Kremenekdbdbaaf2010-03-20 21:06:02 +0000310 }
311};
312
Dan Gohman3c46e8d2010-07-26 21:25:24 +0000313}
314
Ted Kremenekdbdbaaf2010-03-20 21:06:02 +0000315/// CheckFallThroughForFunctionDef - Check that we don't fall off the end of a
316/// function that should return a value. Check that we don't fall off the end
317/// of a noreturn function. We assume that functions and blocks not marked
318/// noreturn will return.
319static void CheckFallThroughForBody(Sema &S, const Decl *D, const Stmt *Body,
Ted Kremenek3ed6fc02011-02-23 01:51:48 +0000320 const BlockExpr *blkExpr,
Ted Kremenekdbdbaaf2010-03-20 21:06:02 +0000321 const CheckFallThroughDiagnostics& CD,
Ted Kremenek1d26f482011-10-24 01:32:45 +0000322 AnalysisDeclContext &AC) {
Ted Kremenekdbdbaaf2010-03-20 21:06:02 +0000323
324 bool ReturnsVoid = false;
325 bool HasNoReturn = false;
326
327 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
328 ReturnsVoid = FD->getResultType()->isVoidType();
329 HasNoReturn = FD->hasAttr<NoReturnAttr>() ||
Rafael Espindola264ba482010-03-30 20:24:48 +0000330 FD->getType()->getAs<FunctionType>()->getNoReturnAttr();
Ted Kremenekdbdbaaf2010-03-20 21:06:02 +0000331 }
332 else if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D)) {
333 ReturnsVoid = MD->getResultType()->isVoidType();
334 HasNoReturn = MD->hasAttr<NoReturnAttr>();
335 }
336 else if (isa<BlockDecl>(D)) {
Ted Kremenek3ed6fc02011-02-23 01:51:48 +0000337 QualType BlockTy = blkExpr->getType();
Ted Kremenekd064fdc2010-03-23 00:13:23 +0000338 if (const FunctionType *FT =
Ted Kremenekdbdbaaf2010-03-20 21:06:02 +0000339 BlockTy->getPointeeType()->getAs<FunctionType>()) {
340 if (FT->getResultType()->isVoidType())
341 ReturnsVoid = true;
342 if (FT->getNoReturnAttr())
343 HasNoReturn = true;
344 }
345 }
346
David Blaikied6471f72011-09-25 23:23:43 +0000347 DiagnosticsEngine &Diags = S.getDiagnostics();
Ted Kremenekdbdbaaf2010-03-20 21:06:02 +0000348
349 // Short circuit for compilation speed.
350 if (CD.checkDiagnostics(Diags, ReturnsVoid, HasNoReturn))
351 return;
Ted Kremenekd064fdc2010-03-23 00:13:23 +0000352
Ted Kremenekdbdbaaf2010-03-20 21:06:02 +0000353 // FIXME: Function try block
354 if (const CompoundStmt *Compound = dyn_cast<CompoundStmt>(Body)) {
355 switch (CheckFallThrough(AC)) {
John McCall16565aa2010-05-16 09:34:11 +0000356 case UnknownFallThrough:
357 break;
358
Ted Kremenekdbdbaaf2010-03-20 21:06:02 +0000359 case MaybeFallThrough:
360 if (HasNoReturn)
361 S.Diag(Compound->getRBracLoc(),
362 CD.diag_MaybeFallThrough_HasNoReturn);
363 else if (!ReturnsVoid)
364 S.Diag(Compound->getRBracLoc(),
365 CD.diag_MaybeFallThrough_ReturnsNonVoid);
366 break;
367 case AlwaysFallThrough:
368 if (HasNoReturn)
369 S.Diag(Compound->getRBracLoc(),
370 CD.diag_AlwaysFallThrough_HasNoReturn);
371 else if (!ReturnsVoid)
372 S.Diag(Compound->getRBracLoc(),
373 CD.diag_AlwaysFallThrough_ReturnsNonVoid);
374 break;
375 case NeverFallThroughOrReturn:
Chandler Carruthb0656ec2011-08-31 09:01:53 +0000376 if (ReturnsVoid && !HasNoReturn && CD.diag_NeverFallThroughOrReturn) {
377 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
378 S.Diag(Compound->getLBracLoc(), CD.diag_NeverFallThroughOrReturn)
Douglas Gregorb3321092011-09-10 00:56:20 +0000379 << 0 << FD;
380 } else if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D)) {
381 S.Diag(Compound->getLBracLoc(), CD.diag_NeverFallThroughOrReturn)
382 << 1 << MD;
Chandler Carruthb0656ec2011-08-31 09:01:53 +0000383 } else {
384 S.Diag(Compound->getLBracLoc(), CD.diag_NeverFallThroughOrReturn);
385 }
386 }
Ted Kremenekdbdbaaf2010-03-20 21:06:02 +0000387 break;
388 case NeverFallThrough:
389 break;
390 }
391 }
392}
393
394//===----------------------------------------------------------------------===//
Ted Kremenek610068c2011-01-15 02:58:47 +0000395// -Wuninitialized
396//===----------------------------------------------------------------------===//
397
Ted Kremenek6f417152011-04-04 20:56:00 +0000398namespace {
Chandler Carruth9f649462011-04-05 06:48:00 +0000399/// ContainsReference - A visitor class to search for references to
400/// a particular declaration (the needle) within any evaluated component of an
401/// expression (recursively).
Ted Kremenek6f417152011-04-04 20:56:00 +0000402class ContainsReference : public EvaluatedExprVisitor<ContainsReference> {
Chandler Carruth9f649462011-04-05 06:48:00 +0000403 bool FoundReference;
404 const DeclRefExpr *Needle;
405
Ted Kremenek6f417152011-04-04 20:56:00 +0000406public:
Chandler Carruth9f649462011-04-05 06:48:00 +0000407 ContainsReference(ASTContext &Context, const DeclRefExpr *Needle)
408 : EvaluatedExprVisitor<ContainsReference>(Context),
409 FoundReference(false), Needle(Needle) {}
410
411 void VisitExpr(Expr *E) {
Ted Kremenek6f417152011-04-04 20:56:00 +0000412 // Stop evaluating if we already have a reference.
Chandler Carruth9f649462011-04-05 06:48:00 +0000413 if (FoundReference)
Ted Kremenek6f417152011-04-04 20:56:00 +0000414 return;
Chandler Carruth9f649462011-04-05 06:48:00 +0000415
416 EvaluatedExprVisitor<ContainsReference>::VisitExpr(E);
Ted Kremenek6f417152011-04-04 20:56:00 +0000417 }
Chandler Carruth9f649462011-04-05 06:48:00 +0000418
419 void VisitDeclRefExpr(DeclRefExpr *E) {
420 if (E == Needle)
421 FoundReference = true;
422 else
423 EvaluatedExprVisitor<ContainsReference>::VisitDeclRefExpr(E);
Ted Kremenek6f417152011-04-04 20:56:00 +0000424 }
Chandler Carruth9f649462011-04-05 06:48:00 +0000425
426 bool doesContainReference() const { return FoundReference; }
Ted Kremenek6f417152011-04-04 20:56:00 +0000427};
428}
429
David Blaikie4f4f3492011-09-10 05:35:08 +0000430static bool SuggestInitializationFixit(Sema &S, const VarDecl *VD) {
Fariborz Jahaniana34194f2012-03-08 00:22:50 +0000431 QualType VariableTy = VD->getType().getCanonicalType();
432 if (VariableTy->isBlockPointerType() &&
433 !VD->hasAttr<BlocksAttr>()) {
434 S.Diag(VD->getLocation(), diag::note_block_var_fixit_add_initialization) << VD->getDeclName()
435 << FixItHint::CreateInsertion(VD->getLocation(), "__block ");
436 return true;
437 }
438
David Blaikie4f4f3492011-09-10 05:35:08 +0000439 // Don't issue a fixit if there is already an initializer.
440 if (VD->getInit())
441 return false;
Fariborz Jahaniana34194f2012-03-08 00:22:50 +0000442
David Blaikie4f4f3492011-09-10 05:35:08 +0000443 // Suggest possible initialization (if any).
David Blaikie2c0abf42012-04-30 18:27:22 +0000444 std::string Init = S.getFixItZeroInitializerForType(VariableTy);
445 if (Init.empty())
David Blaikie4f4f3492011-09-10 05:35:08 +0000446 return false;
Richard Trieu7b0a3e32012-05-03 01:09:59 +0000447
448 // Don't suggest a fixit inside macros.
449 if (VD->getLocEnd().isMacroID())
450 return false;
451
Richard Smith7984de32012-01-12 23:53:29 +0000452 SourceLocation Loc = S.PP.getLocForEndOfToken(VD->getLocEnd());
Fariborz Jahaniana34194f2012-03-08 00:22:50 +0000453
Richard Smith7984de32012-01-12 23:53:29 +0000454 S.Diag(Loc, diag::note_var_fixit_add_initialization) << VD->getDeclName()
455 << FixItHint::CreateInsertion(Loc, Init);
456 return true;
David Blaikie4f4f3492011-09-10 05:35:08 +0000457}
458
Chandler Carruth262d50e2011-04-05 18:27:05 +0000459/// DiagnoseUninitializedUse -- Helper function for diagnosing uses of an
460/// uninitialized variable. This manages the different forms of diagnostic
461/// emitted for particular types of uses. Returns true if the use was diagnosed
462/// as a warning. If a pariticular use is one we omit warnings for, returns
463/// false.
464static bool DiagnoseUninitializedUse(Sema &S, const VarDecl *VD,
Ted Kremenek9e761722011-10-13 18:50:06 +0000465 const Expr *E, bool isAlwaysUninit,
466 bool alwaysReportSelfInit = false) {
Chandler Carruth4c4983b2011-04-05 18:18:05 +0000467
468 if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E)) {
Richard Trieuf6278e52012-05-09 21:08:22 +0000469 // Inspect the initializer of the variable declaration which is
470 // being referenced prior to its initialization. We emit
471 // specialized diagnostics for self-initialization, and we
472 // specifically avoid warning about self references which take the
473 // form of:
474 //
475 // int x = x;
476 //
477 // This is used to indicate to GCC that 'x' is intentionally left
478 // uninitialized. Proven code paths which access 'x' in
479 // an uninitialized state after this will still warn.
480 if (const Expr *Initializer = VD->getInit()) {
481 if (!alwaysReportSelfInit && DRE == Initializer->IgnoreParenImpCasts())
482 return false;
Chandler Carruth4c4983b2011-04-05 18:18:05 +0000483
Richard Trieuf6278e52012-05-09 21:08:22 +0000484 ContainsReference CR(S.Context, DRE);
485 CR.Visit(const_cast<Expr*>(Initializer));
486 if (CR.doesContainReference()) {
Chandler Carruth4c4983b2011-04-05 18:18:05 +0000487 S.Diag(DRE->getLocStart(),
488 diag::warn_uninit_self_reference_in_init)
Richard Trieuf6278e52012-05-09 21:08:22 +0000489 << VD->getDeclName() << VD->getLocation() << DRE->getSourceRange();
490 return true;
Chandler Carruth4c4983b2011-04-05 18:18:05 +0000491 }
Chandler Carruth4c4983b2011-04-05 18:18:05 +0000492 }
Richard Trieuf6278e52012-05-09 21:08:22 +0000493
494 S.Diag(DRE->getLocStart(), isAlwaysUninit ? diag::warn_uninit_var
495 : diag::warn_maybe_uninit_var)
496 << VD->getDeclName() << DRE->getSourceRange();
Chandler Carruth4c4983b2011-04-05 18:18:05 +0000497 } else {
498 const BlockExpr *BE = cast<BlockExpr>(E);
Fariborz Jahaniana34194f2012-03-08 00:22:50 +0000499 if (VD->getType()->isBlockPointerType() &&
500 !VD->hasAttr<BlocksAttr>())
501 S.Diag(BE->getLocStart(), diag::warn_uninit_byref_blockvar_captured_by_block)
502 << VD->getDeclName();
503 else
504 S.Diag(BE->getLocStart(),
505 isAlwaysUninit ? diag::warn_uninit_var_captured_by_block
506 : diag::warn_maybe_uninit_var_captured_by_block)
507 << VD->getDeclName();
Chandler Carruth4c4983b2011-04-05 18:18:05 +0000508 }
509
510 // Report where the variable was declared when the use wasn't within
David Blaikie4f4f3492011-09-10 05:35:08 +0000511 // the initializer of that declaration & we didn't already suggest
512 // an initialization fixit.
Richard Trieuf6278e52012-05-09 21:08:22 +0000513 if (!SuggestInitializationFixit(S, VD))
Chandler Carruth4c4983b2011-04-05 18:18:05 +0000514 S.Diag(VD->getLocStart(), diag::note_uninit_var_def)
515 << VD->getDeclName();
516
Chandler Carruth262d50e2011-04-05 18:27:05 +0000517 return true;
Chandler Carruth64fb9592011-04-05 18:18:08 +0000518}
519
Richard Smithe0d3b4c2012-05-03 18:27:39 +0000520namespace {
521 class FallthroughMapper : public RecursiveASTVisitor<FallthroughMapper> {
522 public:
523 FallthroughMapper(Sema &S)
524 : FoundSwitchStatements(false),
525 S(S) {
526 }
527
528 bool foundSwitchStatements() const { return FoundSwitchStatements; }
529
530 void markFallthroughVisited(const AttributedStmt *Stmt) {
531 bool Found = FallthroughStmts.erase(Stmt);
532 assert(Found);
Kaelyn Uhrain3bb29942012-05-03 19:46:38 +0000533 (void)Found;
Richard Smithe0d3b4c2012-05-03 18:27:39 +0000534 }
535
536 typedef llvm::SmallPtrSet<const AttributedStmt*, 8> AttrStmts;
537
538 const AttrStmts &getFallthroughStmts() const {
539 return FallthroughStmts;
540 }
541
542 bool checkFallThroughIntoBlock(const CFGBlock &B, int &AnnotatedCnt) {
543 int UnannotatedCnt = 0;
544 AnnotatedCnt = 0;
545
546 std::deque<const CFGBlock*> BlockQueue;
547
548 std::copy(B.pred_begin(), B.pred_end(), std::back_inserter(BlockQueue));
549
550 while (!BlockQueue.empty()) {
551 const CFGBlock *P = BlockQueue.front();
552 BlockQueue.pop_front();
553
554 const Stmt *Term = P->getTerminator();
555 if (Term && isa<SwitchStmt>(Term))
556 continue; // Switch statement, good.
557
558 const SwitchCase *SW = dyn_cast_or_null<SwitchCase>(P->getLabel());
559 if (SW && SW->getSubStmt() == B.getLabel() && P->begin() == P->end())
560 continue; // Previous case label has no statements, good.
561
562 if (P->pred_begin() == P->pred_end()) { // The block is unreachable.
563 // This only catches trivially unreachable blocks.
564 for (CFGBlock::const_iterator ElIt = P->begin(), ElEnd = P->end();
565 ElIt != ElEnd; ++ElIt) {
566 if (const CFGStmt *CS = ElIt->getAs<CFGStmt>()){
567 if (const AttributedStmt *AS = asFallThroughAttr(CS->getStmt())) {
568 S.Diag(AS->getLocStart(),
569 diag::warn_fallthrough_attr_unreachable);
570 markFallthroughVisited(AS);
571 ++AnnotatedCnt;
572 }
573 // Don't care about other unreachable statements.
574 }
575 }
576 // If there are no unreachable statements, this may be a special
577 // case in CFG:
578 // case X: {
579 // A a; // A has a destructor.
580 // break;
581 // }
582 // // <<<< This place is represented by a 'hanging' CFG block.
583 // case Y:
584 continue;
585 }
586
587 const Stmt *LastStmt = getLastStmt(*P);
588 if (const AttributedStmt *AS = asFallThroughAttr(LastStmt)) {
589 markFallthroughVisited(AS);
590 ++AnnotatedCnt;
591 continue; // Fallthrough annotation, good.
592 }
593
594 if (!LastStmt) { // This block contains no executable statements.
595 // Traverse its predecessors.
596 std::copy(P->pred_begin(), P->pred_end(),
597 std::back_inserter(BlockQueue));
598 continue;
599 }
600
601 ++UnannotatedCnt;
602 }
603 return !!UnannotatedCnt;
604 }
605
606 // RecursiveASTVisitor setup.
607 bool shouldWalkTypesOfTypeLocs() const { return false; }
608
609 bool VisitAttributedStmt(AttributedStmt *S) {
610 if (asFallThroughAttr(S))
611 FallthroughStmts.insert(S);
612 return true;
613 }
614
615 bool VisitSwitchStmt(SwitchStmt *S) {
616 FoundSwitchStatements = true;
617 return true;
618 }
619
620 private:
621
622 static const AttributedStmt *asFallThroughAttr(const Stmt *S) {
623 if (const AttributedStmt *AS = dyn_cast_or_null<AttributedStmt>(S)) {
624 if (hasSpecificAttr<FallThroughAttr>(AS->getAttrs()))
625 return AS;
626 }
627 return 0;
628 }
629
630 static const Stmt *getLastStmt(const CFGBlock &B) {
631 if (const Stmt *Term = B.getTerminator())
632 return Term;
633 for (CFGBlock::const_reverse_iterator ElemIt = B.rbegin(),
634 ElemEnd = B.rend();
635 ElemIt != ElemEnd; ++ElemIt) {
636 if (const CFGStmt *CS = ElemIt->getAs<CFGStmt>())
637 return CS->getStmt();
638 }
639 // Workaround to detect a statement thrown out by CFGBuilder:
640 // case X: {} case Y:
641 // case X: ; case Y:
642 if (const SwitchCase *SW = dyn_cast_or_null<SwitchCase>(B.getLabel()))
643 if (!isa<SwitchCase>(SW->getSubStmt()))
644 return SW->getSubStmt();
645
646 return 0;
647 }
648
649 bool FoundSwitchStatements;
650 AttrStmts FallthroughStmts;
651 Sema &S;
652 };
653}
654
655static void DiagnoseSwitchLabelsFallthrough(Sema &S, AnalysisDeclContext &AC) {
656 FallthroughMapper FM(S);
657 FM.TraverseStmt(AC.getBody());
658
659 if (!FM.foundSwitchStatements())
660 return;
661
662 CFG *Cfg = AC.getCFG();
663
664 if (!Cfg)
665 return;
666
667 int AnnotatedCnt;
668
669 for (CFG::reverse_iterator I = Cfg->rbegin(), E = Cfg->rend(); I != E; ++I) {
670 const CFGBlock &B = **I;
671 const Stmt *Label = B.getLabel();
672
673 if (!Label || !isa<SwitchCase>(Label))
674 continue;
675
676 if (!FM.checkFallThroughIntoBlock(B, AnnotatedCnt))
677 continue;
678
679 S.Diag(Label->getLocStart(), diag::warn_unannotated_fallthrough);
680
681 if (!AnnotatedCnt) {
682 SourceLocation L = Label->getLocStart();
683 if (L.isMacroID())
684 continue;
685 if (S.getLangOpts().CPlusPlus0x) {
686 S.Diag(L, diag::note_insert_fallthrough_fixit) <<
687 FixItHint::CreateInsertion(L, "[[clang::fallthrough]]; ");
688 }
689 S.Diag(L, diag::note_insert_break_fixit) <<
690 FixItHint::CreateInsertion(L, "break; ");
691 }
692 }
693
694 const FallthroughMapper::AttrStmts &Fallthroughs = FM.getFallthroughStmts();
695 for (FallthroughMapper::AttrStmts::const_iterator I = Fallthroughs.begin(),
696 E = Fallthroughs.end();
697 I != E; ++I) {
698 S.Diag((*I)->getLocStart(), diag::warn_fallthrough_attr_invalid_placement);
699 }
700
701}
702
Ted Kremenekf7bafc72011-03-15 04:57:38 +0000703typedef std::pair<const Expr*, bool> UninitUse;
704
Ted Kremenek610068c2011-01-15 02:58:47 +0000705namespace {
Ted Kremenek94b1b4d2011-01-21 19:41:41 +0000706struct SLocSort {
Ted Kremenekf7bafc72011-03-15 04:57:38 +0000707 bool operator()(const UninitUse &a, const UninitUse &b) {
708 SourceLocation aLoc = a.first->getLocStart();
709 SourceLocation bLoc = b.first->getLocStart();
Ted Kremenek94b1b4d2011-01-21 19:41:41 +0000710 return aLoc.getRawEncoding() < bLoc.getRawEncoding();
711 }
712};
713
Ted Kremenek610068c2011-01-15 02:58:47 +0000714class UninitValsDiagReporter : public UninitVariablesHandler {
715 Sema &S;
Chris Lattner5f9e2722011-07-23 10:55:15 +0000716 typedef SmallVector<UninitUse, 2> UsesVec;
Ted Kremenek9e761722011-10-13 18:50:06 +0000717 typedef llvm::DenseMap<const VarDecl *, std::pair<UsesVec*, bool> > UsesMap;
Ted Kremenek94b1b4d2011-01-21 19:41:41 +0000718 UsesMap *uses;
719
Ted Kremenek610068c2011-01-15 02:58:47 +0000720public:
Ted Kremenek94b1b4d2011-01-21 19:41:41 +0000721 UninitValsDiagReporter(Sema &S) : S(S), uses(0) {}
722 ~UninitValsDiagReporter() {
723 flushDiagnostics();
724 }
Ted Kremenek9e761722011-10-13 18:50:06 +0000725
726 std::pair<UsesVec*, bool> &getUses(const VarDecl *vd) {
Ted Kremenek94b1b4d2011-01-21 19:41:41 +0000727 if (!uses)
728 uses = new UsesMap();
Ted Kremenek9e761722011-10-13 18:50:06 +0000729
730 UsesMap::mapped_type &V = (*uses)[vd];
731 UsesVec *&vec = V.first;
Ted Kremenek94b1b4d2011-01-21 19:41:41 +0000732 if (!vec)
733 vec = new UsesVec();
734
Ted Kremenek9e761722011-10-13 18:50:06 +0000735 return V;
736 }
737
738 void handleUseOfUninitVariable(const Expr *ex, const VarDecl *vd,
739 bool isAlwaysUninit) {
740 getUses(vd).first->push_back(std::make_pair(ex, isAlwaysUninit));
741 }
742
743 void handleSelfInit(const VarDecl *vd) {
744 getUses(vd).second = true;
Ted Kremenek94b1b4d2011-01-21 19:41:41 +0000745 }
746
747 void flushDiagnostics() {
748 if (!uses)
749 return;
Ted Kremenek609e3172011-02-02 23:35:53 +0000750
Richard Smith81891882012-05-24 23:45:35 +0000751 // FIXME: This iteration order, and thus the resulting diagnostic order,
752 // is nondeterministic.
Ted Kremenek94b1b4d2011-01-21 19:41:41 +0000753 for (UsesMap::iterator i = uses->begin(), e = uses->end(); i != e; ++i) {
754 const VarDecl *vd = i->first;
Ted Kremenek9e761722011-10-13 18:50:06 +0000755 const UsesMap::mapped_type &V = i->second;
Ted Kremenek609e3172011-02-02 23:35:53 +0000756
Ted Kremenek9e761722011-10-13 18:50:06 +0000757 UsesVec *vec = V.first;
758 bool hasSelfInit = V.second;
759
760 // Specially handle the case where we have uses of an uninitialized
761 // variable, but the root cause is an idiomatic self-init. We want
762 // to report the diagnostic at the self-init since that is the root cause.
Matt Beaumont-Gay0d381812011-10-19 18:53:03 +0000763 if (!vec->empty() && hasSelfInit && hasAlwaysUninitializedUse(vec))
Ted Kremenek9e761722011-10-13 18:50:06 +0000764 DiagnoseUninitializedUse(S, vd, vd->getInit()->IgnoreParenCasts(),
Matt Beaumont-Gay0d381812011-10-19 18:53:03 +0000765 /* isAlwaysUninit */ true,
766 /* alwaysReportSelfInit */ true);
Ted Kremenek9e761722011-10-13 18:50:06 +0000767 else {
768 // Sort the uses by their SourceLocations. While not strictly
769 // guaranteed to produce them in line/column order, this will provide
770 // a stable ordering.
771 std::sort(vec->begin(), vec->end(), SLocSort());
772
773 for (UsesVec::iterator vi = vec->begin(), ve = vec->end(); vi != ve;
774 ++vi) {
775 if (DiagnoseUninitializedUse(S, vd, vi->first,
776 /*isAlwaysUninit=*/vi->second))
777 // Skip further diagnostics for this variable. We try to warn only
778 // on the first point at which a variable is used uninitialized.
779 break;
780 }
Chandler Carruth64fb9592011-04-05 18:18:08 +0000781 }
Ted Kremenek9e761722011-10-13 18:50:06 +0000782
783 // Release the uses vector.
Ted Kremenek94b1b4d2011-01-21 19:41:41 +0000784 delete vec;
785 }
786 delete uses;
Ted Kremenek610068c2011-01-15 02:58:47 +0000787 }
Matt Beaumont-Gay0d381812011-10-19 18:53:03 +0000788
789private:
790 static bool hasAlwaysUninitializedUse(const UsesVec* vec) {
791 for (UsesVec::const_iterator i = vec->begin(), e = vec->end(); i != e; ++i) {
792 if (i->second) {
793 return true;
794 }
795 }
796 return false;
797}
Ted Kremenek610068c2011-01-15 02:58:47 +0000798};
799}
800
Caitlin Sadowski3ac1fbc2011-08-23 18:46:34 +0000801
802//===----------------------------------------------------------------------===//
803// -Wthread-safety
804//===----------------------------------------------------------------------===//
Caitlin Sadowski75f23ae2011-09-09 16:04:02 +0000805namespace clang {
806namespace thread_safety {
Richard Smith2e515622012-02-03 04:45:26 +0000807typedef llvm::SmallVector<PartialDiagnosticAt, 1> OptionalNotes;
808typedef std::pair<PartialDiagnosticAt, OptionalNotes> DelayedDiag;
Benjamin Kramerecafd302012-03-26 14:05:40 +0000809typedef std::list<DelayedDiag> DiagList;
Caitlin Sadowski75f23ae2011-09-09 16:04:02 +0000810
Caitlin Sadowski75f23ae2011-09-09 16:04:02 +0000811struct SortDiagBySourceLocation {
Benjamin Kramerecafd302012-03-26 14:05:40 +0000812 SourceManager &SM;
813 SortDiagBySourceLocation(SourceManager &SM) : SM(SM) {}
Caitlin Sadowski75f23ae2011-09-09 16:04:02 +0000814
815 bool operator()(const DelayedDiag &left, const DelayedDiag &right) {
816 // Although this call will be slow, this is only called when outputting
817 // multiple warnings.
Benjamin Kramerecafd302012-03-26 14:05:40 +0000818 return SM.isBeforeInTranslationUnit(left.first.first, right.first.first);
Caitlin Sadowski75f23ae2011-09-09 16:04:02 +0000819 }
820};
821
David Blaikie99ba9e32011-12-20 02:48:34 +0000822namespace {
Caitlin Sadowski75f23ae2011-09-09 16:04:02 +0000823class ThreadSafetyReporter : public clang::thread_safety::ThreadSafetyHandler {
824 Sema &S;
825 DiagList Warnings;
Richard Smith2e515622012-02-03 04:45:26 +0000826 SourceLocation FunLocation, FunEndLocation;
Caitlin Sadowski75f23ae2011-09-09 16:04:02 +0000827
828 // Helper functions
829 void warnLockMismatch(unsigned DiagID, Name LockName, SourceLocation Loc) {
DeLesley Hutchinsf1ac6372011-10-21 18:10:14 +0000830 // Gracefully handle rare cases when the analysis can't get a more
831 // precise source location.
832 if (!Loc.isValid())
833 Loc = FunLocation;
Richard Smith2e515622012-02-03 04:45:26 +0000834 PartialDiagnosticAt Warning(Loc, S.PDiag(DiagID) << LockName);
835 Warnings.push_back(DelayedDiag(Warning, OptionalNotes()));
Caitlin Sadowski75f23ae2011-09-09 16:04:02 +0000836 }
837
838 public:
Richard Smith2e515622012-02-03 04:45:26 +0000839 ThreadSafetyReporter(Sema &S, SourceLocation FL, SourceLocation FEL)
840 : S(S), FunLocation(FL), FunEndLocation(FEL) {}
Caitlin Sadowski75f23ae2011-09-09 16:04:02 +0000841
842 /// \brief Emit all buffered diagnostics in order of sourcelocation.
843 /// We need to output diagnostics produced while iterating through
844 /// the lockset in deterministic order, so this function orders diagnostics
845 /// and outputs them.
846 void emitDiagnostics() {
Benjamin Kramerecafd302012-03-26 14:05:40 +0000847 Warnings.sort(SortDiagBySourceLocation(S.getSourceManager()));
Caitlin Sadowski75f23ae2011-09-09 16:04:02 +0000848 for (DiagList::iterator I = Warnings.begin(), E = Warnings.end();
Richard Smith2e515622012-02-03 04:45:26 +0000849 I != E; ++I) {
850 S.Diag(I->first.first, I->first.second);
851 const OptionalNotes &Notes = I->second;
852 for (unsigned NoteI = 0, NoteN = Notes.size(); NoteI != NoteN; ++NoteI)
853 S.Diag(Notes[NoteI].first, Notes[NoteI].second);
854 }
Caitlin Sadowski75f23ae2011-09-09 16:04:02 +0000855 }
856
Caitlin Sadowski99107eb2011-09-09 16:21:55 +0000857 void handleInvalidLockExp(SourceLocation Loc) {
Richard Smith2e515622012-02-03 04:45:26 +0000858 PartialDiagnosticAt Warning(Loc,
859 S.PDiag(diag::warn_cannot_resolve_lock) << Loc);
860 Warnings.push_back(DelayedDiag(Warning, OptionalNotes()));
Caitlin Sadowski99107eb2011-09-09 16:21:55 +0000861 }
Caitlin Sadowski75f23ae2011-09-09 16:04:02 +0000862 void handleUnmatchedUnlock(Name LockName, SourceLocation Loc) {
863 warnLockMismatch(diag::warn_unlock_but_no_lock, LockName, Loc);
864 }
865
866 void handleDoubleLock(Name LockName, SourceLocation Loc) {
867 warnLockMismatch(diag::warn_double_lock, LockName, Loc);
868 }
869
Richard Smith2e515622012-02-03 04:45:26 +0000870 void handleMutexHeldEndOfScope(Name LockName, SourceLocation LocLocked,
871 SourceLocation LocEndOfScope,
Caitlin Sadowski4e4bc752011-09-15 17:25:19 +0000872 LockErrorKind LEK){
873 unsigned DiagID = 0;
874 switch (LEK) {
875 case LEK_LockedSomePredecessors:
Richard Smith2e515622012-02-03 04:45:26 +0000876 DiagID = diag::warn_lock_some_predecessors;
Caitlin Sadowski4e4bc752011-09-15 17:25:19 +0000877 break;
878 case LEK_LockedSomeLoopIterations:
879 DiagID = diag::warn_expecting_lock_held_on_loop;
880 break;
881 case LEK_LockedAtEndOfFunction:
882 DiagID = diag::warn_no_unlock;
883 break;
884 }
Richard Smith2e515622012-02-03 04:45:26 +0000885 if (LocEndOfScope.isInvalid())
886 LocEndOfScope = FunEndLocation;
887
888 PartialDiagnosticAt Warning(LocEndOfScope, S.PDiag(DiagID) << LockName);
889 PartialDiagnosticAt Note(LocLocked, S.PDiag(diag::note_locked_here));
890 Warnings.push_back(DelayedDiag(Warning, OptionalNotes(1, Note)));
Caitlin Sadowski75f23ae2011-09-09 16:04:02 +0000891 }
892
Caitlin Sadowski75f23ae2011-09-09 16:04:02 +0000893
894 void handleExclusiveAndShared(Name LockName, SourceLocation Loc1,
895 SourceLocation Loc2) {
Richard Smith2e515622012-02-03 04:45:26 +0000896 PartialDiagnosticAt Warning(
897 Loc1, S.PDiag(diag::warn_lock_exclusive_and_shared) << LockName);
898 PartialDiagnosticAt Note(
899 Loc2, S.PDiag(diag::note_lock_exclusive_and_shared) << LockName);
900 Warnings.push_back(DelayedDiag(Warning, OptionalNotes(1, Note)));
Caitlin Sadowski75f23ae2011-09-09 16:04:02 +0000901 }
902
903 void handleNoMutexHeld(const NamedDecl *D, ProtectedOperationKind POK,
904 AccessKind AK, SourceLocation Loc) {
Caitlin Sadowskidf8327c2011-09-14 20:09:09 +0000905 assert((POK == POK_VarAccess || POK == POK_VarDereference)
906 && "Only works for variables");
907 unsigned DiagID = POK == POK_VarAccess?
908 diag::warn_variable_requires_any_lock:
909 diag::warn_var_deref_requires_any_lock;
Richard Smith2e515622012-02-03 04:45:26 +0000910 PartialDiagnosticAt Warning(Loc, S.PDiag(DiagID)
911 << D->getName() << getLockKindFromAccessKind(AK));
912 Warnings.push_back(DelayedDiag(Warning, OptionalNotes()));
Caitlin Sadowski75f23ae2011-09-09 16:04:02 +0000913 }
914
915 void handleMutexNotHeld(const NamedDecl *D, ProtectedOperationKind POK,
916 Name LockName, LockKind LK, SourceLocation Loc) {
Caitlin Sadowskie87158d2011-09-13 18:01:58 +0000917 unsigned DiagID = 0;
Caitlin Sadowski75f23ae2011-09-09 16:04:02 +0000918 switch (POK) {
919 case POK_VarAccess:
920 DiagID = diag::warn_variable_requires_lock;
921 break;
922 case POK_VarDereference:
923 DiagID = diag::warn_var_deref_requires_lock;
924 break;
925 case POK_FunctionCall:
926 DiagID = diag::warn_fun_requires_lock;
927 break;
928 }
Richard Smith2e515622012-02-03 04:45:26 +0000929 PartialDiagnosticAt Warning(Loc, S.PDiag(DiagID)
930 << D->getName() << LockName << LK);
931 Warnings.push_back(DelayedDiag(Warning, OptionalNotes()));
Caitlin Sadowski75f23ae2011-09-09 16:04:02 +0000932 }
933
934 void handleFunExcludesLock(Name FunName, Name LockName, SourceLocation Loc) {
Richard Smith2e515622012-02-03 04:45:26 +0000935 PartialDiagnosticAt Warning(Loc,
936 S.PDiag(diag::warn_fun_excludes_mutex) << FunName << LockName);
937 Warnings.push_back(DelayedDiag(Warning, OptionalNotes()));
Caitlin Sadowski75f23ae2011-09-09 16:04:02 +0000938 }
939};
940}
941}
David Blaikie99ba9e32011-12-20 02:48:34 +0000942}
Caitlin Sadowski75f23ae2011-09-09 16:04:02 +0000943
Ted Kremenek610068c2011-01-15 02:58:47 +0000944//===----------------------------------------------------------------------===//
Ted Kremenekdbdbaaf2010-03-20 21:06:02 +0000945// AnalysisBasedWarnings - Worker object used by Sema to execute analysis-based
946// warnings on a function, method, or block.
947//===----------------------------------------------------------------------===//
948
Ted Kremenekd064fdc2010-03-23 00:13:23 +0000949clang::sema::AnalysisBasedWarnings::Policy::Policy() {
950 enableCheckFallThrough = 1;
951 enableCheckUnreachable = 0;
Caitlin Sadowski3ac1fbc2011-08-23 18:46:34 +0000952 enableThreadSafetyAnalysis = 0;
Ted Kremenekd064fdc2010-03-23 00:13:23 +0000953}
954
Chandler Carruth5d989942011-07-06 16:21:37 +0000955clang::sema::AnalysisBasedWarnings::AnalysisBasedWarnings(Sema &s)
956 : S(s),
957 NumFunctionsAnalyzed(0),
Benjamin Kramer54cf3412011-07-08 20:38:53 +0000958 NumFunctionsWithBadCFGs(0),
Chandler Carruth5d989942011-07-06 16:21:37 +0000959 NumCFGBlocks(0),
Benjamin Kramer54cf3412011-07-08 20:38:53 +0000960 MaxCFGBlocksPerFunction(0),
961 NumUninitAnalysisFunctions(0),
962 NumUninitAnalysisVariables(0),
963 MaxUninitAnalysisVariablesPerFunction(0),
964 NumUninitAnalysisBlockVisits(0),
965 MaxUninitAnalysisBlockVisitsPerFunction(0) {
David Blaikied6471f72011-09-25 23:23:43 +0000966 DiagnosticsEngine &D = S.getDiagnostics();
Ted Kremenekd064fdc2010-03-23 00:13:23 +0000967 DefaultPolicy.enableCheckUnreachable = (unsigned)
Argyrios Kyrtzidis08274082010-12-15 18:44:22 +0000968 (D.getDiagnosticLevel(diag::warn_unreachable, SourceLocation()) !=
David Blaikied6471f72011-09-25 23:23:43 +0000969 DiagnosticsEngine::Ignored);
Caitlin Sadowski3ac1fbc2011-08-23 18:46:34 +0000970 DefaultPolicy.enableThreadSafetyAnalysis = (unsigned)
971 (D.getDiagnosticLevel(diag::warn_double_lock, SourceLocation()) !=
David Blaikied6471f72011-09-25 23:23:43 +0000972 DiagnosticsEngine::Ignored);
Caitlin Sadowski3ac1fbc2011-08-23 18:46:34 +0000973
Ted Kremenekdbdbaaf2010-03-20 21:06:02 +0000974}
975
Ted Kremenek351ba912011-02-23 01:52:04 +0000976static void flushDiagnostics(Sema &S, sema::FunctionScopeInfo *fscope) {
Chris Lattner5f9e2722011-07-23 10:55:15 +0000977 for (SmallVectorImpl<sema::PossiblyUnreachableDiag>::iterator
Ted Kremenek351ba912011-02-23 01:52:04 +0000978 i = fscope->PossiblyUnreachableDiags.begin(),
979 e = fscope->PossiblyUnreachableDiags.end();
980 i != e; ++i) {
981 const sema::PossiblyUnreachableDiag &D = *i;
982 S.Diag(D.Loc, D.PD);
983 }
984}
985
Ted Kremenekd064fdc2010-03-23 00:13:23 +0000986void clang::sema::
987AnalysisBasedWarnings::IssueWarnings(sema::AnalysisBasedWarnings::Policy P,
Ted Kremenek283a3582011-02-23 01:51:53 +0000988 sema::FunctionScopeInfo *fscope,
Ted Kremenek3ed6fc02011-02-23 01:51:48 +0000989 const Decl *D, const BlockExpr *blkExpr) {
Ted Kremenekd068aab2010-03-20 21:11:09 +0000990
Ted Kremenekdbdbaaf2010-03-20 21:06:02 +0000991 // We avoid doing analysis-based warnings when there are errors for
992 // two reasons:
993 // (1) The CFGs often can't be constructed (if the body is invalid), so
994 // don't bother trying.
995 // (2) The code already has problems; running the analysis just takes more
996 // time.
David Blaikied6471f72011-09-25 23:23:43 +0000997 DiagnosticsEngine &Diags = S.getDiagnostics();
Ted Kremenek99e81922010-04-30 21:49:25 +0000998
Ted Kremenekd064fdc2010-03-23 00:13:23 +0000999 // Do not do any analysis for declarations in system headers if we are
1000 // going to just ignore them.
Ted Kremenek99e81922010-04-30 21:49:25 +00001001 if (Diags.getSuppressSystemWarnings() &&
Ted Kremenekd064fdc2010-03-23 00:13:23 +00001002 S.SourceMgr.isInSystemHeader(D->getLocation()))
1003 return;
1004
John McCalle0054f62010-08-25 05:56:39 +00001005 // For code in dependent contexts, we'll do this at instantiation time.
David Blaikie23661d32012-01-24 04:51:48 +00001006 if (cast<DeclContext>(D)->isDependentContext())
1007 return;
Ted Kremenekdbdbaaf2010-03-20 21:06:02 +00001008
Ted Kremenek351ba912011-02-23 01:52:04 +00001009 if (Diags.hasErrorOccurred() || Diags.hasFatalErrorOccurred()) {
1010 // Flush out any possibly unreachable diagnostics.
1011 flushDiagnostics(S, fscope);
1012 return;
1013 }
1014
Ted Kremenekdbdbaaf2010-03-20 21:06:02 +00001015 const Stmt *Body = D->getBody();
1016 assert(Body);
1017
Jordy Rosed2001872012-04-28 01:58:08 +00001018 AnalysisDeclContext AC(/* AnalysisDeclContextManager */ 0, D);
Ted Kremenekbc5cb8a2011-07-21 05:22:47 +00001019
Ted Kremenekdbdbaaf2010-03-20 21:06:02 +00001020 // Don't generate EH edges for CallExprs as we'd like to avoid the n^2
1021 // explosion for destrutors that can result and the compile time hit.
Ted Kremenekbc5cb8a2011-07-21 05:22:47 +00001022 AC.getCFGBuildOptions().PruneTriviallyFalseEdges = true;
1023 AC.getCFGBuildOptions().AddEHEdges = false;
1024 AC.getCFGBuildOptions().AddInitializers = true;
1025 AC.getCFGBuildOptions().AddImplicitDtors = true;
Ted Kremenek0c8e5a02011-07-19 14:18:48 +00001026
1027 // Force that certain expressions appear as CFGElements in the CFG. This
1028 // is used to speed up various analyses.
1029 // FIXME: This isn't the right factoring. This is here for initial
1030 // prototyping, but we need a way for analyses to say what expressions they
1031 // expect to always be CFGElements and then fill in the BuildOptions
1032 // appropriately. This is essentially a layering violation.
DeLesley Hutchins1fa3c062011-12-08 20:23:06 +00001033 if (P.enableCheckUnreachable || P.enableThreadSafetyAnalysis) {
1034 // Unreachable code analysis and thread safety require a linearized CFG.
Ted Kremenek0f3b4ca2011-08-23 23:05:11 +00001035 AC.getCFGBuildOptions().setAllAlwaysAdd();
1036 }
1037 else {
1038 AC.getCFGBuildOptions()
1039 .setAlwaysAdd(Stmt::BinaryOperatorClass)
1040 .setAlwaysAdd(Stmt::BlockExprClass)
1041 .setAlwaysAdd(Stmt::CStyleCastExprClass)
1042 .setAlwaysAdd(Stmt::DeclRefExprClass)
1043 .setAlwaysAdd(Stmt::ImplicitCastExprClass)
Richard Smithe0d3b4c2012-05-03 18:27:39 +00001044 .setAlwaysAdd(Stmt::UnaryOperatorClass)
1045 .setAlwaysAdd(Stmt::AttributedStmtClass);
Ted Kremenek0f3b4ca2011-08-23 23:05:11 +00001046 }
Ted Kremenekdbdbaaf2010-03-20 21:06:02 +00001047
Ted Kremenekbc5cb8a2011-07-21 05:22:47 +00001048 // Construct the analysis context with the specified CFG build options.
1049
Ted Kremenek351ba912011-02-23 01:52:04 +00001050 // Emit delayed diagnostics.
David Blaikie23661d32012-01-24 04:51:48 +00001051 if (!fscope->PossiblyUnreachableDiags.empty()) {
Ted Kremenek351ba912011-02-23 01:52:04 +00001052 bool analyzed = false;
Ted Kremenek0d28d362011-03-10 03:50:34 +00001053
1054 // Register the expressions with the CFGBuilder.
Chris Lattner5f9e2722011-07-23 10:55:15 +00001055 for (SmallVectorImpl<sema::PossiblyUnreachableDiag>::iterator
Ted Kremenek0d28d362011-03-10 03:50:34 +00001056 i = fscope->PossiblyUnreachableDiags.begin(),
1057 e = fscope->PossiblyUnreachableDiags.end();
1058 i != e; ++i) {
1059 if (const Stmt *stmt = i->stmt)
1060 AC.registerForcedBlockExpression(stmt);
1061 }
1062
1063 if (AC.getCFG()) {
1064 analyzed = true;
Chris Lattner5f9e2722011-07-23 10:55:15 +00001065 for (SmallVectorImpl<sema::PossiblyUnreachableDiag>::iterator
Ted Kremenek0d28d362011-03-10 03:50:34 +00001066 i = fscope->PossiblyUnreachableDiags.begin(),
1067 e = fscope->PossiblyUnreachableDiags.end();
1068 i != e; ++i)
1069 {
1070 const sema::PossiblyUnreachableDiag &D = *i;
1071 bool processed = false;
1072 if (const Stmt *stmt = i->stmt) {
1073 const CFGBlock *block = AC.getBlockForRegisteredExpression(stmt);
Eli Friedman71b8fb52012-01-21 01:01:51 +00001074 CFGReverseBlockReachabilityAnalysis *cra =
1075 AC.getCFGReachablityAnalysis();
1076 // FIXME: We should be able to assert that block is non-null, but
1077 // the CFG analysis can skip potentially-evaluated expressions in
1078 // edge cases; see test/Sema/vla-2.c.
1079 if (block && cra) {
Ted Kremenek351ba912011-02-23 01:52:04 +00001080 // Can this block be reached from the entrance?
Ted Kremenek0d28d362011-03-10 03:50:34 +00001081 if (cra->isReachable(&AC.getCFG()->getEntry(), block))
Ted Kremenek351ba912011-02-23 01:52:04 +00001082 S.Diag(D.Loc, D.PD);
Ted Kremenek0d28d362011-03-10 03:50:34 +00001083 processed = true;
Ted Kremenek351ba912011-02-23 01:52:04 +00001084 }
1085 }
Ted Kremenek0d28d362011-03-10 03:50:34 +00001086 if (!processed) {
1087 // Emit the warning anyway if we cannot map to a basic block.
1088 S.Diag(D.Loc, D.PD);
1089 }
Ted Kremenek351ba912011-02-23 01:52:04 +00001090 }
Ted Kremenek0d28d362011-03-10 03:50:34 +00001091 }
Ted Kremenek351ba912011-02-23 01:52:04 +00001092
1093 if (!analyzed)
1094 flushDiagnostics(S, fscope);
1095 }
1096
1097
Ted Kremenekdbdbaaf2010-03-20 21:06:02 +00001098 // Warning: check missing 'return'
David Blaikie23661d32012-01-24 04:51:48 +00001099 if (P.enableCheckFallThrough) {
Ted Kremenekdbdbaaf2010-03-20 21:06:02 +00001100 const CheckFallThroughDiagnostics &CD =
1101 (isa<BlockDecl>(D) ? CheckFallThroughDiagnostics::MakeForBlock()
Douglas Gregor793cd1c2012-02-15 16:20:15 +00001102 : (isa<CXXMethodDecl>(D) &&
1103 cast<CXXMethodDecl>(D)->getOverloadedOperator() == OO_Call &&
1104 cast<CXXMethodDecl>(D)->getParent()->isLambda())
1105 ? CheckFallThroughDiagnostics::MakeForLambda()
1106 : CheckFallThroughDiagnostics::MakeForFunction(D));
Ted Kremenek3ed6fc02011-02-23 01:51:48 +00001107 CheckFallThroughForBody(S, D, Body, blkExpr, CD, AC);
Ted Kremenekdbdbaaf2010-03-20 21:06:02 +00001108 }
1109
1110 // Warning: check for unreachable code
Ted Kremenek5dfee062011-11-30 21:22:09 +00001111 if (P.enableCheckUnreachable) {
1112 // Only check for unreachable code on non-template instantiations.
1113 // Different template instantiations can effectively change the control-flow
1114 // and it is very difficult to prove that a snippet of code in a template
1115 // is unreachable for all instantiations.
Ted Kremenek75df4ee2011-12-01 00:59:17 +00001116 bool isTemplateInstantiation = false;
1117 if (const FunctionDecl *Function = dyn_cast<FunctionDecl>(D))
1118 isTemplateInstantiation = Function->isTemplateInstantiation();
1119 if (!isTemplateInstantiation)
Ted Kremenek5dfee062011-11-30 21:22:09 +00001120 CheckUnreachable(S, AC);
1121 }
Caitlin Sadowski75f23ae2011-09-09 16:04:02 +00001122
Caitlin Sadowski3ac1fbc2011-08-23 18:46:34 +00001123 // Check for thread safety violations
David Blaikie23661d32012-01-24 04:51:48 +00001124 if (P.enableThreadSafetyAnalysis) {
DeLesley Hutchinsf1ac6372011-10-21 18:10:14 +00001125 SourceLocation FL = AC.getDecl()->getLocation();
Richard Smith2e515622012-02-03 04:45:26 +00001126 SourceLocation FEL = AC.getDecl()->getLocEnd();
1127 thread_safety::ThreadSafetyReporter Reporter(S, FL, FEL);
Caitlin Sadowski75f23ae2011-09-09 16:04:02 +00001128 thread_safety::runThreadSafetyAnalysis(AC, Reporter);
1129 Reporter.emitDiagnostics();
1130 }
Caitlin Sadowski3ac1fbc2011-08-23 18:46:34 +00001131
Ted Kremeneka8c17a52011-01-25 19:13:48 +00001132 if (Diags.getDiagnosticLevel(diag::warn_uninit_var, D->getLocStart())
David Blaikied6471f72011-09-25 23:23:43 +00001133 != DiagnosticsEngine::Ignored ||
Ted Kremenek76709bf2011-03-15 05:22:28 +00001134 Diags.getDiagnosticLevel(diag::warn_maybe_uninit_var, D->getLocStart())
David Blaikied6471f72011-09-25 23:23:43 +00001135 != DiagnosticsEngine::Ignored) {
Ted Kremenekc5e43c12011-03-17 05:29:57 +00001136 if (CFG *cfg = AC.getCFG()) {
Ted Kremenekc21fed32011-01-18 21:18:58 +00001137 UninitValsDiagReporter reporter(S);
Fariborz Jahanian57080fb2011-07-16 18:31:33 +00001138 UninitVariablesAnalysisStats stats;
Benjamin Kramer12efd572011-07-16 20:13:06 +00001139 std::memset(&stats, 0, sizeof(UninitVariablesAnalysisStats));
Ted Kremeneka8c17a52011-01-25 19:13:48 +00001140 runUninitializedVariablesAnalysis(*cast<DeclContext>(D), *cfg, AC,
Chandler Carruth5d989942011-07-06 16:21:37 +00001141 reporter, stats);
1142
1143 if (S.CollectStats && stats.NumVariablesAnalyzed > 0) {
1144 ++NumUninitAnalysisFunctions;
1145 NumUninitAnalysisVariables += stats.NumVariablesAnalyzed;
1146 NumUninitAnalysisBlockVisits += stats.NumBlockVisits;
1147 MaxUninitAnalysisVariablesPerFunction =
1148 std::max(MaxUninitAnalysisVariablesPerFunction,
1149 stats.NumVariablesAnalyzed);
1150 MaxUninitAnalysisBlockVisitsPerFunction =
1151 std::max(MaxUninitAnalysisBlockVisitsPerFunction,
1152 stats.NumBlockVisits);
1153 }
Ted Kremenek610068c2011-01-15 02:58:47 +00001154 }
1155 }
Chandler Carruth5d989942011-07-06 16:21:37 +00001156
Richard Smithe0d3b4c2012-05-03 18:27:39 +00001157 if (Diags.getDiagnosticLevel(diag::warn_unannotated_fallthrough,
1158 D->getLocStart()) != DiagnosticsEngine::Ignored) {
1159 DiagnoseSwitchLabelsFallthrough(S, AC);
1160 }
1161
Chandler Carruth5d989942011-07-06 16:21:37 +00001162 // Collect statistics about the CFG if it was built.
1163 if (S.CollectStats && AC.isCFGBuilt()) {
1164 ++NumFunctionsAnalyzed;
1165 if (CFG *cfg = AC.getCFG()) {
1166 // If we successfully built a CFG for this context, record some more
1167 // detail information about it.
Chandler Carruth3ea4c492011-07-06 22:21:45 +00001168 NumCFGBlocks += cfg->getNumBlockIDs();
Chandler Carruth5d989942011-07-06 16:21:37 +00001169 MaxCFGBlocksPerFunction = std::max(MaxCFGBlocksPerFunction,
Chandler Carruth3ea4c492011-07-06 22:21:45 +00001170 cfg->getNumBlockIDs());
Chandler Carruth5d989942011-07-06 16:21:37 +00001171 } else {
1172 ++NumFunctionsWithBadCFGs;
1173 }
1174 }
1175}
1176
1177void clang::sema::AnalysisBasedWarnings::PrintStats() const {
1178 llvm::errs() << "\n*** Analysis Based Warnings Stats:\n";
1179
1180 unsigned NumCFGsBuilt = NumFunctionsAnalyzed - NumFunctionsWithBadCFGs;
1181 unsigned AvgCFGBlocksPerFunction =
1182 !NumCFGsBuilt ? 0 : NumCFGBlocks/NumCFGsBuilt;
1183 llvm::errs() << NumFunctionsAnalyzed << " functions analyzed ("
1184 << NumFunctionsWithBadCFGs << " w/o CFGs).\n"
1185 << " " << NumCFGBlocks << " CFG blocks built.\n"
1186 << " " << AvgCFGBlocksPerFunction
1187 << " average CFG blocks per function.\n"
1188 << " " << MaxCFGBlocksPerFunction
1189 << " max CFG blocks per function.\n";
1190
1191 unsigned AvgUninitVariablesPerFunction = !NumUninitAnalysisFunctions ? 0
1192 : NumUninitAnalysisVariables/NumUninitAnalysisFunctions;
1193 unsigned AvgUninitBlockVisitsPerFunction = !NumUninitAnalysisFunctions ? 0
1194 : NumUninitAnalysisBlockVisits/NumUninitAnalysisFunctions;
1195 llvm::errs() << NumUninitAnalysisFunctions
1196 << " functions analyzed for uninitialiazed variables\n"
1197 << " " << NumUninitAnalysisVariables << " variables analyzed.\n"
1198 << " " << AvgUninitVariablesPerFunction
1199 << " average variables per function.\n"
1200 << " " << MaxUninitAnalysisVariablesPerFunction
1201 << " max variables per function.\n"
1202 << " " << NumUninitAnalysisBlockVisits << " block visits.\n"
1203 << " " << AvgUninitBlockVisitsPerFunction
1204 << " average block visits per function.\n"
1205 << " " << MaxUninitAnalysisBlockVisitsPerFunction
1206 << " max block visits per function.\n";
Ted Kremenekdbdbaaf2010-03-20 21:06:02 +00001207}