Skip to content

Commit ec96c0c

Browse files
authored
[analyzer] Fix tagging of PostAllocatorCall (#142132)
By design the `Location` data member of a `CheckerContext` is always a `ProgramPoint` which is tagged with the currently active checker (note that all checker classes are subclasses of `ProgramPointTag`). This ensures that exploded nodes created by the checker are by default tagged by the checker object unless the checker specifies some other tag (e.g. a note tag) when it calls the `addTransition`-like method that creates the node. This was followed by all the `CheckerManager::runCheckersForXXX` methods, except for `runCheckerForNewAllocator`, where the implementation constructed the `PostAllocatorCall` program point which was used to create the `CheckerContext` without passing `checkFn.Checker` as the tag of the program point. This commit elimintates this inconsistency and adds an assertion to the constructor of `CheckerContext` to ensure that this invariant will be upheld even if we e.g. add a new program point kind. I strongly suspect that this is a non-functional change because program point tags are a vestigial feature in the codebase that barely affect anything -- but e.g. their presence affects the infamous node reclamation process, so I'm not marking this as NFC.
1 parent 3ddc1e1 commit ec96c0c

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ class CheckerContext {
5151
wasInlined(wasInlined) {
5252
assert(Pred->getState() &&
5353
"We should not call the checkers on an empty state.");
54+
assert(loc.getTag() && "The ProgramPoint associated with CheckerContext "
55+
"must be tagged with the active checker.");
5456
}
5557

5658
AnalysisManager &getAnalysisManager() {

clang/lib/StaticAnalyzer/Core/CheckerManager.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -585,8 +585,8 @@ namespace {
585585
NodeBuilder &Bldr, ExplodedNode *Pred) {
586586
llvm::TimeTraceScope TimeScope(
587587
checkerScopeName("Allocator", checkFn.Checker));
588-
ProgramPoint L =
589-
PostAllocatorCall(Call.getOriginExpr(), Pred->getLocationContext());
588+
ProgramPoint L = PostAllocatorCall(
589+
Call.getOriginExpr(), Pred->getLocationContext(), checkFn.Checker);
590590
CheckerContext C(Bldr, Eng, Pred, L, WasInlined);
591591
checkFn(cast<CXXAllocatorCall>(*Call.cloneWithState(Pred->getState())),
592592
C);

0 commit comments

Comments
 (0)