[PATCH] D125532: [analyzer] Introduce clang_analyzer_dumpSvalType introspection function
Balázs Benics via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri May 13 03:39:30 PDT 2022
steakhal created this revision.
steakhal added a reviewer: martong.
Herald added subscribers: manas, ASDenysPetrov, dkrupp, donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, rnkovacs, szepet, baloghadamsoftware, xazax.hun.
Herald added a reviewer: Szelethus.
Herald added a project: All.
steakhal requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
In some rare cases the type of an SVal might be interesting.
This introspection function exposes this information in tests.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D125532
Files:
clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
clang/test/Analysis/expr-inspection.c
Index: clang/test/Analysis/expr-inspection.c
===================================================================
--- clang/test/Analysis/expr-inspection.c
+++ clang/test/Analysis/expr-inspection.c
@@ -6,12 +6,16 @@
void clang_analyzer_dump(int x);
void clang_analyzer_dump_pointer(int *p);
+void clang_analyzer_dumpSvalType(int x);
+void clang_analyzer_dumpSvalType_pointer(int *p);
void clang_analyzer_printState(void);
void clang_analyzer_numTimesReached(void);
void foo(int x) {
clang_analyzer_dump(x); // expected-warning{{reg_$0<int x>}}
clang_analyzer_dump(x + (-1)); // expected-warning{{(reg_$0<int x>) - 1}}
+ clang_analyzer_dumpSvalType(x); // expected-warning {{int}}
+
int y = 1;
for (; y < 3; ++y) {
clang_analyzer_numTimesReached(); // expected-warning{{2}}
@@ -53,4 +57,5 @@
void test_field_dumps(struct S s, struct S *p) {
clang_analyzer_dump_pointer(&s.x); // expected-warning{{&s.x}}
clang_analyzer_dump_pointer(&p->x); // expected-warning{{&SymRegion{reg_$1<struct S * p>}.x}}
+ clang_analyzer_dumpSvalType_pointer(&s.x); // expected-warning {{int *}}
}
Index: clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
===================================================================
--- clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
@@ -40,6 +40,7 @@
void analyzerNumTimesReached(const CallExpr *CE, CheckerContext &C) const;
void analyzerCrash(const CallExpr *CE, CheckerContext &C) const;
void analyzerWarnOnDeadSymbol(const CallExpr *CE, CheckerContext &C) const;
+ void analyzerDumpSValType(const CallExpr *CE, CheckerContext &C) const;
void analyzerDump(const CallExpr *CE, CheckerContext &C) const;
void analyzerExplain(const CallExpr *CE, CheckerContext &C) const;
void analyzerPrintState(const CallExpr *CE, CheckerContext &C) const;
@@ -98,6 +99,8 @@
&ExprInspectionChecker::analyzerDumpExtent)
.Case("clang_analyzer_dumpElementCount",
&ExprInspectionChecker::analyzerDumpElementCount)
+ .StartsWith("clang_analyzer_dumpSvalType",
+ &ExprInspectionChecker::analyzerDumpSValType)
.StartsWith("clang_analyzer_dump",
&ExprInspectionChecker::analyzerDump)
.Case("clang_analyzer_getExtent",
@@ -255,6 +258,16 @@
reportBug(Ex.Visit(V), C);
}
+void ExprInspectionChecker::analyzerDumpSValType(const CallExpr *CE,
+ CheckerContext &C) const {
+ const Expr *Arg = getArgExpr(CE, C);
+ if (!Arg)
+ return;
+
+ QualType Ty = C.getSVal(Arg).getType(C.getASTContext());
+ reportBug(Ty.getAsString(), C);
+}
+
void ExprInspectionChecker::analyzerDump(const CallExpr *CE,
CheckerContext &C) const {
const Expr *Arg = getArgExpr(CE, C);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D125532.429186.patch
Type: text/x-patch
Size: 2915 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220513/7cc7fc7b/attachment.bin>
More information about the cfe-commits
mailing list