From 15e9d0493a9f62d0a6b68178627dda057d14bbd1 Mon Sep 17 00:00:00 2001 From: Artem Dergachev Date: Fri, 18 Oct 2019 20:15:39 +0000 Subject: [PATCH] [analyzer] Fix FieldRegion dumps. The '->' thing has always been confusing; the actual operation '->' translates to a pointer dereference together with adding a FieldRegion, but FieldRegion on its own doesn't imply an additional pointer dereference. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@375281 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/StaticAnalyzer/Core/MemRegion.cpp | 2 +- test/Analysis/dump_egraph.cpp | 2 +- .../initializers_under_construction.cpp | 2 +- test/Analysis/expr-inspection.c | 11 ++++++++++- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/StaticAnalyzer/Core/MemRegion.cpp b/lib/StaticAnalyzer/Core/MemRegion.cpp index c7b280adcd..a10d7e69ad 100644 --- a/lib/StaticAnalyzer/Core/MemRegion.cpp +++ b/lib/StaticAnalyzer/Core/MemRegion.cpp @@ -506,7 +506,7 @@ void ElementRegion::dumpToStream(raw_ostream &os) const { } void FieldRegion::dumpToStream(raw_ostream &os) const { - os << superRegion << "->" << *getDecl(); + os << superRegion << "." << *getDecl(); } void ObjCIvarRegion::dumpToStream(raw_ostream &os) const { diff --git a/test/Analysis/dump_egraph.cpp b/test/Analysis/dump_egraph.cpp index a56f061949..9b87d1a90f 100644 --- a/test/Analysis/dump_egraph.cpp +++ b/test/Analysis/dump_egraph.cpp @@ -20,7 +20,7 @@ void foo() { // CHECK: \"location_context\": \"#0 Call\", \"calling\": \"foo\", \"location\": null, \"items\": [\l        \{ \"stmt_id\": {{[0-9]+}}, \"kind\": \"construct into local variable\", \"argument_index\": null, \"pretty\": \"T t;\", \"value\": \"&t\" -// CHECK: \"location_context\": \"#0 Call\", \"calling\": \"T::T\", \"location\": \{ \"line\": 16, \"column\": 5, \"file\": \"{{.*}}dump_egraph.cpp\" \}, \"items\": [\l        \{ \"init_id\": {{[0-9]+}}, \"kind\": \"construct into member variable\", \"argument_index\": null, \"pretty\": \"s\", \"value\": \"&t-\>s\" +// CHECK: \"location_context\": \"#0 Call\", \"calling\": \"T::T\", \"location\": \{ \"line\": 16, \"column\": 5, \"file\": \"{{.*}}dump_egraph.cpp\" \}, \"items\": [\l        \{ \"init_id\": {{[0-9]+}}, \"kind\": \"construct into member variable\", \"argument_index\": null, \"pretty\": \"s\", \"value\": \"&t.s\" // CHECK: \"cluster\": \"t\", \"pointer\": \"{{0x[0-9a-f]+}}\", \"items\": [\l        \{ \"kind\": \"Default\", \"offset\": 0, \"value\": \"conj_$2\{int, LC5, no stmt, #1\}\" diff --git a/test/Analysis/exploded-graph-rewriter/initializers_under_construction.cpp b/test/Analysis/exploded-graph-rewriter/initializers_under_construction.cpp index 472627ef61..96df69f857 100644 --- a/test/Analysis/exploded-graph-rewriter/initializers_under_construction.cpp +++ b/test/Analysis/exploded-graph-rewriter/initializers_under_construction.cpp @@ -20,6 +20,6 @@ struct B { void test() { // CHECK: (construct into member variable) // CHECK-SAME: a - // CHECK-SAME: &b->a + // CHECK-SAME: &b.a B b; } diff --git a/test/Analysis/expr-inspection.c b/test/Analysis/expr-inspection.c index 6d9ea4bb26..7c5d9e5c49 100644 --- a/test/Analysis/expr-inspection.c +++ b/test/Analysis/expr-inspection.c @@ -5,6 +5,7 @@ // Self-tests for the debug.ExprInspection checker. void clang_analyzer_dump(int x); +void clang_analyzer_dump_pointer(int *p); void clang_analyzer_printState(); void clang_analyzer_numTimesReached(); @@ -30,7 +31,7 @@ void foo(int x) { // CHECK-NEXT: ]} // CHECK-NEXT: ]}, // CHECK-NEXT: "environment": { "pointer": "{{0x[0-9a-f]+}}", "items": [ -// CHECK-NEXT: { "lctx_id": 1, "location_context": "#0 Call", "calling": "foo", "location": null, "items": [ +// CHECK-NEXT: { "lctx_id": {{[0-9]+}}, "location_context": "#0 Call", "calling": "foo", "location": null, "items": [ // CHECK-NEXT: { "stmt_id": {{[0-9]+}}, "pretty": "clang_analyzer_printState", "value": "&code{clang_analyzer_printState}" } // CHECK-NEXT: ]} // CHECK-NEXT: ]}, @@ -43,3 +44,11 @@ void foo(int x) { // CHECK-NEXT: "checker_messages": null // CHECK-NEXT: } +struct S { + int x, y; +}; + +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_$0}.x}} +} -- 2.40.0