balazske created this revision. Herald added subscribers: cfe-commits, ASDenysPetrov, martong, Charusso, gamesh411, dkrupp, donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, szepet, baloghadamsoftware, xazax.hun. Herald added a reviewer: Szelethus. Herald added a project: clang.
Use of BuiltinBug is replaced by BugType. Class BuiltinBug seems to have no benefits and is confusing. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D84494 Files: clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp Index: clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp =================================================================== --- clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp +++ clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp @@ -30,8 +30,9 @@ : public Checker< check::Location, check::Bind, EventDispatcher<ImplicitNullDerefEvent> > { - mutable std::unique_ptr<BuiltinBug> BT_null; - mutable std::unique_ptr<BuiltinBug> BT_undef; + BugType BT_Null{this, "Dereference of null pointer", categories::MemoryError}; + BugType BT_Undef{this, "Dereference of undefined pointer value", + categories::MemoryError}; void reportBug(ProgramStateRef State, const Stmt *S, CheckerContext &C) const; @@ -123,11 +124,6 @@ if (!N) return; - // We know that 'location' cannot be non-null. This is what - // we call an "explicit" null dereference. - if (!BT_null) - BT_null.reset(new BuiltinBug(this, "Dereference of null pointer")); - SmallString<100> buf; llvm::raw_svector_ostream os(buf); @@ -180,7 +176,7 @@ } auto report = std::make_unique<PathSensitiveBugReport>( - *BT_null, buf.empty() ? BT_null->getDescription() : StringRef(buf), N); + BT_Null, buf.empty() ? BT_Null.getDescription() : StringRef(buf), N); bugreporter::trackExpressionValue(N, bugreporter::getDerefExpr(S), *report); @@ -196,12 +192,8 @@ // Check for dereference of an undefined value. if (l.isUndef()) { if (ExplodedNode *N = C.generateErrorNode()) { - if (!BT_undef) - BT_undef.reset( - new BuiltinBug(this, "Dereference of undefined pointer value")); - auto report = std::make_unique<PathSensitiveBugReport>( - *BT_undef, BT_undef->getDescription(), N); + BT_Undef, BT_Undef.getDescription(), N); bugreporter::trackExpressionValue(N, bugreporter::getDerefExpr(S), *report); C.emitReport(std::move(report)); } @@ -220,6 +212,8 @@ std::tie(notNullState, nullState) = state->assume(location); // The explicit NULL case. + // We know that 'location' cannot be non-null. This is what + // we call an "explicit" null dereference. if (nullState) { if (!notNullState) { const Expr *expr = getDereferenceExpr(S);
Index: clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp =================================================================== --- clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp +++ clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp @@ -30,8 +30,9 @@ : public Checker< check::Location, check::Bind, EventDispatcher<ImplicitNullDerefEvent> > { - mutable std::unique_ptr<BuiltinBug> BT_null; - mutable std::unique_ptr<BuiltinBug> BT_undef; + BugType BT_Null{this, "Dereference of null pointer", categories::MemoryError}; + BugType BT_Undef{this, "Dereference of undefined pointer value", + categories::MemoryError}; void reportBug(ProgramStateRef State, const Stmt *S, CheckerContext &C) const; @@ -123,11 +124,6 @@ if (!N) return; - // We know that 'location' cannot be non-null. This is what - // we call an "explicit" null dereference. - if (!BT_null) - BT_null.reset(new BuiltinBug(this, "Dereference of null pointer")); - SmallString<100> buf; llvm::raw_svector_ostream os(buf); @@ -180,7 +176,7 @@ } auto report = std::make_unique<PathSensitiveBugReport>( - *BT_null, buf.empty() ? BT_null->getDescription() : StringRef(buf), N); + BT_Null, buf.empty() ? BT_Null.getDescription() : StringRef(buf), N); bugreporter::trackExpressionValue(N, bugreporter::getDerefExpr(S), *report); @@ -196,12 +192,8 @@ // Check for dereference of an undefined value. if (l.isUndef()) { if (ExplodedNode *N = C.generateErrorNode()) { - if (!BT_undef) - BT_undef.reset( - new BuiltinBug(this, "Dereference of undefined pointer value")); - auto report = std::make_unique<PathSensitiveBugReport>( - *BT_undef, BT_undef->getDescription(), N); + BT_Undef, BT_Undef.getDescription(), N); bugreporter::trackExpressionValue(N, bugreporter::getDerefExpr(S), *report); C.emitReport(std::move(report)); } @@ -220,6 +212,8 @@ std::tie(notNullState, nullState) = state->assume(location); // The explicit NULL case. + // We know that 'location' cannot be non-null. This is what + // we call an "explicit" null dereference. if (nullState) { if (!notNullState) { const Expr *expr = getDereferenceExpr(S);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits