[PATCH] D130974: [analyzer] Fix for the crash in #56873
Domján Dániel via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 3 10:25:36 PDT 2022
This revision was automatically updated to reflect the committed changes.
Closed by commit rG10a7ee0bac21: [analyzer] Fix for the crash in #56873 (authored by isuckatcs).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D130974/new/
https://reviews.llvm.org/D130974
Files:
clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
clang/test/Analysis/Issue56873.cpp
Index: clang/test/Analysis/Issue56873.cpp
===================================================================
--- /dev/null
+++ clang/test/Analysis/Issue56873.cpp
@@ -0,0 +1,24 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify %s
+
+void clang_analyzer_warnIfReached();
+
+struct S {
+};
+
+void Issue56873_1() {
+ int n;
+
+ // This line used to crash
+ S *arr = new S[n];
+
+ clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+}
+
+void Issue56873_2() {
+ int n;
+
+ // This line used to crash
+ int *arr = new int[n];
+
+ clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+}
Index: clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
===================================================================
--- clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
@@ -762,6 +762,11 @@
svalBuilder.evalBinOp(State, BO_Mul, ElementCount, ElementSize,
svalBuilder.getArrayIndexType());
+ // FIXME: This line is to prevent a crash. For more details please check
+ // issue #56264.
+ if (Size.isUndef())
+ Size = UnknownVal();
+
State = setDynamicExtent(State, MR, Size.castAs<DefinedOrUnknownSVal>(),
svalBuilder);
} else {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D130974.449702.patch
Type: text/x-patch
Size: 1400 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220803/d925e0c2/attachment.bin>
More information about the cfe-commits
mailing list