blob: b6322293212c9ff648d82a6e3dae8e1dfd8b8747 [file] [log] [blame]
Kristof Umann30f08652018-06-18 11:50:17 +00001//===----- UninitializedObjectChecker.cpp ------------------------*- 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 a checker that reports uninitialized fields in objects
11// created after a constructor call.
12//
Kristof Umann6cec6c42018-09-14 09:39:26 +000013// To read about command line options and how the checker works, refer to the
14// top of the file and inline comments in UninitializedObject.h.
Kristof Umann56963ae2018-08-13 18:17:05 +000015//
16// Some of the logic is implemented in UninitializedPointee.cpp, to reduce the
17// complexity of this file.
18//
Kristof Umann30f08652018-06-18 11:50:17 +000019//===----------------------------------------------------------------------===//
20
Richard Smith651d6832018-08-13 22:07:11 +000021#include "../ClangSACheckers.h"
Kristof Umanna37bba42018-08-13 18:22:22 +000022#include "UninitializedObject.h"
Kristof Umann30f08652018-06-18 11:50:17 +000023#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
24#include "clang/StaticAnalyzer/Core/Checker.h"
25#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
Kristof Umannef9af052018-08-08 13:18:53 +000026#include "clang/StaticAnalyzer/Core/PathSensitive/DynamicTypeMap.h"
Kristof Umann30f08652018-06-18 11:50:17 +000027
28using namespace clang;
29using namespace clang::ento;
30
31namespace {
32
33class UninitializedObjectChecker : public Checker<check::EndFunction> {
34 std::unique_ptr<BuiltinBug> BT_uninitField;
35
36public:
Kristof Umann6cec6c42018-09-14 09:39:26 +000037 // The fields of this struct will be initialized when registering the checker.
38 UninitObjCheckerOptions Opts;
Kristof Umann30f08652018-06-18 11:50:17 +000039
40 UninitializedObjectChecker()
41 : BT_uninitField(new BuiltinBug(this, "Uninitialized fields")) {}
Reka Kovacsed8c05c2018-07-16 20:47:45 +000042 void checkEndFunction(const ReturnStmt *RS, CheckerContext &C) const;
Kristof Umann30f08652018-06-18 11:50:17 +000043};
44
Kristof Umann015b0592018-08-13 18:43:08 +000045/// A basic field type, that is not a pointer or a reference, it's dynamic and
46/// static type is the same.
Richard Smith651d6832018-08-13 22:07:11 +000047class RegularField final : public FieldNode {
Kristof Umann015b0592018-08-13 18:43:08 +000048public:
49 RegularField(const FieldRegion *FR) : FieldNode(FR) {}
50
51 virtual void printNoteMsg(llvm::raw_ostream &Out) const override {
52 Out << "uninitialized field ";
53 }
54
55 virtual void printPrefix(llvm::raw_ostream &Out) const override {}
56
Richard Smith651d6832018-08-13 22:07:11 +000057 virtual void printNode(llvm::raw_ostream &Out) const override {
Kristof Umann015b0592018-08-13 18:43:08 +000058 Out << getVariableName(getDecl());
59 }
60
61 virtual void printSeparator(llvm::raw_ostream &Out) const override {
62 Out << '.';
63 }
64};
65
Kristof Umannb59b45e2018-08-21 12:16:59 +000066/// Represents that the FieldNode that comes after this is declared in a base
Kristof Umannceb5f652018-09-14 09:07:40 +000067/// of the previous FieldNode. As such, this descendant doesn't wrap a
68/// FieldRegion, and is purely a tool to describe a relation between two other
69/// FieldRegion wrapping descendants.
Kristof Umannb59b45e2018-08-21 12:16:59 +000070class BaseClass final : public FieldNode {
71 const QualType BaseClassT;
72
73public:
74 BaseClass(const QualType &T) : FieldNode(nullptr), BaseClassT(T) {
75 assert(!T.isNull());
76 assert(T->getAsCXXRecordDecl());
77 }
78
79 virtual void printNoteMsg(llvm::raw_ostream &Out) const override {
80 llvm_unreachable("This node can never be the final node in the "
81 "fieldchain!");
82 }
83
84 virtual void printPrefix(llvm::raw_ostream &Out) const override {}
85
86 virtual void printNode(llvm::raw_ostream &Out) const override {
87 Out << BaseClassT->getAsCXXRecordDecl()->getName() << "::";
88 }
89
90 virtual void printSeparator(llvm::raw_ostream &Out) const override {}
91
Kristof Umann06209cb2018-08-21 15:09:22 +000092 virtual bool isBase() const override { return true; }
Kristof Umannb59b45e2018-08-21 12:16:59 +000093};
94
Kristof Umanncc852442018-07-12 13:13:46 +000095} // end of anonymous namespace
96
Kristof Umann30f08652018-06-18 11:50:17 +000097// Utility function declarations.
98
99/// Returns the object that was constructed by CtorDecl, or None if that isn't
100/// possible.
Kristof Umann0735cfb2018-08-08 12:23:02 +0000101// TODO: Refactor this function so that it returns the constructed object's
102// region.
Kristof Umanncc852442018-07-12 13:13:46 +0000103static Optional<nonloc::LazyCompoundVal>
Kristof Umann30f08652018-06-18 11:50:17 +0000104getObjectVal(const CXXConstructorDecl *CtorDecl, CheckerContext &Context);
105
Kristof Umann0735cfb2018-08-08 12:23:02 +0000106/// Checks whether the object constructed by \p Ctor will be analyzed later
107/// (e.g. if the object is a field of another object, in which case we'd check
108/// it multiple times).
109static bool willObjectBeAnalyzedLater(const CXXConstructorDecl *Ctor,
Kristof Umanna37bba42018-08-13 18:22:22 +0000110 CheckerContext &Context);
Kristof Umann30f08652018-06-18 11:50:17 +0000111
Kristof Umannd6145d92018-09-14 10:10:09 +0000112/// Checks whether RD contains a field with a name or type name that matches
113/// \p Pattern.
114static bool shouldIgnoreRecord(const RecordDecl *RD, StringRef Pattern);
115
Kristof Umann30f08652018-06-18 11:50:17 +0000116//===----------------------------------------------------------------------===//
117// Methods for UninitializedObjectChecker.
118//===----------------------------------------------------------------------===//
119
120void UninitializedObjectChecker::checkEndFunction(
Reka Kovacsed8c05c2018-07-16 20:47:45 +0000121 const ReturnStmt *RS, CheckerContext &Context) const {
Kristof Umann30f08652018-06-18 11:50:17 +0000122
123 const auto *CtorDecl = dyn_cast_or_null<CXXConstructorDecl>(
124 Context.getLocationContext()->getDecl());
125 if (!CtorDecl)
126 return;
127
128 if (!CtorDecl->isUserProvided())
129 return;
130
131 if (CtorDecl->getParent()->isUnion())
132 return;
133
134 // This avoids essentially the same error being reported multiple times.
Kristof Umann0735cfb2018-08-08 12:23:02 +0000135 if (willObjectBeAnalyzedLater(CtorDecl, Context))
Kristof Umann30f08652018-06-18 11:50:17 +0000136 return;
137
138 Optional<nonloc::LazyCompoundVal> Object = getObjectVal(CtorDecl, Context);
139 if (!Object)
140 return;
141
Kristof Umann6cec6c42018-09-14 09:39:26 +0000142 FindUninitializedFields F(Context.getState(), Object->getRegion(), Opts);
Kristof Umann30f08652018-06-18 11:50:17 +0000143
Kristof Umann015b0592018-08-13 18:43:08 +0000144 const UninitFieldMap &UninitFields = F.getUninitFields();
Kristof Umann30f08652018-06-18 11:50:17 +0000145
146 if (UninitFields.empty())
147 return;
148
149 // There are uninitialized fields in the record.
150
151 ExplodedNode *Node = Context.generateNonFatalErrorNode(Context.getState());
152 if (!Node)
153 return;
154
155 PathDiagnosticLocation LocUsedForUniqueing;
156 const Stmt *CallSite = Context.getStackFrame()->getCallSite();
157 if (CallSite)
158 LocUsedForUniqueing = PathDiagnosticLocation::createBegin(
159 CallSite, Context.getSourceManager(), Node->getLocationContext());
160
Kristof Umann9bd44392018-06-29 11:25:24 +0000161 // For Plist consumers that don't support notes just yet, we'll convert notes
162 // to warnings.
Kristof Umann6cec6c42018-09-14 09:39:26 +0000163 if (Opts.ShouldConvertNotesToWarnings) {
Kristof Umann015b0592018-08-13 18:43:08 +0000164 for (const auto &Pair : UninitFields) {
Kristof Umann9bd44392018-06-29 11:25:24 +0000165
166 auto Report = llvm::make_unique<BugReport>(
Kristof Umann015b0592018-08-13 18:43:08 +0000167 *BT_uninitField, Pair.second, Node, LocUsedForUniqueing,
Kristof Umann9bd44392018-06-29 11:25:24 +0000168 Node->getLocationContext()->getDecl());
169 Context.emitReport(std::move(Report));
170 }
171 return;
172 }
173
Kristof Umann30f08652018-06-18 11:50:17 +0000174 SmallString<100> WarningBuf;
175 llvm::raw_svector_ostream WarningOS(WarningBuf);
176 WarningOS << UninitFields.size() << " uninitialized field"
177 << (UninitFields.size() == 1 ? "" : "s")
178 << " at the end of the constructor call";
179
180 auto Report = llvm::make_unique<BugReport>(
181 *BT_uninitField, WarningOS.str(), Node, LocUsedForUniqueing,
182 Node->getLocationContext()->getDecl());
183
Kristof Umann015b0592018-08-13 18:43:08 +0000184 for (const auto &Pair : UninitFields) {
185 Report->addNote(Pair.second,
186 PathDiagnosticLocation::create(Pair.first->getDecl(),
Kristof Umann30f08652018-06-18 11:50:17 +0000187 Context.getSourceManager()));
188 }
Kristof Umann30f08652018-06-18 11:50:17 +0000189 Context.emitReport(std::move(Report));
190}
191
192//===----------------------------------------------------------------------===//
193// Methods for FindUninitializedFields.
194//===----------------------------------------------------------------------===//
195
196FindUninitializedFields::FindUninitializedFields(
Kristof Umann23ca9662018-08-13 18:48:34 +0000197 ProgramStateRef State, const TypedValueRegion *const R,
Kristof Umann6cec6c42018-09-14 09:39:26 +0000198 const UninitObjCheckerOptions &Opts)
199 : State(State), ObjectR(R), Opts(Opts) {
Kristof Umann30f08652018-06-18 11:50:17 +0000200
Kristof Umann015b0592018-08-13 18:43:08 +0000201 isNonUnionUninit(ObjectR, FieldChainInfo(ChainFactory));
Kristof Umann6cec6c42018-09-14 09:39:26 +0000202
203 // In non-pedantic mode, if ObjectR doesn't contain a single initialized
204 // field, we'll assume that Object was intentionally left uninitialized.
205 if (!Opts.IsPedantic && !isAnyFieldInitialized())
206 UninitFields.clear();
Kristof Umann30f08652018-06-18 11:50:17 +0000207}
208
209bool FindUninitializedFields::addFieldToUninits(FieldChainInfo Chain) {
210 if (State->getStateManager().getContext().getSourceManager().isInSystemHeader(
Kristof Umann015b0592018-08-13 18:43:08 +0000211 Chain.getUninitRegion()->getDecl()->getLocation()))
Kristof Umann30f08652018-06-18 11:50:17 +0000212 return false;
213
Kristof Umann015b0592018-08-13 18:43:08 +0000214 UninitFieldMap::mapped_type NoteMsgBuf;
215 llvm::raw_svector_ostream OS(NoteMsgBuf);
216 Chain.printNoteMsg(OS);
217 return UninitFields
218 .insert(std::make_pair(Chain.getUninitRegion(), std::move(NoteMsgBuf)))
219 .second;
Kristof Umann30f08652018-06-18 11:50:17 +0000220}
221
222bool FindUninitializedFields::isNonUnionUninit(const TypedValueRegion *R,
223 FieldChainInfo LocalChain) {
224 assert(R->getValueType()->isRecordType() &&
225 !R->getValueType()->isUnionType() &&
226 "This method only checks non-union record objects!");
227
Kristof Umannf0dd1012018-09-14 08:58:21 +0000228 const RecordDecl *RD = R->getValueType()->getAsRecordDecl()->getDefinition();
229
230 if (!RD) {
231 IsAnyFieldInitialized = true;
232 return true;
233 }
Kristof Umann30f08652018-06-18 11:50:17 +0000234
Kristof Umannd6145d92018-09-14 10:10:09 +0000235 if (!Opts.IgnoredRecordsWithFieldPattern.empty() &&
236 shouldIgnoreRecord(RD, Opts.IgnoredRecordsWithFieldPattern)) {
237 IsAnyFieldInitialized = true;
238 return false;
239 }
240
Kristof Umann30f08652018-06-18 11:50:17 +0000241 bool ContainsUninitField = false;
242
243 // Are all of this non-union's fields initialized?
244 for (const FieldDecl *I : RD->fields()) {
245
246 const auto FieldVal =
247 State->getLValue(I, loc::MemRegionVal(R)).castAs<loc::MemRegionVal>();
248 const auto *FR = FieldVal.getRegionAs<FieldRegion>();
249 QualType T = I->getType();
250
251 // If LocalChain already contains FR, then we encountered a cyclic
252 // reference. In this case, region FR is already under checking at an
253 // earlier node in the directed tree.
254 if (LocalChain.contains(FR))
255 return false;
256
257 if (T->isStructureOrClassType()) {
Kristof Umann015b0592018-08-13 18:43:08 +0000258 if (isNonUnionUninit(FR, LocalChain.add(RegularField(FR))))
Kristof Umann30f08652018-06-18 11:50:17 +0000259 ContainsUninitField = true;
260 continue;
261 }
262
263 if (T->isUnionType()) {
264 if (isUnionUninit(FR)) {
Kristof Umann015b0592018-08-13 18:43:08 +0000265 if (addFieldToUninits(LocalChain.add(RegularField(FR))))
Kristof Umann30f08652018-06-18 11:50:17 +0000266 ContainsUninitField = true;
267 } else
268 IsAnyFieldInitialized = true;
269 continue;
270 }
271
272 if (T->isArrayType()) {
273 IsAnyFieldInitialized = true;
274 continue;
275 }
276
Kristof Umannf0dd1012018-09-14 08:58:21 +0000277 if (isDereferencableType(T)) {
Kristof Umannceb5f652018-09-14 09:07:40 +0000278 if (isDereferencableUninit(FR, LocalChain))
Kristof Umann30f08652018-06-18 11:50:17 +0000279 ContainsUninitField = true;
280 continue;
281 }
282
Kristof Umann20e85ba2018-06-19 08:35:02 +0000283 if (isPrimitiveType(T)) {
284 SVal V = State->getSVal(FieldVal);
Kristof Umann30f08652018-06-18 11:50:17 +0000285
Kristof Umann20e85ba2018-06-19 08:35:02 +0000286 if (isPrimitiveUninit(V)) {
Kristof Umann015b0592018-08-13 18:43:08 +0000287 if (addFieldToUninits(LocalChain.add(RegularField(FR))))
Kristof Umann20e85ba2018-06-19 08:35:02 +0000288 ContainsUninitField = true;
289 }
290 continue;
Kristof Umann30f08652018-06-18 11:50:17 +0000291 }
Kristof Umann20e85ba2018-06-19 08:35:02 +0000292
293 llvm_unreachable("All cases are handled!");
Kristof Umann30f08652018-06-18 11:50:17 +0000294 }
295
Kristof Umannceb5f652018-09-14 09:07:40 +0000296 // Checking bases. The checker will regard inherited data members as direct
297 // fields.
Kristof Umann30f08652018-06-18 11:50:17 +0000298 const auto *CXXRD = dyn_cast<CXXRecordDecl>(RD);
299 if (!CXXRD)
300 return ContainsUninitField;
301
302 for (const CXXBaseSpecifier &BaseSpec : CXXRD->bases()) {
303 const auto *BaseRegion = State->getLValue(BaseSpec, R)
304 .castAs<loc::MemRegionVal>()
305 .getRegionAs<TypedValueRegion>();
306
Kristof Umannb59b45e2018-08-21 12:16:59 +0000307 // If the head of the list is also a BaseClass, we'll overwrite it to avoid
308 // note messages like 'this->A::B::x'.
309 if (!LocalChain.isEmpty() && LocalChain.getHead().isBase()) {
310 if (isNonUnionUninit(BaseRegion, LocalChain.replaceHead(
311 BaseClass(BaseSpec.getType()))))
312 ContainsUninitField = true;
313 } else {
314 if (isNonUnionUninit(BaseRegion,
315 LocalChain.add(BaseClass(BaseSpec.getType()))))
316 ContainsUninitField = true;
317 }
Kristof Umann30f08652018-06-18 11:50:17 +0000318 }
319
320 return ContainsUninitField;
321}
322
323bool FindUninitializedFields::isUnionUninit(const TypedValueRegion *R) {
324 assert(R->getValueType()->isUnionType() &&
325 "This method only checks union objects!");
326 // TODO: Implement support for union fields.
327 return false;
328}
329
Kristof Umann30f08652018-06-18 11:50:17 +0000330bool FindUninitializedFields::isPrimitiveUninit(const SVal &V) {
331 if (V.isUndef())
332 return true;
333
334 IsAnyFieldInitialized = true;
335 return false;
336}
337
338//===----------------------------------------------------------------------===//
339// Methods for FieldChainInfo.
340//===----------------------------------------------------------------------===//
341
Kristof Umann015b0592018-08-13 18:43:08 +0000342const FieldRegion *FieldChainInfo::getUninitRegion() const {
Kristof Umann30f08652018-06-18 11:50:17 +0000343 assert(!Chain.isEmpty() && "Empty fieldchain!");
Kristof Umannceb5f652018-09-14 09:07:40 +0000344
345 // ImmutableList::getHead() isn't a const method, hence the not too nice
346 // implementation.
Kristof Umann015b0592018-08-13 18:43:08 +0000347 return (*Chain.begin()).getRegion();
Kristof Umann30f08652018-06-18 11:50:17 +0000348}
349
Kristof Umann015b0592018-08-13 18:43:08 +0000350bool FieldChainInfo::contains(const FieldRegion *FR) const {
351 for (const FieldNode &Node : Chain) {
352 if (Node.isSameRegion(FR))
353 return true;
354 }
355 return false;
Kristof Umann30f08652018-06-18 11:50:17 +0000356}
357
Kristof Umanna37bba42018-08-13 18:22:22 +0000358/// Prints every element except the last to `Out`. Since ImmutableLists store
359/// elements in reverse order, and have no reverse iterators, we use a
360/// recursive function to print the fieldchain correctly. The last element in
Kristof Umannceb5f652018-09-14 09:07:40 +0000361/// the chain is to be printed by `FieldChainInfo::print`.
Kristof Umanna37bba42018-08-13 18:22:22 +0000362static void printTail(llvm::raw_ostream &Out,
363 const FieldChainInfo::FieldChainImpl *L);
364
Kristof Umannceb5f652018-09-14 09:07:40 +0000365// FIXME: This function constructs an incorrect string in the following case:
Kristof Umann30f08652018-06-18 11:50:17 +0000366//
367// struct Base { int x; };
368// struct D1 : Base {}; struct D2 : Base {};
369//
370// struct MostDerived : D1, D2 {
371// MostDerived() {}
372// }
373//
374// A call to MostDerived::MostDerived() will cause two notes that say
375// "uninitialized field 'this->x'", but we can't refer to 'x' directly,
376// we need an explicit namespace resolution whether the uninit field was
377// 'D1::x' or 'D2::x'.
Kristof Umann015b0592018-08-13 18:43:08 +0000378void FieldChainInfo::printNoteMsg(llvm::raw_ostream &Out) const {
Kristof Umann30f08652018-06-18 11:50:17 +0000379 if (Chain.isEmpty())
380 return;
381
Kristof Umanna37bba42018-08-13 18:22:22 +0000382 const FieldChainImpl *L = Chain.getInternalPointer();
Kristof Umann015b0592018-08-13 18:43:08 +0000383 const FieldNode &LastField = L->getHead();
384
385 LastField.printNoteMsg(Out);
386 Out << '\'';
387
388 for (const FieldNode &Node : Chain)
389 Node.printPrefix(Out);
390
391 Out << "this->";
Kristof Umann30f08652018-06-18 11:50:17 +0000392 printTail(Out, L->getTail());
Kristof Umann015b0592018-08-13 18:43:08 +0000393 LastField.printNode(Out);
394 Out << '\'';
Kristof Umann30f08652018-06-18 11:50:17 +0000395}
396
Kristof Umanna37bba42018-08-13 18:22:22 +0000397static void printTail(llvm::raw_ostream &Out,
398 const FieldChainInfo::FieldChainImpl *L) {
Kristof Umann30f08652018-06-18 11:50:17 +0000399 if (!L)
400 return;
401
402 printTail(Out, L->getTail());
Kristof Umann015b0592018-08-13 18:43:08 +0000403
404 L->getHead().printNode(Out);
405 L->getHead().printSeparator(Out);
Kristof Umann30f08652018-06-18 11:50:17 +0000406}
407
408//===----------------------------------------------------------------------===//
409// Utility functions.
410//===----------------------------------------------------------------------===//
411
Kristof Umanncc852442018-07-12 13:13:46 +0000412static Optional<nonloc::LazyCompoundVal>
Kristof Umann30f08652018-06-18 11:50:17 +0000413getObjectVal(const CXXConstructorDecl *CtorDecl, CheckerContext &Context) {
414
415 Loc ThisLoc = Context.getSValBuilder().getCXXThis(CtorDecl->getParent(),
416 Context.getStackFrame());
417 // Getting the value for 'this'.
418 SVal This = Context.getState()->getSVal(ThisLoc);
419
420 // Getting the value for '*this'.
421 SVal Object = Context.getState()->getSVal(This.castAs<Loc>());
422
423 return Object.getAs<nonloc::LazyCompoundVal>();
424}
425
Kristof Umann0735cfb2018-08-08 12:23:02 +0000426static bool willObjectBeAnalyzedLater(const CXXConstructorDecl *Ctor,
Kristof Umanna37bba42018-08-13 18:22:22 +0000427 CheckerContext &Context) {
Kristof Umann30f08652018-06-18 11:50:17 +0000428
Kristof Umann0735cfb2018-08-08 12:23:02 +0000429 Optional<nonloc::LazyCompoundVal> CurrentObject = getObjectVal(Ctor, Context);
430 if (!CurrentObject)
431 return false;
432
433 const LocationContext *LC = Context.getLocationContext();
434 while ((LC = LC->getParent())) {
435
436 // If \p Ctor was called by another constructor.
437 const auto *OtherCtor = dyn_cast<CXXConstructorDecl>(LC->getDecl());
438 if (!OtherCtor)
439 continue;
440
441 Optional<nonloc::LazyCompoundVal> OtherObject =
442 getObjectVal(OtherCtor, Context);
443 if (!OtherObject)
444 continue;
445
446 // If the CurrentObject is a subregion of OtherObject, it will be analyzed
447 // during the analysis of OtherObject.
448 if (CurrentObject->getRegion()->isSubRegionOf(OtherObject->getRegion()))
Kristof Umann30f08652018-06-18 11:50:17 +0000449 return true;
Kristof Umann30f08652018-06-18 11:50:17 +0000450 }
Kristof Umann0735cfb2018-08-08 12:23:02 +0000451
Kristof Umann30f08652018-06-18 11:50:17 +0000452 return false;
453}
454
Kristof Umannd6145d92018-09-14 10:10:09 +0000455static bool shouldIgnoreRecord(const RecordDecl *RD, StringRef Pattern) {
456 llvm::Regex R(Pattern);
457
458 for (const FieldDecl *FD : RD->fields()) {
459 if (R.match(FD->getType().getAsString()))
460 return true;
461 if (R.match(FD->getName()))
462 return true;
463 }
464
465 return false;
466}
467
Kristof Umannf0dd1012018-09-14 08:58:21 +0000468std::string clang::ento::getVariableName(const FieldDecl *Field) {
Kristof Umann8c119092018-07-13 12:54:47 +0000469 // If Field is a captured lambda variable, Field->getName() will return with
470 // an empty string. We can however acquire it's name from the lambda's
471 // captures.
472 const auto *CXXParent = dyn_cast<CXXRecordDecl>(Field->getParent());
473
474 if (CXXParent && CXXParent->isLambda()) {
475 assert(CXXParent->captures_begin());
476 auto It = CXXParent->captures_begin() + Field->getFieldIndex();
Kristof Umannf0dd1012018-09-14 08:58:21 +0000477
478 if (It->capturesVariable())
479 return llvm::Twine("/*captured variable*/" +
480 It->getCapturedVar()->getName())
481 .str();
482
483 if (It->capturesThis())
484 return "/*'this' capture*/";
485
486 llvm_unreachable("No other capture type is expected!");
Kristof Umann8c119092018-07-13 12:54:47 +0000487 }
488
489 return Field->getName();
490}
491
Kristof Umann30f08652018-06-18 11:50:17 +0000492void ento::registerUninitializedObjectChecker(CheckerManager &Mgr) {
493 auto Chk = Mgr.registerChecker<UninitializedObjectChecker>();
Kristof Umannceb5f652018-09-14 09:07:40 +0000494
Kristof Umann6cec6c42018-09-14 09:39:26 +0000495 AnalyzerOptions &AnOpts = Mgr.getAnalyzerOptions();
496 UninitObjCheckerOptions &ChOpts = Chk->Opts;
497
Kristof Umannd6145d92018-09-14 10:10:09 +0000498 ChOpts.IsPedantic =
499 AnOpts.getBooleanOption("Pedantic", /*DefaultVal*/ false, Chk);
500 ChOpts.ShouldConvertNotesToWarnings =
501 AnOpts.getBooleanOption("NotesAsWarnings", /*DefaultVal*/ false, Chk);
Kristof Umann6cec6c42018-09-14 09:39:26 +0000502 ChOpts.CheckPointeeInitialization = AnOpts.getBooleanOption(
Kristof Umanna3f7b582018-08-07 12:55:26 +0000503 "CheckPointeeInitialization", /*DefaultVal*/ false, Chk);
Kristof Umannd6145d92018-09-14 10:10:09 +0000504 ChOpts.IgnoredRecordsWithFieldPattern =
505 AnOpts.getOptionAsString("IgnoreRecordsWithField",
506 /*DefaultVal*/ "", Chk);
Kristof Umann30f08652018-06-18 11:50:17 +0000507}