Skip to content

Commit 8818728

Browse files
[analyzer] Add previous CFG block to BlockEntrance ProgramPoints (#140861)
This helps to gain contextual information about how we entered a CFG block. The `noexprcrash.c` test probably changed due to the fact that now BlockEntrance ProgramPoint Profile also hashes the pointer of the previous CFG block. I didn't investigate. CPP-6483
1 parent bb27916 commit 8818728

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

clang/include/clang/Analysis/ProgramPoint.h

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,14 @@ class ProgramPoint {
224224

225225
class BlockEntrance : public ProgramPoint {
226226
public:
227-
BlockEntrance(const CFGBlock *B, const LocationContext *L,
228-
const ProgramPointTag *tag = nullptr)
229-
: ProgramPoint(B, BlockEntranceKind, L, tag) {
230-
assert(B && "BlockEntrance requires non-null block");
227+
BlockEntrance(const CFGBlock *PrevBlock, const CFGBlock *CurrBlock,
228+
const LocationContext *L, const ProgramPointTag *Tag = nullptr)
229+
: ProgramPoint(CurrBlock, PrevBlock, BlockEntranceKind, L, Tag) {
230+
assert(CurrBlock && "BlockEntrance requires non-null block");
231+
}
232+
233+
const CFGBlock *getPreviousBlock() const {
234+
return reinterpret_cast<const CFGBlock *>(getData2());
231235
}
232236

233237
const CFGBlock *getBlock() const {
@@ -760,13 +764,15 @@ template <> struct DenseMapInfo<clang::ProgramPoint> {
760764
static inline clang::ProgramPoint getEmptyKey() {
761765
uintptr_t x =
762766
reinterpret_cast<uintptr_t>(DenseMapInfo<void*>::getEmptyKey()) & ~0x7;
763-
return clang::BlockEntrance(reinterpret_cast<clang::CFGBlock*>(x), nullptr);
767+
return clang::BlockEntrance(nullptr, reinterpret_cast<clang::CFGBlock *>(x),
768+
nullptr);
764769
}
765770

766771
static inline clang::ProgramPoint getTombstoneKey() {
767772
uintptr_t x =
768773
reinterpret_cast<uintptr_t>(DenseMapInfo<void*>::getTombstoneKey()) & ~0x7;
769-
return clang::BlockEntrance(reinterpret_cast<clang::CFGBlock*>(x), nullptr);
774+
return clang::BlockEntrance(nullptr, reinterpret_cast<clang::CFGBlock *>(x),
775+
nullptr);
770776
}
771777

772778
static unsigned getHashValue(const clang::ProgramPoint &Loc) {

clang/lib/StaticAnalyzer/Core/CoreEngine.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ void CoreEngine::HandleBlockEdge(const BlockEdge &L, ExplodedNode *Pred) {
315315

316316
// Call into the ExprEngine to process entering the CFGBlock.
317317
ExplodedNodeSet dstNodes;
318-
BlockEntrance BE(Blk, Pred->getLocationContext());
318+
BlockEntrance BE(L.getSrc(), L.getDst(), Pred->getLocationContext());
319319
NodeBuilderWithSinks nodeBuilder(Pred, dstNodes, BuilderCtx, BE);
320320
ExprEng.processCFGBlockEntrance(L, nodeBuilder, Pred);
321321

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1-
// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify -analyzer-config exploration_strategy=unexplored_first %s
2-
// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify -analyzer-config exploration_strategy=dfs %s
1+
// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify=common,ufirst -analyzer-config exploration_strategy=unexplored_first %s
2+
// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify=common,dfs -analyzer-config exploration_strategy=dfs %s
33

44
extern void clang_analyzer_eval(int);
55

66
typedef struct { char a; } b;
77
int c(b* input) {
8-
int x = (input->a ?: input) ? 1 : 0; // expected-warning{{pointer/integer type mismatch}}
8+
int x = (input->a ?: input) ? 1 : 0; // common-warning{{pointer/integer type mismatch}}
99
if (input->a) {
1010
// FIXME: The value should actually be "TRUE",
1111
// but is incorrect due to a bug.
12-
clang_analyzer_eval(x); // expected-warning{{FALSE}}
12+
// dfs-warning@+1 {{FALSE}} ufirst-warning@+1 {{TRUE}}
13+
clang_analyzer_eval(x);
1314
} else {
14-
clang_analyzer_eval(x); // expected-warning{{TRUE}}
15+
clang_analyzer_eval(x); // common-warning{{TRUE}}
1516
}
1617
return x;
1718
}

0 commit comments

Comments
 (0)