[PATCH] D128068: [analyzer] Do not emit redundant SymbolCasts
Gabor Marton via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 5 09:59:56 PDT 2022
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5d7fa481cf4d: [analyzer] Do not emit redundant SymbolCasts (authored by martong).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D128068/new/
https://reviews.llvm.org/D128068
Files:
clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
clang/test/Analysis/symbolcast-floatingpoint.cpp
Index: clang/test/Analysis/symbolcast-floatingpoint.cpp
===================================================================
--- /dev/null
+++ clang/test/Analysis/symbolcast-floatingpoint.cpp
@@ -0,0 +1,24 @@
+// RUN: %clang_analyze_cc1 -x c++ -analyzer-checker=debug.ExprInspection \
+// RUN: -analyzer-config support-symbolic-integer-casts=false \
+// RUN: -verify %s
+
+// RUN: %clang_analyze_cc1 -x c++ -analyzer-checker=debug.ExprInspection \
+// RUN: -analyzer-config support-symbolic-integer-casts=true \
+// RUN: -verify %s
+
+template <typename T>
+void clang_analyzer_dump(T);
+
+void test_no_redundant_floating_point_cast(int n) {
+
+ double D = n / 30;
+ clang_analyzer_dump(D); // expected-warning{{(double) ((reg_$0<int n>) / 30)}}
+
+ // There are two cast operations evaluated above:
+ // 1. (n / 30) is cast to a double during the store of `D`.
+ // 2. Then in the next line, in RegionStore::getBinding during the load of `D`.
+ //
+ // We should not see in the dump of the SVal any redundant casts like
+ // (double) ((double) $n / 30)
+
+}
Index: clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
===================================================================
--- clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SValBuilder.cpp
@@ -113,6 +113,8 @@
QualType fromTy, QualType toTy) {
assert(operand);
assert(!Loc::isLocType(toTy));
+ if (fromTy == toTy)
+ return operand;
return nonloc::SymbolVal(SymMgr.getCastSymbol(operand, fromTy, toTy));
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D128068.442341.patch
Type: text/x-patch
Size: 1573 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220705/1f75edbb/attachment.bin>
More information about the cfe-commits
mailing list