clang 24.0.0git
UninitializedObjectChecker.cpp
Go to the documentation of this file.
1//===----- UninitializedObjectChecker.cpp ------------------------*- C++ -*-==//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines a checker that reports uninitialized fields in objects
10// created after a constructor call.
11//
12// To read about command line options and how the checker works, refer to the
13// top of the file and inline comments in UninitializedObject.h.
14//
15// Some of the logic is implemented in UninitializedPointee.cpp, to reduce the
16// complexity of this file.
17//
18//===----------------------------------------------------------------------===//
19
20#include "UninitializedObject.h"
28#include "llvm/ADT/STLExtras.h"
29
30using namespace clang;
31using namespace clang::ento;
32using namespace clang::ast_matchers;
33
34/// We'll mark fields (and pointee of fields) that are confirmed to be
35/// uninitialized as already analyzed.
36REGISTER_SET_WITH_PROGRAMSTATE(AnalyzedRegions, const MemRegion *)
37
38namespace {
39
40class UninitializedObjectChecker
41 : public Checker<check::EndFunction, check::DeadSymbols> {
42 const BugType BT_uninitField{this, "Uninitialized fields"};
43
44public:
45 // The fields of this struct will be initialized when registering the checker.
46 UninitObjCheckerOptions Opts;
47
48 void checkEndFunction(const ReturnStmt *RS, CheckerContext &C) const;
49 void checkDeadSymbols(SymbolReaper &SR, CheckerContext &C) const;
50};
51
52/// A basic field type, that is not a pointer or a reference, it's dynamic and
53/// static type is the same.
54class RegularField final : public FieldNode {
55public:
56 RegularField(const FieldRegion *FR) : FieldNode(FR) {}
57
58 void printNoteMsg(llvm::raw_ostream &Out) const override {
59 Out << "uninitialized field ";
60 }
61
62 void printPrefix(llvm::raw_ostream &Out) const override {}
63
64 void printNode(llvm::raw_ostream &Out) const override {
65 Out << getVariableName(getDecl());
66 }
67
68 void printSeparator(llvm::raw_ostream &Out) const override { Out << '.'; }
69};
70
71/// Represents that the FieldNode that comes after this is declared in a base
72/// of the previous FieldNode. As such, this descendant doesn't wrap a
73/// FieldRegion, and is purely a tool to describe a relation between two other
74/// FieldRegion wrapping descendants.
75class BaseClass final : public FieldNode {
76 const QualType BaseClassT;
77
78public:
79 BaseClass(const QualType &T) : FieldNode(nullptr), BaseClassT(T) {
80 assert(!T.isNull());
81 assert(T->getAsCXXRecordDecl());
82 }
83
84 void printNoteMsg(llvm::raw_ostream &Out) const override {
85 llvm_unreachable("This node can never be the final node in the "
86 "fieldchain!");
87 }
88
89 void printPrefix(llvm::raw_ostream &Out) const override {}
90
91 void printNode(llvm::raw_ostream &Out) const override {
92 Out << BaseClassT->getAsCXXRecordDecl()->getName() << "::";
93 }
94
95 void printSeparator(llvm::raw_ostream &Out) const override {}
96
97 bool isBase() const override { return true; }
98};
99
100} // end of anonymous namespace
101
102// Utility function declarations.
103
104/// Returns the region that was constructed by CtorDecl, or nullptr if that
105/// isn't possible.
106static const TypedValueRegion *
108 CheckerContext &Context);
109
110/// Checks whether the object constructed by \p Ctor will be analyzed later
111/// (e.g. if the object is a field of another object, in which case we'd check
112/// it multiple times).
113static bool willObjectBeAnalyzedLater(const CXXConstructorDecl *Ctor,
114 CheckerContext &Context);
115
116/// Checks whether RD contains a field with a name or type name that matches
117/// \p Pattern.
118static bool shouldIgnoreRecord(const RecordDecl *RD, StringRef Pattern);
119
120/// Checks _syntactically_ whether it is possible to access FD from the record
121/// that contains it without a preceding assert (even if that access happens
122/// inside a method). This is mainly used for records that act like unions, like
123/// having multiple bit fields, with only a fraction being properly initialized.
124/// If these fields are properly guarded with asserts, this method returns
125/// false.
126///
127/// Since this check is done syntactically, this method could be inaccurate.
128static bool hasUnguardedAccess(const FieldDecl *FD, ProgramStateRef State);
129
130//===----------------------------------------------------------------------===//
131// Methods for UninitializedObjectChecker.
132//===----------------------------------------------------------------------===//
133
134void UninitializedObjectChecker::checkEndFunction(
135 const ReturnStmt *RS, CheckerContext &Context) const {
136
137 const auto *CtorDecl =
138 dyn_cast_or_null<CXXConstructorDecl>(Context.getStackFrame()->getDecl());
139 if (!CtorDecl)
140 return;
141
142 if (!CtorDecl->isUserProvided())
143 return;
144
145 if (CtorDecl->getParent()->isUnion())
146 return;
147
148 // This avoids essentially the same error being reported multiple times.
149 if (willObjectBeAnalyzedLater(CtorDecl, Context))
150 return;
151
152 const TypedValueRegion *R = getConstructedRegion(CtorDecl, Context);
153 if (!R)
154 return;
155
156 FindUninitializedFields F(Context.getState(), R, Opts);
157
158 std::pair<ProgramStateRef, const UninitFieldMap &> UninitInfo =
159 F.getResults();
160
161 ProgramStateRef UpdatedState = UninitInfo.first;
162 const UninitFieldMap &UninitFields = UninitInfo.second;
163
164 if (UninitFields.empty()) {
165 Context.addTransition(UpdatedState);
166 return;
167 }
168
169 // There are uninitialized fields in the record.
170
171 ExplodedNode *Node = Context.generateNonFatalErrorNode(UpdatedState);
172 if (!Node)
173 return;
174
175 PathDiagnosticLocation LocUsedForUniqueing;
176 const Expr *CallSite = Context.getStackFrame()->getCallSite();
177 if (CallSite)
178 LocUsedForUniqueing = PathDiagnosticLocation::createBegin(
179 CallSite, Context.getSourceManager(), Node->getStackFrame());
180
181 // For Plist consumers that don't support notes just yet, we'll convert notes
182 // to warnings.
184 for (const auto &Pair : UninitFields) {
185
186 auto Report = std::make_unique<PathSensitiveBugReport>(
187 BT_uninitField, Pair.second, Node, LocUsedForUniqueing,
188 Node->getStackFrame()->getDecl());
189 Context.emitReport(std::move(Report));
190 }
191 return;
192 }
193
194 SmallString<100> WarningBuf;
195 llvm::raw_svector_ostream WarningOS(WarningBuf);
196 WarningOS << UninitFields.size() << " uninitialized field"
197 << (UninitFields.size() == 1 ? "" : "s")
198 << " at the end of the constructor call";
199
200 auto Report = std::make_unique<PathSensitiveBugReport>(
201 BT_uninitField, WarningOS.str(), Node, LocUsedForUniqueing,
202 Node->getStackFrame()->getDecl());
203
204 using NoteTy = std::pair<PathDiagnosticLocation, StringRef>;
205 SmallVector<NoteTy> Notes;
206 const auto &SM = Context.getSourceManager();
207 for (const auto &[FieldRegion, NoteMsg] : UninitFields) {
208 auto FieldLoc = PathDiagnosticLocation::create(FieldRegion->getDecl(), SM);
209 Notes.emplace_back(FieldLoc, NoteMsg);
210 }
211
212 // Make the order deterministic.
213 llvm::sort(Notes, [](const NoteTy &LHS, const NoteTy &RHS) {
214 FullSourceLoc L = LHS.first.asLocation();
215 FullSourceLoc R = RHS.first.asLocation();
216 if (L != R)
218 // Comparing the field locs might not be enough so we might need a tie
219 // breaker.
220 // See the `cxx-uninitialized-object-note-order.cpp:fTwoInstances` test
221 // demonstrating this.
222 return LHS.second < RHS.second;
223 });
224
225 for (const auto &[Loc, NoteMsg] : Notes)
226 Report->addNote(NoteMsg, Loc);
227
228 Context.emitReport(std::move(Report));
229}
230
231void UninitializedObjectChecker::checkDeadSymbols(SymbolReaper &SR,
232 CheckerContext &C) const {
233 ProgramStateRef State = C.getState();
234 for (const MemRegion *R : State->get<AnalyzedRegions>()) {
235 if (!SR.isLiveRegion(R))
236 State = State->remove<AnalyzedRegions>(R);
237 }
238}
239
240//===----------------------------------------------------------------------===//
241// Methods for FindUninitializedFields.
242//===----------------------------------------------------------------------===//
243
245 ProgramStateRef State, const TypedValueRegion *const R,
246 const UninitObjCheckerOptions &Opts)
247 : State(State), ObjectR(R), Opts(Opts) {
248
249 isNonUnionUninit(ObjectR, FieldChainInfo(ChainFactory));
250
251 // In non-pedantic mode, if ObjectR doesn't contain a single initialized
252 // field, we'll assume that Object was intentionally left uninitialized.
253 if (!Opts.IsPedantic && !isAnyFieldInitialized())
254 UninitFields.clear();
255}
256
257bool FindUninitializedFields::addFieldToUninits(FieldChainInfo Chain,
258 const MemRegion *PointeeR) {
259 const FieldRegion *FR = Chain.getUninitRegion();
260
261 assert((PointeeR || !isDereferencableType(FR->getDecl()->getType())) &&
262 "One must also pass the pointee region as a parameter for "
263 "dereferenceable fields!");
264
265 if (State->getStateManager().getContext().getSourceManager().isInSystemHeader(
266 FR->getDecl()->getLocation()))
267 return false;
268
269 if (Opts.IgnoreGuardedFields && !hasUnguardedAccess(FR->getDecl(), State))
270 return false;
271
272 if (State->contains<AnalyzedRegions>(FR))
273 return false;
274
275 if (PointeeR) {
276 if (State->contains<AnalyzedRegions>(PointeeR)) {
277 return false;
278 }
279 State = State->add<AnalyzedRegions>(PointeeR);
280 }
281
282 State = State->add<AnalyzedRegions>(FR);
283
284 UninitFieldMap::mapped_type NoteMsgBuf;
285 llvm::raw_svector_ostream OS(NoteMsgBuf);
286 Chain.printNoteMsg(OS);
287
288 return UninitFields.insert({FR, std::move(NoteMsgBuf)}).second;
289}
290
291bool FindUninitializedFields::isNonUnionUninit(const TypedValueRegion *R,
292 FieldChainInfo LocalChain) {
293 assert(R->getValueType()->isRecordType() &&
294 !R->getValueType()->isUnionType() &&
295 "This method only checks non-union record objects!");
296
297 const RecordDecl *RD = R->getValueType()->getAsRecordDecl()->getDefinition();
298
299 if (!RD) {
300 IsAnyFieldInitialized = true;
301 return true;
302 }
303
304 if (!Opts.IgnoredRecordsWithFieldPattern.empty() &&
305 shouldIgnoreRecord(RD, Opts.IgnoredRecordsWithFieldPattern)) {
306 IsAnyFieldInitialized = true;
307 return false;
308 }
309
310 bool ContainsUninitField = false;
311
312 // Are all of this non-union's fields initialized?
313 for (const FieldDecl *I : RD->fields()) {
314 if (I->isUnnamedBitField()) {
315 continue;
316 }
317 const auto FieldVal =
318 State->getLValue(I, loc::MemRegionVal(R)).castAs<loc::MemRegionVal>();
319 const auto *FR = FieldVal.getRegionAs<FieldRegion>();
320 QualType T = I->getType();
321
322 // If LocalChain already contains FR, then we encountered a cyclic
323 // reference. In this case, region FR is already under checking at an
324 // earlier node in the directed tree.
325 if (LocalChain.contains(FR))
326 return false;
327
328 if (T->isStructureOrClassType()) {
329 if (isNonUnionUninit(FR, LocalChain.add(RegularField(FR))))
330 ContainsUninitField = true;
331 continue;
332 }
333
334 if (T->isUnionType()) {
335 if (isUnionUninit(FR)) {
336 if (addFieldToUninits(LocalChain.add(RegularField(FR))))
337 ContainsUninitField = true;
338 } else
339 IsAnyFieldInitialized = true;
340 continue;
341 }
342
343 if (T->isArrayType()) {
344 IsAnyFieldInitialized = true;
345 continue;
346 }
347
348 SVal V = State->getSVal(FieldVal);
349
351 if (isDereferencableUninit(FR, LocalChain))
352 ContainsUninitField = true;
353 continue;
354 }
355
356 if (isPrimitiveType(T)) {
357 if (isPrimitiveUninit(V)) {
358 if (addFieldToUninits(LocalChain.add(RegularField(FR))))
359 ContainsUninitField = true;
360 }
361 continue;
362 }
363
364 llvm_unreachable("All cases are handled!");
365 }
366
367 // Checking bases. The checker will regard inherited data members as direct
368 // fields.
369 const auto *CXXRD = dyn_cast<CXXRecordDecl>(RD);
370 if (!CXXRD)
371 return ContainsUninitField;
372
373 for (const CXXBaseSpecifier &BaseSpec : CXXRD->bases()) {
374 const auto *BaseRegion = State->getLValue(BaseSpec, R)
375 .castAs<loc::MemRegionVal>()
376 .getRegionAs<TypedValueRegion>();
377
378 // If the head of the list is also a BaseClass, we'll overwrite it to avoid
379 // note messages like 'this->A::B::x'.
380 if (!LocalChain.isEmpty() && LocalChain.getHead().isBase()) {
381 if (isNonUnionUninit(BaseRegion, LocalChain.replaceHead(
382 BaseClass(BaseSpec.getType()))))
383 ContainsUninitField = true;
384 } else {
385 if (isNonUnionUninit(BaseRegion,
386 LocalChain.add(BaseClass(BaseSpec.getType()))))
387 ContainsUninitField = true;
388 }
389 }
390
391 return ContainsUninitField;
392}
393
394bool FindUninitializedFields::isUnionUninit(const TypedValueRegion *R) {
395 assert(R->getValueType()->isUnionType() &&
396 "This method only checks union objects!");
397 // TODO: Implement support for union fields.
398 return false;
399}
400
401bool FindUninitializedFields::isPrimitiveUninit(SVal V) {
402 if (V.isUndef())
403 return true;
404
405 IsAnyFieldInitialized = true;
406 return false;
407}
408
409//===----------------------------------------------------------------------===//
410// Methods for FieldChainInfo.
411//===----------------------------------------------------------------------===//
412
414 for (const FieldNode &Node : Chain) {
415 if (Node.isSameRegion(FR))
416 return true;
417 }
418 return false;
419}
420
421/// Prints every element except the last to `Out`. Since ImmutableLists store
422/// elements in reverse order, and have no reverse iterators, we use a
423/// recursive function to print the fieldchain correctly. The last element in
424/// the chain is to be printed by `FieldChainInfo::print`.
425static void printTail(llvm::raw_ostream &Out,
427
428// FIXME: This function constructs an incorrect string in the following case:
429//
430// struct Base { int x; };
431// struct D1 : Base {}; struct D2 : Base {};
432//
433// struct MostDerived : D1, D2 {
434// MostDerived() {}
435// }
436//
437// A call to MostDerived::MostDerived() will cause two notes that say
438// "uninitialized field 'this->x'", but we can't refer to 'x' directly,
439// we need an explicit namespace resolution whether the uninit field was
440// 'D1::x' or 'D2::x'.
441void FieldChainInfo::printNoteMsg(llvm::raw_ostream &Out) const {
442 if (Chain.isEmpty())
443 return;
444
445 const FieldNode &LastField = getHead();
446
447 LastField.printNoteMsg(Out);
448 Out << '\'';
449
450 for (const FieldNode &Node : Chain)
451 Node.printPrefix(Out);
452
453 Out << "this->";
454 printTail(Out, Chain.getTail());
455 LastField.printNode(Out);
456 Out << '\'';
457}
458
459static void printTail(llvm::raw_ostream &Out,
461 if (L.isEmpty())
462 return;
463
464 printTail(Out, L.getTail());
465
466 L.getHead().printNode(Out);
467 L.getHead().printSeparator(Out);
468}
469
470//===----------------------------------------------------------------------===//
471// Utility functions.
472//===----------------------------------------------------------------------===//
473
474static const SubRegion *
476 CheckerContext &Context) {
477 Loc ThisLoc =
478 Context.getSValBuilder().getCXXThis(CtorDecl, Context.getStackFrame());
479 SVal ObjectV = Context.getState()->getSVal(ThisLoc);
480 return ObjectV.getAsRegion()->getAs<SubRegion>();
481}
482
483static const TypedValueRegion *
485 CheckerContext &Context) {
486
487 const SubRegion *SR = getConstructedSubRegion(CtorDecl, Context);
488 if (!SR)
489 return nullptr;
490
491 if (const auto *TVR = SR->getAs<TypedValueRegion>()) {
492 return TVR->getValueType()->getAsCXXRecordDecl() ? TVR : nullptr;
493 }
494
495 QualType ThisPointeeTy = CtorDecl->getThisType()->getPointeeType();
496 if (!ThisPointeeTy->getAsCXXRecordDecl())
497 return nullptr;
498
499 auto &MemMgr = Context.getState()->getStateManager().getRegionManager();
500 auto &SVB = Context.getSValBuilder();
501
502 const auto *ElemR = MemMgr.getElementRegion(
503 ThisPointeeTy, SVB.makeZeroArrayIndex(), SR, Context.getASTContext());
504
505 return ElemR;
506}
507
509 CheckerContext &Context) {
510
511 const SubRegion *CurrRegion = getConstructedSubRegion(Ctor, Context);
512 if (!CurrRegion)
513 return false;
514
515 // Returns true if \p Ctor was called by another constructor whose region
516 // contains CurrRegion, so CurrRegion will be analyzed during that analysis.
517 return llvm::any_of(
518 Context.getStackFrame()->parents(), [&](const StackFrame &SF) {
519 const auto *OtherCtor = dyn_cast<CXXConstructorDecl>(SF.getDecl());
520 if (!OtherCtor)
521 return false;
522
523 const SubRegion *OtherRegion =
524 getConstructedSubRegion(OtherCtor, Context);
525 return OtherRegion && CurrRegion->isSubRegionOf(OtherRegion);
526 });
527}
528
529static bool shouldIgnoreRecord(const RecordDecl *RD, StringRef Pattern) {
530 llvm::Regex R(Pattern);
531
532 for (const FieldDecl *FD : RD->fields()) {
533 if (R.match(FD->getType().getAsString()))
534 return true;
535 if (R.match(FD->getName()))
536 return true;
537 }
538
539 return false;
540}
541
542static const Stmt *getMethodBody(const CXXMethodDecl *M) {
544 return nullptr;
545
546 if (!M->isDefined())
547 return nullptr;
548
549 return M->getDefinition()->getBody();
550}
551
552static bool hasUnguardedAccess(const FieldDecl *FD, ProgramStateRef State) {
553
555 return true;
556
557 const auto *Parent = dyn_cast<CXXRecordDecl>(FD->getParent());
558
559 if (!Parent)
560 return true;
561
562 Parent = Parent->getDefinition();
563 assert(Parent && "The record's definition must be avaible if an uninitialized"
564 " field of it was found!");
565
566 ASTContext &AC = State->getStateManager().getContext();
567
568 auto FieldAccessM = memberExpr(hasDeclaration(equalsNode(FD))).bind("access");
569
570 auto AssertLikeM = callExpr(callee(functionDecl(
571 hasAnyName("exit", "panic", "error", "Assert", "assert", "ziperr",
572 "assfail", "db_error", "__assert", "__assert2", "_wassert",
573 "__assert_rtn", "__assert_fail", "dtrace_assfail",
574 "yy_fatal_error", "_XCAssertionFailureHandler",
575 "_DTAssertionFailureHandler", "_TSAssertionFailureHandler"))));
576
577 auto NoReturnFuncM = callExpr(callee(functionDecl(isNoReturn())));
578
579 auto GuardM =
580 stmt(anyOf(ifStmt(), switchStmt(), conditionalOperator(), AssertLikeM,
581 NoReturnFuncM))
582 .bind("guard");
583
584 for (const CXXMethodDecl *M : Parent->methods()) {
585 const Stmt *MethodBody = getMethodBody(M);
586 if (!MethodBody)
587 continue;
588
589 auto Accesses = match(stmt(hasDescendant(FieldAccessM)), *MethodBody, AC);
590 if (Accesses.empty())
591 continue;
592 const auto *FirstAccess = Accesses[0].getNodeAs<MemberExpr>("access");
593 assert(FirstAccess);
594
595 auto Guards = match(stmt(hasDescendant(GuardM)), *MethodBody, AC);
596 if (Guards.empty())
597 return true;
598 const auto *FirstGuard = Guards[0].getNodeAs<Stmt>("guard");
599 assert(FirstGuard);
600
601 if (FirstAccess->getBeginLoc() < FirstGuard->getBeginLoc())
602 return true;
603 }
604
605 return false;
606}
607
608std::string clang::ento::getVariableName(const FieldDecl *Field) {
609 // If Field is a captured lambda variable, Field->getName() will return with
610 // an empty string. We can however acquire it's name from the lambda's
611 // captures.
612 const auto *CXXParent = dyn_cast<CXXRecordDecl>(Field->getParent());
613
614 if (CXXParent && CXXParent->isLambda()) {
615 assert(CXXParent->captures_begin());
616 auto It = CXXParent->captures_begin() + Field->getFieldIndex();
617
618 if (It->capturesVariable())
619 return llvm::Twine("/*captured variable*/" +
620 It->getCapturedVar()->getName())
621 .str();
622
623 if (It->capturesThis())
624 return "/*'this' capture*/";
625
626 llvm_unreachable("No other capture type is expected!");
627 }
628
629 return std::string(Field->getName());
630}
631
632void ento::registerUninitializedObjectChecker(CheckerManager &Mgr) {
633 auto Chk = Mgr.registerChecker<UninitializedObjectChecker>();
634
635 const AnalyzerOptions &AnOpts = Mgr.getAnalyzerOptions();
636 UninitObjCheckerOptions &ChOpts = Chk->Opts;
637
638 ChOpts.IsPedantic = AnOpts.getCheckerBooleanOption(Chk, "Pedantic");
639 ChOpts.ShouldConvertNotesToWarnings = AnOpts.getCheckerBooleanOption(
640 Chk, "NotesAsWarnings");
641 ChOpts.CheckPointeeInitialization = AnOpts.getCheckerBooleanOption(
642 Chk, "CheckPointeeInitialization");
644 std::string(AnOpts.getCheckerStringOption(Chk, "IgnoreRecordsWithField"));
645 ChOpts.IgnoreGuardedFields =
646 AnOpts.getCheckerBooleanOption(Chk, "IgnoreGuardedFields");
647
648 std::string ErrorMsg;
649 if (!llvm::Regex(ChOpts.IgnoredRecordsWithFieldPattern).isValid(ErrorMsg))
650 Mgr.reportInvalidCheckerOptionValue(Chk, "IgnoreRecordsWithField",
651 "a valid regex, building failed with error message "
652 "\"" + ErrorMsg + "\"");
653}
654
655bool ento::shouldRegisterUninitializedObjectChecker(const CheckerManager &mgr) {
656 return true;
657}
#define V(N, I)
#define REGISTER_SET_WITH_PROGRAMSTATE(Name, Elem)
Declares an immutable set of type NameTy, suitable for placement into the ProgramState.
static Error printNode(StringRef Id, const MatchFinder::MatchResult &Match, std::string *Result)
Definition Stencil.cpp:45
static const Stmt * getMethodBody(const CXXMethodDecl *M)
static const TypedValueRegion * getConstructedRegion(const CXXConstructorDecl *CtorDecl, CheckerContext &Context)
Returns the region that was constructed by CtorDecl, or nullptr if that isn't possible.
static bool hasUnguardedAccess(const FieldDecl *FD, ProgramStateRef State)
Checks syntactically whether it is possible to access FD from the record that contains it without a p...
static bool willObjectBeAnalyzedLater(const CXXConstructorDecl *Ctor, CheckerContext &Context)
Checks whether the object constructed by Ctor will be analyzed later (e.g.
static const SubRegion * getConstructedSubRegion(const CXXConstructorDecl *CtorDecl, CheckerContext &Context)
static bool shouldIgnoreRecord(const RecordDecl *RD, StringRef Pattern)
Checks whether RD contains a field with a name or type name that matches Pattern.
static void printTail(llvm::raw_ostream &Out, const FieldChainInfo::FieldChain L)
Prints every element except the last to Out.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:223
SourceManager & getSourceManager()
Definition ASTContext.h:884
Stores options for the analyzer from the command line.
Represents a C++ constructor within a class.
Definition DeclCXX.h:2637
Represents a static or instance method of a struct/union/class.
Definition DeclCXX.h:2145
QualType getThisType() const
Return the type of the this pointer.
Definition DeclCXX.cpp:2859
SourceLocation getLocation() const
Definition DeclBase.h:447
AccessSpecifier getAccess() const
Definition DeclBase.h:515
Represents a member of a struct/union/class.
Definition Decl.h:3294
const RecordDecl * getParent() const
Returns the parent of this field declaration, which is the struct in which this field is defined.
Definition Decl.h:3530
bool isBeforeInTranslationUnitThan(SourceLocation Loc) const
Determines the order of 2 source locations in the translation unit.
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
Definition Decl.cpp:3267
FunctionDecl * getDefinition()
Get the definition for this declaration.
Definition Decl.h:2395
bool isDefined(const FunctionDecl *&Definition, bool CheckForPendingFriendDefinition=false) const
Returns true if the function has a definition that does not need to be instantiated.
Definition Decl.cpp:3234
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition Expr.h:3375
A (possibly-)qualified type.
Definition TypeBase.h:938
Represents a struct/union/class.
Definition Decl.h:4459
field_range fields() const
Definition Decl.h:4662
ReturnStmt - This represents a return, optionally of an expression: return; return 4;.
Definition Stmt.h:3169
It represents a stack frame of the call stack.
const Decl * getDecl() const
Stmt - This represents one statement.
Definition Stmt.h:85
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Definition Type.h:26
bool isArrayType() const
Definition TypeBase.h:8840
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Definition Type.cpp:789
bool isStructureOrClassType() const
Definition Type.cpp:743
bool isUnionType() const
Definition Type.cpp:755
QualType getType() const
Definition Decl.h:723
const AnalyzerOptions & getAnalyzerOptions() const
CHECKER * registerChecker(AT &&...Args)
Register a single-part checker (derived from Checker): construct its singleton instance,...
void reportInvalidCheckerOptionValue(const CheckerFrontend *Checker, StringRef OptionName, StringRef ExpectedValueDesc) const
Emits an error through a DiagnosticsEngine about an invalid user supplied checker option value.
Simple checker classes that implement one frontend (i.e.
Definition Checker.h:565
const StackFrame * getStackFrame() const
Represents a field chain.
bool contains(const FieldRegion *FR) const
llvm::ImmutableList< const FieldNode & > FieldChain
const FieldNode & getHead() const
const FieldRegion * getUninitRegion() const
FieldChainInfo replaceHead(const FieldNodeT &FN)
Constructs a new FieldChainInfo object with FN as the new head of the list.
FieldChainInfo add(const FieldNodeT &FN)
Constructs a new FieldChainInfo object with FN appended.
void printNoteMsg(llvm::raw_ostream &Out) const
A lightweight polymorphic wrapper around FieldRegion *.
virtual bool isBase() const
virtual void printNoteMsg(llvm::raw_ostream &Out) const =0
If this is the last element of the fieldchain, this method will print the note message associated wit...
virtual void printNode(llvm::raw_ostream &Out) const =0
Print the node. Should contain the name of the field stored in FR.
LLVM_ATTRIBUTE_RETURNS_NONNULL const FieldDecl * getDecl() const override
Definition MemRegion.h:1163
FindUninitializedFields(ProgramStateRef State, const TypedValueRegion *const R, const UninitObjCheckerOptions &Opts)
Constructs the FindUninitializedField object, searches for and stores uninitialized fields in R.
bool isAnyFieldInitialized()
Returns whether the analyzed region contains at least one initialized field.
MemRegion - The root abstract class for all memory regions.
Definition MemRegion.h:97
const RegionTy * getAs() const
Definition MemRegion.h:1426
static PathDiagnosticLocation createBegin(const Decl *D, const SourceManager &SM)
Create a location for the beginning of the declaration.
static PathDiagnosticLocation create(const Decl *D, const SourceManager &SM)
Create a location corresponding to the given declaration.
SVal - This represents a symbolic expression, which can be either an L-value or an R-value.
Definition SVals.h:57
const MemRegion * getAsRegion() const
Definition SVals.cpp:119
SubRegion - A region that subsets another larger region.
Definition MemRegion.h:480
bool isLiveRegion(const MemRegion *region)
TypedValueRegion - An abstract class representing regions having a typed value.
Definition MemRegion.h:569
const internal::ArgumentAdaptingMatcherFunc< internal::HasDescendantMatcher > hasDescendant
Matches AST nodes that have descendant AST nodes that match the provided matcher.
const internal::VariadicDynCastAllOfMatcher< Stmt, CallExpr > callExpr
Matches call expressions.
SmallVector< BoundNodes, 1 > match(MatcherT Matcher, const NodeT &Node, ASTContext &Context)
Returns the results of matching Matcher on Node.
const internal::VariadicFunction< internal::Matcher< NamedDecl >, StringRef, internal::hasAnyNameFunc > hasAnyName
Matches NamedDecl nodes that have any of the specified names.
const internal::VariadicDynCastAllOfMatcher< Decl, FunctionDecl > functionDecl
Matches function declarations.
const internal::VariadicDynCastAllOfMatcher< Stmt, SwitchStmt > switchStmt
Matches switch statements.
const internal::VariadicDynCastAllOfMatcher< Stmt, MemberExpr > memberExpr
Matches member expressions.
internal::PolymorphicMatcher< internal::HasDeclarationMatcher, void(internal::HasDeclarationSupportedTypes), internal::Matcher< Decl > > hasDeclaration(const internal::Matcher< Decl > &InnerMatcher)
Matches a node if the declaration associated with that node matches the given matcher.
const internal::VariadicAllOfMatcher< Stmt > stmt
Matches statements.
const internal::VariadicDynCastAllOfMatcher< Stmt, ConditionalOperator > conditionalOperator
Matches conditional operator expressions.
const internal::VariadicOperatorMatcherFunc< 2, std::numeric_limits< unsigned >::max()> anyOf
Matches if any of the given matchers matches.
const internal::VariadicDynCastAllOfMatcher< Stmt, IfStmt > ifStmt
Matches if statements.
std::string getVariableName(const FieldDecl *Field)
Returns with Field's name.
std::map< const FieldRegion *, llvm::SmallString< 50 > > UninitFieldMap
bool isPrimitiveType(const QualType &T)
Returns true if T is a primitive type.
IntrusiveRefCntPtr< const ProgramState > ProgramStateRef
@ OS
Indicates that the tracking object is a descendant of a referenced-counted OSObject,...
bool isDereferencableType(const QualType &T)
Top level wrappers for InstallAPI frontend operations.
bool isa(CodeGen::Address addr)
Definition Address.h:330
@ AS_public
Definition Specifiers.h:125
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
const FunctionProtoType * T