UninitializedObjectChecker.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  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. #include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
  20. #include "UninitializedObject.h"
  21. #include "clang/ASTMatchers/ASTMatchFinder.h"
  22. #include "clang/Driver/DriverDiagnostic.h"
  23. #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
  24. #include "clang/StaticAnalyzer/Core/Checker.h"
  25. #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
  26. #include "clang/StaticAnalyzer/Core/PathSensitive/DynamicType.h"
  27. using namespace clang;
  28. using namespace clang::ento;
  29. using namespace clang::ast_matchers;
  30. /// We'll mark fields (and pointee of fields) that are confirmed to be
  31. /// uninitialized as already analyzed.
  32. REGISTER_SET_WITH_PROGRAMSTATE(AnalyzedRegions, const MemRegion *)
  33. namespace {
  34. class UninitializedObjectChecker
  35. : public Checker<check::EndFunction, check::DeadSymbols> {
  36. std::unique_ptr<BuiltinBug> BT_uninitField;
  37. public:
  38. // The fields of this struct will be initialized when registering the checker.
  39. UninitObjCheckerOptions Opts;
  40. UninitializedObjectChecker()
  41. : BT_uninitField(new BuiltinBug(this, "Uninitialized fields")) {}
  42. void checkEndFunction(const ReturnStmt *RS, CheckerContext &C) const;
  43. void checkDeadSymbols(SymbolReaper &SR, CheckerContext &C) const;
  44. };
  45. /// A basic field type, that is not a pointer or a reference, it's dynamic and
  46. /// static type is the same.
  47. class RegularField final : public FieldNode {
  48. public:
  49. RegularField(const FieldRegion *FR) : FieldNode(FR) {}
  50. void printNoteMsg(llvm::raw_ostream &Out) const override {
  51. Out << "uninitialized field ";
  52. }
  53. void printPrefix(llvm::raw_ostream &Out) const override {}
  54. void printNode(llvm::raw_ostream &Out) const override {
  55. Out << getVariableName(getDecl());
  56. }
  57. void printSeparator(llvm::raw_ostream &Out) const override { Out << '.'; }
  58. };
  59. /// Represents that the FieldNode that comes after this is declared in a base
  60. /// of the previous FieldNode. As such, this descendant doesn't wrap a
  61. /// FieldRegion, and is purely a tool to describe a relation between two other
  62. /// FieldRegion wrapping descendants.
  63. class BaseClass final : public FieldNode {
  64. const QualType BaseClassT;
  65. public:
  66. BaseClass(const QualType &T) : FieldNode(nullptr), BaseClassT(T) {
  67. assert(!T.isNull());
  68. assert(T->getAsCXXRecordDecl());
  69. }
  70. void printNoteMsg(llvm::raw_ostream &Out) const override {
  71. llvm_unreachable("This node can never be the final node in the "
  72. "fieldchain!");
  73. }
  74. void printPrefix(llvm::raw_ostream &Out) const override {}
  75. void printNode(llvm::raw_ostream &Out) const override {
  76. Out << BaseClassT->getAsCXXRecordDecl()->getName() << "::";
  77. }
  78. void printSeparator(llvm::raw_ostream &Out) const override {}
  79. bool isBase() const override { return true; }
  80. };
  81. } // end of anonymous namespace
  82. // Utility function declarations.
  83. /// Returns the region that was constructed by CtorDecl, or nullptr if that
  84. /// isn't possible.
  85. static const TypedValueRegion *
  86. getConstructedRegion(const CXXConstructorDecl *CtorDecl,
  87. CheckerContext &Context);
  88. /// Checks whether the object constructed by \p Ctor will be analyzed later
  89. /// (e.g. if the object is a field of another object, in which case we'd check
  90. /// it multiple times).
  91. static bool willObjectBeAnalyzedLater(const CXXConstructorDecl *Ctor,
  92. CheckerContext &Context);
  93. /// Checks whether RD contains a field with a name or type name that matches
  94. /// \p Pattern.
  95. static bool shouldIgnoreRecord(const RecordDecl *RD, StringRef Pattern);
  96. /// Checks _syntactically_ whether it is possible to access FD from the record
  97. /// that contains it without a preceding assert (even if that access happens
  98. /// inside a method). This is mainly used for records that act like unions, like
  99. /// having multiple bit fields, with only a fraction being properly initialized.
  100. /// If these fields are properly guarded with asserts, this method returns
  101. /// false.
  102. ///
  103. /// Since this check is done syntactically, this method could be inaccurate.
  104. static bool hasUnguardedAccess(const FieldDecl *FD, ProgramStateRef State);
  105. //===----------------------------------------------------------------------===//
  106. // Methods for UninitializedObjectChecker.
  107. //===----------------------------------------------------------------------===//
  108. void UninitializedObjectChecker::checkEndFunction(
  109. const ReturnStmt *RS, CheckerContext &Context) const {
  110. const auto *CtorDecl = dyn_cast_or_null<CXXConstructorDecl>(
  111. Context.getLocationContext()->getDecl());
  112. if (!CtorDecl)
  113. return;
  114. if (!CtorDecl->isUserProvided())
  115. return;
  116. if (CtorDecl->getParent()->isUnion())
  117. return;
  118. // This avoids essentially the same error being reported multiple times.
  119. if (willObjectBeAnalyzedLater(CtorDecl, Context))
  120. return;
  121. const TypedValueRegion *R = getConstructedRegion(CtorDecl, Context);
  122. if (!R)
  123. return;
  124. FindUninitializedFields F(Context.getState(), R, Opts);
  125. std::pair<ProgramStateRef, const UninitFieldMap &> UninitInfo =
  126. F.getResults();
  127. ProgramStateRef UpdatedState = UninitInfo.first;
  128. const UninitFieldMap &UninitFields = UninitInfo.second;
  129. if (UninitFields.empty()) {
  130. Context.addTransition(UpdatedState);
  131. return;
  132. }
  133. // There are uninitialized fields in the record.
  134. ExplodedNode *Node = Context.generateNonFatalErrorNode(UpdatedState);
  135. if (!Node)
  136. return;
  137. PathDiagnosticLocation LocUsedForUniqueing;
  138. const Stmt *CallSite = Context.getStackFrame()->getCallSite();
  139. if (CallSite)
  140. LocUsedForUniqueing = PathDiagnosticLocation::createBegin(
  141. CallSite, Context.getSourceManager(), Node->getLocationContext());
  142. // For Plist consumers that don't support notes just yet, we'll convert notes
  143. // to warnings.
  144. if (Opts.ShouldConvertNotesToWarnings) {
  145. for (const auto &Pair : UninitFields) {
  146. auto Report = std::make_unique<PathSensitiveBugReport>(
  147. *BT_uninitField, Pair.second, Node, LocUsedForUniqueing,
  148. Node->getLocationContext()->getDecl());
  149. Context.emitReport(std::move(Report));
  150. }
  151. return;
  152. }
  153. SmallString<100> WarningBuf;
  154. llvm::raw_svector_ostream WarningOS(WarningBuf);
  155. WarningOS << UninitFields.size() << " uninitialized field"
  156. << (UninitFields.size() == 1 ? "" : "s")
  157. << " at the end of the constructor call";
  158. auto Report = std::make_unique<PathSensitiveBugReport>(
  159. *BT_uninitField, WarningOS.str(), Node, LocUsedForUniqueing,
  160. Node->getLocationContext()->getDecl());
  161. for (const auto &Pair : UninitFields) {
  162. Report->addNote(Pair.second,
  163. PathDiagnosticLocation::create(Pair.first->getDecl(),
  164. Context.getSourceManager()));
  165. }
  166. Context.emitReport(std::move(Report));
  167. }
  168. void UninitializedObjectChecker::checkDeadSymbols(SymbolReaper &SR,
  169. CheckerContext &C) const {
  170. ProgramStateRef State = C.getState();
  171. for (const MemRegion *R : State->get<AnalyzedRegions>()) {
  172. if (!SR.isLiveRegion(R))
  173. State = State->remove<AnalyzedRegions>(R);
  174. }
  175. }
  176. //===----------------------------------------------------------------------===//
  177. // Methods for FindUninitializedFields.
  178. //===----------------------------------------------------------------------===//
  179. FindUninitializedFields::FindUninitializedFields(
  180. ProgramStateRef State, const TypedValueRegion *const R,
  181. const UninitObjCheckerOptions &Opts)
  182. : State(State), ObjectR(R), Opts(Opts) {
  183. isNonUnionUninit(ObjectR, FieldChainInfo(ChainFactory));
  184. // In non-pedantic mode, if ObjectR doesn't contain a single initialized
  185. // field, we'll assume that Object was intentionally left uninitialized.
  186. if (!Opts.IsPedantic && !isAnyFieldInitialized())
  187. UninitFields.clear();
  188. }
  189. bool FindUninitializedFields::addFieldToUninits(FieldChainInfo Chain,
  190. const MemRegion *PointeeR) {
  191. const FieldRegion *FR = Chain.getUninitRegion();
  192. assert((PointeeR || !isDereferencableType(FR->getDecl()->getType())) &&
  193. "One must also pass the pointee region as a parameter for "
  194. "dereferenceable fields!");
  195. if (State->getStateManager().getContext().getSourceManager().isInSystemHeader(
  196. FR->getDecl()->getLocation()))
  197. return false;
  198. if (Opts.IgnoreGuardedFields && !hasUnguardedAccess(FR->getDecl(), State))
  199. return false;
  200. if (State->contains<AnalyzedRegions>(FR))
  201. return false;
  202. if (PointeeR) {
  203. if (State->contains<AnalyzedRegions>(PointeeR)) {
  204. return false;
  205. }
  206. State = State->add<AnalyzedRegions>(PointeeR);
  207. }
  208. State = State->add<AnalyzedRegions>(FR);
  209. UninitFieldMap::mapped_type NoteMsgBuf;
  210. llvm::raw_svector_ostream OS(NoteMsgBuf);
  211. Chain.printNoteMsg(OS);
  212. return UninitFields.insert({FR, std::move(NoteMsgBuf)}).second;
  213. }
  214. bool FindUninitializedFields::isNonUnionUninit(const TypedValueRegion *R,
  215. FieldChainInfo LocalChain) {
  216. assert(R->getValueType()->isRecordType() &&
  217. !R->getValueType()->isUnionType() &&
  218. "This method only checks non-union record objects!");
  219. const RecordDecl *RD = R->getValueType()->getAsRecordDecl()->getDefinition();
  220. if (!RD) {
  221. IsAnyFieldInitialized = true;
  222. return true;
  223. }
  224. if (!Opts.IgnoredRecordsWithFieldPattern.empty() &&
  225. shouldIgnoreRecord(RD, Opts.IgnoredRecordsWithFieldPattern)) {
  226. IsAnyFieldInitialized = true;
  227. return false;
  228. }
  229. bool ContainsUninitField = false;
  230. // Are all of this non-union's fields initialized?
  231. for (const FieldDecl *I : RD->fields()) {
  232. const auto FieldVal =
  233. State->getLValue(I, loc::MemRegionVal(R)).castAs<loc::MemRegionVal>();
  234. const auto *FR = FieldVal.getRegionAs<FieldRegion>();
  235. QualType T = I->getType();
  236. // If LocalChain already contains FR, then we encountered a cyclic
  237. // reference. In this case, region FR is already under checking at an
  238. // earlier node in the directed tree.
  239. if (LocalChain.contains(FR))
  240. return false;
  241. if (T->isStructureOrClassType()) {
  242. if (isNonUnionUninit(FR, LocalChain.add(RegularField(FR))))
  243. ContainsUninitField = true;
  244. continue;
  245. }
  246. if (T->isUnionType()) {
  247. if (isUnionUninit(FR)) {
  248. if (addFieldToUninits(LocalChain.add(RegularField(FR))))
  249. ContainsUninitField = true;
  250. } else
  251. IsAnyFieldInitialized = true;
  252. continue;
  253. }
  254. if (T->isArrayType()) {
  255. IsAnyFieldInitialized = true;
  256. continue;
  257. }
  258. SVal V = State->getSVal(FieldVal);
  259. if (isDereferencableType(T) || isa<nonloc::LocAsInteger>(V)) {
  260. if (isDereferencableUninit(FR, LocalChain))
  261. ContainsUninitField = true;
  262. continue;
  263. }
  264. if (isPrimitiveType(T)) {
  265. if (isPrimitiveUninit(V)) {
  266. if (addFieldToUninits(LocalChain.add(RegularField(FR))))
  267. ContainsUninitField = true;
  268. }
  269. continue;
  270. }
  271. llvm_unreachable("All cases are handled!");
  272. }
  273. // Checking bases. The checker will regard inherited data members as direct
  274. // fields.
  275. const auto *CXXRD = dyn_cast<CXXRecordDecl>(RD);
  276. if (!CXXRD)
  277. return ContainsUninitField;
  278. for (const CXXBaseSpecifier &BaseSpec : CXXRD->bases()) {
  279. const auto *BaseRegion = State->getLValue(BaseSpec, R)
  280. .castAs<loc::MemRegionVal>()
  281. .getRegionAs<TypedValueRegion>();
  282. // If the head of the list is also a BaseClass, we'll overwrite it to avoid
  283. // note messages like 'this->A::B::x'.
  284. if (!LocalChain.isEmpty() && LocalChain.getHead().isBase()) {
  285. if (isNonUnionUninit(BaseRegion, LocalChain.replaceHead(
  286. BaseClass(BaseSpec.getType()))))
  287. ContainsUninitField = true;
  288. } else {
  289. if (isNonUnionUninit(BaseRegion,
  290. LocalChain.add(BaseClass(BaseSpec.getType()))))
  291. ContainsUninitField = true;
  292. }
  293. }
  294. return ContainsUninitField;
  295. }
  296. bool FindUninitializedFields::isUnionUninit(const TypedValueRegion *R) {
  297. assert(R->getValueType()->isUnionType() &&
  298. "This method only checks union objects!");
  299. // TODO: Implement support for union fields.
  300. return false;
  301. }
  302. bool FindUninitializedFields::isPrimitiveUninit(const SVal &V) {
  303. if (V.isUndef())
  304. return true;
  305. IsAnyFieldInitialized = true;
  306. return false;
  307. }
  308. //===----------------------------------------------------------------------===//
  309. // Methods for FieldChainInfo.
  310. //===----------------------------------------------------------------------===//
  311. bool FieldChainInfo::contains(const FieldRegion *FR) const {
  312. for (const FieldNode &Node : Chain) {
  313. if (Node.isSameRegion(FR))
  314. return true;
  315. }
  316. return false;
  317. }
  318. /// Prints every element except the last to `Out`. Since ImmutableLists store
  319. /// elements in reverse order, and have no reverse iterators, we use a
  320. /// recursive function to print the fieldchain correctly. The last element in
  321. /// the chain is to be printed by `FieldChainInfo::print`.
  322. static void printTail(llvm::raw_ostream &Out,
  323. const FieldChainInfo::FieldChain L);
  324. // FIXME: This function constructs an incorrect string in the following case:
  325. //
  326. // struct Base { int x; };
  327. // struct D1 : Base {}; struct D2 : Base {};
  328. //
  329. // struct MostDerived : D1, D2 {
  330. // MostDerived() {}
  331. // }
  332. //
  333. // A call to MostDerived::MostDerived() will cause two notes that say
  334. // "uninitialized field 'this->x'", but we can't refer to 'x' directly,
  335. // we need an explicit namespace resolution whether the uninit field was
  336. // 'D1::x' or 'D2::x'.
  337. void FieldChainInfo::printNoteMsg(llvm::raw_ostream &Out) const {
  338. if (Chain.isEmpty())
  339. return;
  340. const FieldNode &LastField = getHead();
  341. LastField.printNoteMsg(Out);
  342. Out << '\'';
  343. for (const FieldNode &Node : Chain)
  344. Node.printPrefix(Out);
  345. Out << "this->";
  346. printTail(Out, Chain.getTail());
  347. LastField.printNode(Out);
  348. Out << '\'';
  349. }
  350. static void printTail(llvm::raw_ostream &Out,
  351. const FieldChainInfo::FieldChain L) {
  352. if (L.isEmpty())
  353. return;
  354. printTail(Out, L.getTail());
  355. L.getHead().printNode(Out);
  356. L.getHead().printSeparator(Out);
  357. }
  358. //===----------------------------------------------------------------------===//
  359. // Utility functions.
  360. //===----------------------------------------------------------------------===//
  361. static const TypedValueRegion *
  362. getConstructedRegion(const CXXConstructorDecl *CtorDecl,
  363. CheckerContext &Context) {
  364. Loc ThisLoc =
  365. Context.getSValBuilder().getCXXThis(CtorDecl, Context.getStackFrame());
  366. SVal ObjectV = Context.getState()->getSVal(ThisLoc);
  367. auto *R = ObjectV.getAsRegion()->getAs<TypedValueRegion>();
  368. if (R && !R->getValueType()->getAsCXXRecordDecl())
  369. return nullptr;
  370. return R;
  371. }
  372. static bool willObjectBeAnalyzedLater(const CXXConstructorDecl *Ctor,
  373. CheckerContext &Context) {
  374. const TypedValueRegion *CurrRegion = getConstructedRegion(Ctor, Context);
  375. if (!CurrRegion)
  376. return false;
  377. const LocationContext *LC = Context.getLocationContext();
  378. while ((LC = LC->getParent())) {
  379. // If \p Ctor was called by another constructor.
  380. const auto *OtherCtor = dyn_cast<CXXConstructorDecl>(LC->getDecl());
  381. if (!OtherCtor)
  382. continue;
  383. const TypedValueRegion *OtherRegion =
  384. getConstructedRegion(OtherCtor, Context);
  385. if (!OtherRegion)
  386. continue;
  387. // If the CurrRegion is a subregion of OtherRegion, it will be analyzed
  388. // during the analysis of OtherRegion.
  389. if (CurrRegion->isSubRegionOf(OtherRegion))
  390. return true;
  391. }
  392. return false;
  393. }
  394. static bool shouldIgnoreRecord(const RecordDecl *RD, StringRef Pattern) {
  395. llvm::Regex R(Pattern);
  396. for (const FieldDecl *FD : RD->fields()) {
  397. if (R.match(FD->getType().getAsString()))
  398. return true;
  399. if (R.match(FD->getName()))
  400. return true;
  401. }
  402. return false;
  403. }
  404. static const Stmt *getMethodBody(const CXXMethodDecl *M) {
  405. if (isa<CXXConstructorDecl>(M))
  406. return nullptr;
  407. if (!M->isDefined())
  408. return nullptr;
  409. return M->getDefinition()->getBody();
  410. }
  411. static bool hasUnguardedAccess(const FieldDecl *FD, ProgramStateRef State) {
  412. if (FD->getAccess() == AccessSpecifier::AS_public)
  413. return true;
  414. const auto *Parent = dyn_cast<CXXRecordDecl>(FD->getParent());
  415. if (!Parent)
  416. return true;
  417. Parent = Parent->getDefinition();
  418. assert(Parent && "The record's definition must be avaible if an uninitialized"
  419. " field of it was found!");
  420. ASTContext &AC = State->getStateManager().getContext();
  421. auto FieldAccessM = memberExpr(hasDeclaration(equalsNode(FD))).bind("access");
  422. auto AssertLikeM = callExpr(callee(functionDecl(
  423. hasAnyName("exit", "panic", "error", "Assert", "assert", "ziperr",
  424. "assfail", "db_error", "__assert", "__assert2", "_wassert",
  425. "__assert_rtn", "__assert_fail", "dtrace_assfail",
  426. "yy_fatal_error", "_XCAssertionFailureHandler",
  427. "_DTAssertionFailureHandler", "_TSAssertionFailureHandler"))));
  428. auto NoReturnFuncM = callExpr(callee(functionDecl(isNoReturn())));
  429. auto GuardM =
  430. stmt(anyOf(ifStmt(), switchStmt(), conditionalOperator(), AssertLikeM,
  431. NoReturnFuncM))
  432. .bind("guard");
  433. for (const CXXMethodDecl *M : Parent->methods()) {
  434. const Stmt *MethodBody = getMethodBody(M);
  435. if (!MethodBody)
  436. continue;
  437. auto Accesses = match(stmt(hasDescendant(FieldAccessM)), *MethodBody, AC);
  438. if (Accesses.empty())
  439. continue;
  440. const auto *FirstAccess = Accesses[0].getNodeAs<MemberExpr>("access");
  441. assert(FirstAccess);
  442. auto Guards = match(stmt(hasDescendant(GuardM)), *MethodBody, AC);
  443. if (Guards.empty())
  444. return true;
  445. const auto *FirstGuard = Guards[0].getNodeAs<Stmt>("guard");
  446. assert(FirstGuard);
  447. if (FirstAccess->getBeginLoc() < FirstGuard->getBeginLoc())
  448. return true;
  449. }
  450. return false;
  451. }
  452. std::string clang::ento::getVariableName(const FieldDecl *Field) {
  453. // If Field is a captured lambda variable, Field->getName() will return with
  454. // an empty string. We can however acquire it's name from the lambda's
  455. // captures.
  456. const auto *CXXParent = dyn_cast<CXXRecordDecl>(Field->getParent());
  457. if (CXXParent && CXXParent->isLambda()) {
  458. assert(CXXParent->captures_begin());
  459. auto It = CXXParent->captures_begin() + Field->getFieldIndex();
  460. if (It->capturesVariable())
  461. return llvm::Twine("/*captured variable*/" +
  462. It->getCapturedVar()->getName())
  463. .str();
  464. if (It->capturesThis())
  465. return "/*'this' capture*/";
  466. llvm_unreachable("No other capture type is expected!");
  467. }
  468. return std::string(Field->getName());
  469. }
  470. void ento::registerUninitializedObjectChecker(CheckerManager &Mgr) {
  471. auto Chk = Mgr.registerChecker<UninitializedObjectChecker>();
  472. const AnalyzerOptions &AnOpts = Mgr.getAnalyzerOptions();
  473. UninitObjCheckerOptions &ChOpts = Chk->Opts;
  474. ChOpts.IsPedantic = AnOpts.getCheckerBooleanOption(Chk, "Pedantic");
  475. ChOpts.ShouldConvertNotesToWarnings = AnOpts.getCheckerBooleanOption(
  476. Chk, "NotesAsWarnings");
  477. ChOpts.CheckPointeeInitialization = AnOpts.getCheckerBooleanOption(
  478. Chk, "CheckPointeeInitialization");
  479. ChOpts.IgnoredRecordsWithFieldPattern =
  480. std::string(AnOpts.getCheckerStringOption(Chk, "IgnoreRecordsWithField"));
  481. ChOpts.IgnoreGuardedFields =
  482. AnOpts.getCheckerBooleanOption(Chk, "IgnoreGuardedFields");
  483. std::string ErrorMsg;
  484. if (!llvm::Regex(ChOpts.IgnoredRecordsWithFieldPattern).isValid(ErrorMsg))
  485. Mgr.reportInvalidCheckerOptionValue(Chk, "IgnoreRecordsWithField",
  486. "a valid regex, building failed with error message "
  487. "\"" + ErrorMsg + "\"");
  488. }
  489. bool ento::shouldRegisterUninitializedObjectChecker(const CheckerManager &mgr) {
  490. return true;
  491. }