blob: 50ab7c0a0e82a7ba3706da3e580de0af72e17493 [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 Umannf0513792018-09-14 10:18:26 +0000277 SVal V = State->getSVal(FieldVal);
278
279 if (isDereferencableType(T) || V.getAs<nonloc::LocAsInteger>()) {
Kristof Umannceb5f652018-09-14 09:07:40 +0000280 if (isDereferencableUninit(FR, LocalChain))
Kristof Umann30f08652018-06-18 11:50:17 +0000281 ContainsUninitField = true;
282 continue;
283 }
284
Kristof Umann20e85ba2018-06-19 08:35:02 +0000285 if (isPrimitiveType(T)) {
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 +0000342bool FieldChainInfo::contains(const FieldRegion *FR) const {
343 for (const FieldNode &Node : Chain) {
344 if (Node.isSameRegion(FR))
345 return true;
346 }
347 return false;
Kristof Umann30f08652018-06-18 11:50:17 +0000348}
349
Kristof Umanna37bba42018-08-13 18:22:22 +0000350/// Prints every element except the last to `Out`. Since ImmutableLists store
351/// elements in reverse order, and have no reverse iterators, we use a
352/// recursive function to print the fieldchain correctly. The last element in
Kristof Umannceb5f652018-09-14 09:07:40 +0000353/// the chain is to be printed by `FieldChainInfo::print`.
Kristof Umanna37bba42018-08-13 18:22:22 +0000354static void printTail(llvm::raw_ostream &Out,
Kristof Umann82eeca32018-09-23 09:16:27 +0000355 const FieldChainInfo::FieldChain L);
Kristof Umanna37bba42018-08-13 18:22:22 +0000356
Kristof Umannceb5f652018-09-14 09:07:40 +0000357// FIXME: This function constructs an incorrect string in the following case:
Kristof Umann30f08652018-06-18 11:50:17 +0000358//
359// struct Base { int x; };
360// struct D1 : Base {}; struct D2 : Base {};
361//
362// struct MostDerived : D1, D2 {
363// MostDerived() {}
364// }
365//
366// A call to MostDerived::MostDerived() will cause two notes that say
367// "uninitialized field 'this->x'", but we can't refer to 'x' directly,
368// we need an explicit namespace resolution whether the uninit field was
369// 'D1::x' or 'D2::x'.
Kristof Umann015b0592018-08-13 18:43:08 +0000370void FieldChainInfo::printNoteMsg(llvm::raw_ostream &Out) const {
Kristof Umann30f08652018-06-18 11:50:17 +0000371 if (Chain.isEmpty())
372 return;
373
Kristof Umann82eeca32018-09-23 09:16:27 +0000374 const FieldNode &LastField = getHead();
Kristof Umann015b0592018-08-13 18:43:08 +0000375
376 LastField.printNoteMsg(Out);
377 Out << '\'';
378
379 for (const FieldNode &Node : Chain)
380 Node.printPrefix(Out);
381
382 Out << "this->";
Kristof Umann82eeca32018-09-23 09:16:27 +0000383 printTail(Out, Chain.getTail());
Kristof Umann015b0592018-08-13 18:43:08 +0000384 LastField.printNode(Out);
385 Out << '\'';
Kristof Umann30f08652018-06-18 11:50:17 +0000386}
387
Kristof Umanna37bba42018-08-13 18:22:22 +0000388static void printTail(llvm::raw_ostream &Out,
Kristof Umann82eeca32018-09-23 09:16:27 +0000389 const FieldChainInfo::FieldChain L) {
390 if (L.isEmpty())
Kristof Umann30f08652018-06-18 11:50:17 +0000391 return;
392
Kristof Umann82eeca32018-09-23 09:16:27 +0000393 printTail(Out, L.getTail());
Kristof Umann015b0592018-08-13 18:43:08 +0000394
Kristof Umann82eeca32018-09-23 09:16:27 +0000395 L.getHead().printNode(Out);
396 L.getHead().printSeparator(Out);
Kristof Umann30f08652018-06-18 11:50:17 +0000397}
398
399//===----------------------------------------------------------------------===//
400// Utility functions.
401//===----------------------------------------------------------------------===//
402
Kristof Umanncc852442018-07-12 13:13:46 +0000403static Optional<nonloc::LazyCompoundVal>
Kristof Umann30f08652018-06-18 11:50:17 +0000404getObjectVal(const CXXConstructorDecl *CtorDecl, CheckerContext &Context) {
405
406 Loc ThisLoc = Context.getSValBuilder().getCXXThis(CtorDecl->getParent(),
407 Context.getStackFrame());
408 // Getting the value for 'this'.
409 SVal This = Context.getState()->getSVal(ThisLoc);
410
411 // Getting the value for '*this'.
412 SVal Object = Context.getState()->getSVal(This.castAs<Loc>());
413
414 return Object.getAs<nonloc::LazyCompoundVal>();
415}
416
Kristof Umann0735cfb2018-08-08 12:23:02 +0000417static bool willObjectBeAnalyzedLater(const CXXConstructorDecl *Ctor,
Kristof Umanna37bba42018-08-13 18:22:22 +0000418 CheckerContext &Context) {
Kristof Umann30f08652018-06-18 11:50:17 +0000419
Kristof Umann0735cfb2018-08-08 12:23:02 +0000420 Optional<nonloc::LazyCompoundVal> CurrentObject = getObjectVal(Ctor, Context);
421 if (!CurrentObject)
422 return false;
423
424 const LocationContext *LC = Context.getLocationContext();
425 while ((LC = LC->getParent())) {
426
427 // If \p Ctor was called by another constructor.
428 const auto *OtherCtor = dyn_cast<CXXConstructorDecl>(LC->getDecl());
429 if (!OtherCtor)
430 continue;
431
432 Optional<nonloc::LazyCompoundVal> OtherObject =
433 getObjectVal(OtherCtor, Context);
434 if (!OtherObject)
435 continue;
436
437 // If the CurrentObject is a subregion of OtherObject, it will be analyzed
438 // during the analysis of OtherObject.
439 if (CurrentObject->getRegion()->isSubRegionOf(OtherObject->getRegion()))
Kristof Umann30f08652018-06-18 11:50:17 +0000440 return true;
Kristof Umann30f08652018-06-18 11:50:17 +0000441 }
Kristof Umann0735cfb2018-08-08 12:23:02 +0000442
Kristof Umann30f08652018-06-18 11:50:17 +0000443 return false;
444}
445
Kristof Umannd6145d92018-09-14 10:10:09 +0000446static bool shouldIgnoreRecord(const RecordDecl *RD, StringRef Pattern) {
447 llvm::Regex R(Pattern);
448
449 for (const FieldDecl *FD : RD->fields()) {
450 if (R.match(FD->getType().getAsString()))
451 return true;
452 if (R.match(FD->getName()))
453 return true;
454 }
455
456 return false;
457}
458
Kristof Umannf0dd1012018-09-14 08:58:21 +0000459std::string clang::ento::getVariableName(const FieldDecl *Field) {
Kristof Umann8c119092018-07-13 12:54:47 +0000460 // If Field is a captured lambda variable, Field->getName() will return with
461 // an empty string. We can however acquire it's name from the lambda's
462 // captures.
463 const auto *CXXParent = dyn_cast<CXXRecordDecl>(Field->getParent());
464
465 if (CXXParent && CXXParent->isLambda()) {
466 assert(CXXParent->captures_begin());
467 auto It = CXXParent->captures_begin() + Field->getFieldIndex();
Kristof Umannf0dd1012018-09-14 08:58:21 +0000468
469 if (It->capturesVariable())
470 return llvm::Twine("/*captured variable*/" +
471 It->getCapturedVar()->getName())
472 .str();
473
474 if (It->capturesThis())
475 return "/*'this' capture*/";
476
477 llvm_unreachable("No other capture type is expected!");
Kristof Umann8c119092018-07-13 12:54:47 +0000478 }
479
480 return Field->getName();
481}
482
Kristof Umann30f08652018-06-18 11:50:17 +0000483void ento::registerUninitializedObjectChecker(CheckerManager &Mgr) {
484 auto Chk = Mgr.registerChecker<UninitializedObjectChecker>();
Kristof Umannceb5f652018-09-14 09:07:40 +0000485
Kristof Umann6cec6c42018-09-14 09:39:26 +0000486 AnalyzerOptions &AnOpts = Mgr.getAnalyzerOptions();
487 UninitObjCheckerOptions &ChOpts = Chk->Opts;
488
Kristof Umannd6145d92018-09-14 10:10:09 +0000489 ChOpts.IsPedantic =
490 AnOpts.getBooleanOption("Pedantic", /*DefaultVal*/ false, Chk);
491 ChOpts.ShouldConvertNotesToWarnings =
492 AnOpts.getBooleanOption("NotesAsWarnings", /*DefaultVal*/ false, Chk);
Kristof Umann6cec6c42018-09-14 09:39:26 +0000493 ChOpts.CheckPointeeInitialization = AnOpts.getBooleanOption(
Kristof Umanna3f7b582018-08-07 12:55:26 +0000494 "CheckPointeeInitialization", /*DefaultVal*/ false, Chk);
Kristof Umannd6145d92018-09-14 10:10:09 +0000495 ChOpts.IgnoredRecordsWithFieldPattern =
496 AnOpts.getOptionAsString("IgnoreRecordsWithField",
497 /*DefaultVal*/ "", Chk);
Kristof Umann30f08652018-06-18 11:50:17 +0000498}