Skip to content

Commit db836ed

Browse files
authored
Revert "[analyzer] Delay the checker constructions after parsing" (#128350)
Reverts #127409 This caused a test failure: LLVM Buildbot has detected a new failure on builder `sanitizer-aarch64-linux-bootstrap-hwasan` running on `sanitizer-buildbot11` while building `clang` at step 2 "annotate". Full details are available at: https://lab.llvm.org/buildbot/#/builders/55/builds/7431 <details> <summary>Here is the relevant piece of the build log for the reference</summary> ``` Step 2 (annotate) failure: 'python ../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py' (failure) ... llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:512: note: using lld-link: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/lld-link llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:512: note: using ld64.lld: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/ld64.lld llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:512: note: using wasm-ld: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/wasm-ld llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:512: note: using ld.lld: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/ld.lld llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:512: note: using lld-link: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/lld-link llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:512: note: using ld64.lld: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/ld64.lld llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:512: note: using wasm-ld: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/wasm-ld llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/main.py:72: note: The test suite configuration requested an individual test timeout of 0 seconds but a timeout of 900 seconds was requested on the command line. Forcing timeout to be 900 seconds. -- Testing: 86643 tests, 72 workers -- Testing: FAIL: Clang :: Analysis/cxx11-crashes.cpp (1006 of 86643) ******************** TEST 'Clang :: Analysis/cxx11-crashes.cpp' FAILED ******************** Exit Code: 134 Command Output (stderr): -- RUN: at line 1: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/clang -cc1 -internal-isystem /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/lib/clang/21/include -nostdsysteminc -analyze -analyzer-constraints=range -setup-static-analyzer -analyzer-checker=core -std=c++11 -verify /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/clang/test/Analysis/cxx11-crashes.cpp + /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/clang -cc1 -internal-isystem /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/lib/clang/21/include -nostdsysteminc -analyze -analyzer-constraints=range -setup-static-analyzer -analyzer-checker=core -std=c++11 -verify /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/clang/test/Analysis/cxx11-crashes.cpp libc++abi: Pure virtual function called! /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/tools/clang/test/Analysis/Output/cxx11-crashes.cpp.script: line 1: 1936960 Aborted /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/clang -cc1 -internal-isystem /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/lib/clang/21/include -nostdsysteminc -analyze -analyzer-constraints=range -setup-static-analyzer -analyzer-checker=core -std=c++11 -verify /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/clang/test/Analysis/cxx11-crashes.cpp -- ******************** Testing: FAIL: Clang :: Analysis/stack-block-returned.cpp (1505 of 86643) ******************** TEST 'Clang :: Analysis/stack-block-returned.cpp' FAILED ******************** Exit Code: 134 Command Output (stderr): -- RUN: at line 1: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/clang -cc1 -internal-isystem /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/lib/clang/21/include -nostdsysteminc -analyze -analyzer-constraints=range -setup-static-analyzer -analyzer-checker=core -fblocks -verify /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/clang/test/Analysis/stack-block-returned.cpp + /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/clang -cc1 -internal-isystem /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/lib/clang/21/include -nostdsysteminc -analyze -analyzer-constraints=range -setup-static-analyzer -analyzer-checker=core -fblocks -verify /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/clang/test/Analysis/stack-block-returned.cpp libc++abi: Pure virtual function called! /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/tools/clang/test/Analysis/Output/stack-block-returned.cpp.script: line 1: 1940139 Aborted /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/clang -cc1 -internal-isystem /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/lib/clang/21/include -nostdsysteminc -analyze -analyzer-constraints=range -setup-static-analyzer -analyzer-checker=core -fblocks -verify /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/clang/test/Analysis/stack-block-returned.cpp -- ******************** Testing: 0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90.. Slowest Tests: -------------------------------------------------------------------------- 59.70s: Clang :: Driver/fsanitize.c 48.34s: Clang :: Preprocessor/riscv-target-features.c 41.66s: Clang :: OpenMP/target_defaultmap_codegen_01.cpp 40.68s: Clang :: OpenMP/target_update_codegen.cpp 39.21s: Clang :: Driver/arm-cortex-cpus-2.c 38.19s: Clang :: Driver/arm-cortex-cpus-1.c 36.55s: Clang :: Preprocessor/arm-target-features.c Step 11 (stage2/hwasan check) failure: stage2/hwasan check (failure) ... llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:512: note: using lld-link: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/lld-link llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:512: note: using ld64.lld: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/ld64.lld llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:512: note: using wasm-ld: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/wasm-ld llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:512: note: using ld.lld: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/ld.lld llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:512: note: using lld-link: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/lld-link llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:512: note: using ld64.lld: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/ld64.lld llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:512: note: using wasm-ld: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/wasm-ld llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/main.py:72: note: The test suite configuration requested an individual test timeout of 0 seconds but a timeout of 900 seconds was requested on the command line. Forcing timeout to be 900 seconds. -- Testing: 86643 tests, 72 workers -- Testing: FAIL: Clang :: Analysis/cxx11-crashes.cpp (1006 of 86643) ******************** TEST 'Clang :: Analysis/cxx11-crashes.cpp' FAILED ******************** Exit Code: 134 Command Output (stderr): -- RUN: at line 1: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/clang -cc1 -internal-isystem /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/lib/clang/21/include -nostdsysteminc -analyze -analyzer-constraints=range -setup-static-analyzer -analyzer-checker=core -std=c++11 -verify /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/clang/test/Analysis/cxx11-crashes.cpp + /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/clang -cc1 -internal-isystem /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/lib/clang/21/include -nostdsysteminc -analyze -analyzer-constraints=range -setup-static-analyzer -analyzer-checker=core -std=c++11 -verify /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/clang/test/Analysis/cxx11-crashes.cpp libc++abi: Pure virtual function called! /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/tools/clang/test/Analysis/Output/cxx11-crashes.cpp.script: line 1: 1936960 Aborted /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/clang -cc1 -internal-isystem /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/lib/clang/21/include -nostdsysteminc -analyze -analyzer-constraints=range -setup-static-analyzer -analyzer-checker=core -std=c++11 -verify /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/clang/test/Analysis/cxx11-crashes.cpp -- ******************** Testing: FAIL: Clang :: Analysis/stack-block-returned.cpp (1505 of 86643) ******************** TEST 'Clang :: Analysis/stack-block-returned.cpp' FAILED ******************** Exit Code: 134 Command Output (stderr): -- RUN: at line 1: /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/clang -cc1 -internal-isystem /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/lib/clang/21/include -nostdsysteminc -analyze -analyzer-constraints=range -setup-static-analyzer -analyzer-checker=core -fblocks -verify /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/clang/test/Analysis/stack-block-returned.cpp + /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/clang -cc1 -internal-isystem /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/lib/clang/21/include -nostdsysteminc -analyze -analyzer-constraints=range -setup-static-analyzer -analyzer-checker=core -fblocks -verify /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/clang/test/Analysis/stack-block-returned.cpp libc++abi: Pure virtual function called! /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/tools/clang/test/Analysis/Output/stack-block-returned.cpp.script: line 1: 1940139 Aborted /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/clang -cc1 -internal-isystem /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/lib/clang/21/include -nostdsysteminc -analyze -analyzer-constraints=range -setup-static-analyzer -analyzer-checker=core -fblocks -verify /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/clang/test/Analysis/stack-block-returned.cpp -- ******************** Testing: 0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90.. Slowest Tests: -------------------------------------------------------------------------- 59.70s: Clang :: Driver/fsanitize.c 48.34s: Clang :: Preprocessor/riscv-target-features.c 41.66s: Clang :: OpenMP/target_defaultmap_codegen_01.cpp 40.68s: Clang :: OpenMP/target_update_codegen.cpp 39.21s: Clang :: Driver/arm-cortex-cpus-2.c 38.19s: Clang :: Driver/arm-cortex-cpus-1.c 36.55s: Clang :: Preprocessor/arm-target-features.c ``` </details>
1 parent 26afa2d commit db836ed

File tree

2 files changed

+39
-40
lines changed

2 files changed

+39
-40
lines changed

clang/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -40,28 +40,17 @@ enum class OpenVariant {
4040
OpenAt
4141
};
4242

43-
static std::optional<int> getCreateFlagValue(const ASTContext &Ctx,
44-
const Preprocessor &PP) {
45-
std::optional<int> MacroVal = tryExpandAsInteger("O_CREAT", PP);
46-
if (MacroVal.has_value())
47-
return MacroVal;
48-
49-
// If we failed, fall-back to known values.
50-
if (Ctx.getTargetInfo().getTriple().getVendor() == llvm::Triple::Apple)
51-
return {0x0200};
52-
return MacroVal;
53-
}
54-
5543
namespace {
5644

57-
class UnixAPIMisuseChecker : public Checker<check::PreCall> {
45+
class UnixAPIMisuseChecker
46+
: public Checker<check::PreCall, check::ASTDecl<TranslationUnitDecl>> {
5847
const BugType BT_open{this, "Improper use of 'open'", categories::UnixAPI};
5948
const BugType BT_getline{this, "Improper use of getdelim",
6049
categories::UnixAPI};
6150
const BugType BT_pthreadOnce{this, "Improper use of 'pthread_once'",
6251
categories::UnixAPI};
6352
const BugType BT_ArgumentNull{this, "NULL pointer", categories::UnixAPI};
64-
const std::optional<int> Val_O_CREAT;
53+
mutable std::optional<uint64_t> Val_O_CREAT;
6554

6655
ProgramStateRef
6756
EnsurePtrNotNull(SVal PtrVal, const Expr *PtrExpr, CheckerContext &C,
@@ -74,9 +63,6 @@ class UnixAPIMisuseChecker : public Checker<check::PreCall> {
7463
const Expr *SizePtrExpr, CheckerContext &C, ProgramStateRef State) const;
7564

7665
public:
77-
UnixAPIMisuseChecker(const ASTContext &Ctx, const Preprocessor &PP)
78-
: Val_O_CREAT(getCreateFlagValue(Ctx, PP)) {}
79-
8066
void checkASTDecl(const TranslationUnitDecl *TU, AnalysisManager &Mgr,
8167
BugReporter &BR) const;
8268

@@ -148,6 +134,20 @@ ProgramStateRef UnixAPIMisuseChecker::EnsurePtrNotNull(
148134
return PtrNotNull;
149135
}
150136

137+
void UnixAPIMisuseChecker::checkASTDecl(const TranslationUnitDecl *TU,
138+
AnalysisManager &Mgr,
139+
BugReporter &) const {
140+
// The definition of O_CREAT is platform specific.
141+
// Try to get the macro value from the preprocessor.
142+
Val_O_CREAT = tryExpandAsInteger("O_CREAT", Mgr.getPreprocessor());
143+
// If we failed, fall-back to known values.
144+
if (!Val_O_CREAT) {
145+
if (TU->getASTContext().getTargetInfo().getTriple().getVendor() ==
146+
llvm::Triple::Apple)
147+
Val_O_CREAT = 0x0200;
148+
}
149+
}
150+
151151
//===----------------------------------------------------------------------===//
152152
// "open" (man 2 open)
153153
//===----------------------------------------------------------------------===/
@@ -262,7 +262,7 @@ void UnixAPIMisuseChecker::CheckOpenVariant(CheckerContext &C,
262262
return;
263263
}
264264

265-
if (!Val_O_CREAT.has_value()) {
265+
if (!Val_O_CREAT) {
266266
return;
267267
}
268268

@@ -276,7 +276,7 @@ void UnixAPIMisuseChecker::CheckOpenVariant(CheckerContext &C,
276276
}
277277
NonLoc oflags = V.castAs<NonLoc>();
278278
NonLoc ocreateFlag = C.getSValBuilder()
279-
.makeIntVal(Val_O_CREAT.value(), oflagsEx->getType())
279+
.makeIntVal(*Val_O_CREAT, oflagsEx->getType())
280280
.castAs<NonLoc>();
281281
SVal maskedFlagsUC = C.getSValBuilder().evalBinOpNN(state, BO_And,
282282
oflags, ocreateFlag,
@@ -621,17 +621,14 @@ void UnixAPIPortabilityChecker::checkPreStmt(const CallExpr *CE,
621621
// Registration.
622622
//===----------------------------------------------------------------------===//
623623

624-
void ento::registerUnixAPIMisuseChecker(CheckerManager &Mgr) {
625-
Mgr.registerChecker<UnixAPIMisuseChecker>(Mgr.getASTContext(),
626-
Mgr.getPreprocessor());
627-
}
628-
bool ento::shouldRegisterUnixAPIMisuseChecker(const CheckerManager &Mgr) {
629-
return true;
630-
}
624+
#define REGISTER_CHECKER(CHECKERNAME) \
625+
void ento::register##CHECKERNAME(CheckerManager &mgr) { \
626+
mgr.registerChecker<CHECKERNAME>(); \
627+
} \
628+
\
629+
bool ento::shouldRegister##CHECKERNAME(const CheckerManager &mgr) { \
630+
return true; \
631+
}
631632

632-
void ento::registerUnixAPIPortabilityChecker(CheckerManager &Mgr) {
633-
Mgr.registerChecker<UnixAPIPortabilityChecker>();
634-
}
635-
bool ento::shouldRegisterUnixAPIPortabilityChecker(const CheckerManager &Mgr) {
636-
return true;
637-
}
633+
REGISTER_CHECKER(UnixAPIMisuseChecker)
634+
REGISTER_CHECKER(UnixAPIPortabilityChecker)

clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,16 @@ class AnalysisConsumer : public AnalysisASTConsumer,
224224
}
225225
}
226226

227+
void Initialize(ASTContext &Context) override {
228+
Ctx = &Context;
229+
checkerMgr = std::make_unique<CheckerManager>(*Ctx, Opts, PP, Plugins,
230+
CheckerRegistrationFns);
231+
232+
Mgr = std::make_unique<AnalysisManager>(*Ctx, PP, PathConsumers,
233+
CreateStoreMgr, CreateConstraintMgr,
234+
checkerMgr.get(), Opts, Injector);
235+
}
236+
227237
/// Store the top level decls in the set to be processed later on.
228238
/// (Doing this pre-processing avoids deserialization of data from PCH.)
229239
bool HandleTopLevelDecl(DeclGroupRef D) override;
@@ -605,14 +615,6 @@ void AnalysisConsumer::HandleTranslationUnit(ASTContext &C) {
605615
if (Diags.hasErrorOccurred() || Diags.hasFatalErrorOccurred())
606616
return;
607617

608-
Ctx = &C;
609-
checkerMgr = std::make_unique<CheckerManager>(*Ctx, Opts, PP, Plugins,
610-
CheckerRegistrationFns);
611-
612-
Mgr = std::make_unique<AnalysisManager>(*Ctx, PP, PathConsumers,
613-
CreateStoreMgr, CreateConstraintMgr,
614-
checkerMgr.get(), Opts, Injector);
615-
616618
// Explicitly destroy the PathDiagnosticConsumer. This will flush its output.
617619
// FIXME: This should be replaced with something that doesn't rely on
618620
// side-effects in PathDiagnosticConsumer's destructor. This is required when

0 commit comments

Comments
 (0)