Skip to content

Commit 10a7ee0

Browse files
committed
[analyzer] Fix for the crash in #56873
In ExprEngine::bindReturnValue() we cast an SVal to DefinedOrUnknownSVal, however this SVal can also be Undefined, which leads to an assertion failure. Fixes: #56873 Differential Revision: https://reviews.llvm.org/D130974
1 parent 3426fc7 commit 10a7ee0

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,11 @@ ProgramStateRef ExprEngine::bindReturnValue(const CallEvent &Call,
762762
svalBuilder.evalBinOp(State, BO_Mul, ElementCount, ElementSize,
763763
svalBuilder.getArrayIndexType());
764764

765+
// FIXME: This line is to prevent a crash. For more details please check
766+
// issue #56264.
767+
if (Size.isUndef())
768+
Size = UnknownVal();
769+
765770
State = setDynamicExtent(State, MR, Size.castAs<DefinedOrUnknownSVal>(),
766771
svalBuilder);
767772
} else {

clang/test/Analysis/Issue56873.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify %s
2+
3+
void clang_analyzer_warnIfReached();
4+
5+
struct S {
6+
};
7+
8+
void Issue56873_1() {
9+
int n;
10+
11+
// This line used to crash
12+
S *arr = new S[n];
13+
14+
clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
15+
}
16+
17+
void Issue56873_2() {
18+
int n;
19+
20+
// This line used to crash
21+
int *arr = new int[n];
22+
23+
clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
24+
}

0 commit comments

Comments
 (0)