From: Jordan Rose Date: Mon, 3 Jun 2013 22:59:41 +0000 (+0000) Subject: CFG: In a DeclStmt, skip anything that's not a VarDecl. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2794bc0e3757992194dd587d0f6a253ec72afc9a;p=clang CFG: In a DeclStmt, skip anything that's not a VarDecl. Neither the compiler nor the analyzer are doing anything with non-VarDecl decls in the CFG, and having them there creates extra nodes in the analyzer's path diagnostics. Simplify the CFG (and the path edges) by simply leaving them out. We can always add interesting decls back in when they become relevant. Note that this only affects decls declared in a DeclStmt, and then only those that appear within a function body. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@183157 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Analysis/CFG.cpp b/lib/Analysis/CFG.cpp index 674c01201d..e06e661750 100644 --- a/lib/Analysis/CFG.cpp +++ b/lib/Analysis/CFG.cpp @@ -1639,19 +1639,11 @@ CFGBlock *CFGBuilder::VisitDeclStmt(DeclStmt *DS) { /// DeclStmts and initializers in them. CFGBlock *CFGBuilder::VisitDeclSubExpr(DeclStmt *DS) { assert(DS->isSingleDecl() && "Can handle single declarations only."); - Decl *D = DS->getSingleDecl(); - - if (isa(D)) { - // static_asserts aren't added to the CFG because they do not impact - // runtime semantics. - return Block; - } - VarDecl *VD = dyn_cast(DS->getSingleDecl()); if (!VD) { - autoCreateBlock(); - appendStmt(Block, DS); + // Of everything that can be declared in a DeclStmt, only VarDecls impact + // runtime semantics. return Block; } diff --git a/test/Analysis/cfg.cpp b/test/Analysis/cfg.cpp index 8c1c7653db..0587057d72 100644 --- a/test/Analysis/cfg.cpp +++ b/test/Analysis/cfg.cpp @@ -1,5 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -analyze -analyzer-checker=debug.DumpCFG %s 2>&1 | FileCheck %s -// Check the wrapping behavior when dumping the CFG. +// RUN: %clang_cc1 -analyze -analyzer-checker=debug.DumpCFG -std=c++11 %s 2>&1 | FileCheck %s // CHECK: ENTRY // CHECK-NEXT: Succs (1): B1 @@ -11,7 +10,7 @@ // CHECK-NEXT: Preds (21): B2 B3 B4 B5 B6 B7 B8 B9 // CHECK-NEXT: B10 B11 B12 B13 B14 B15 B16 B17 B18 B19 // CHECK-NEXT: B20 B21 B1 -void test(int i) { +void checkWrap(int i) { switch(i) { case 0: break; case 1: break; @@ -35,3 +34,35 @@ void test(int i) { case 19: break; } } + +// CHECK: ENTRY +// CHECK-NEXT: Succs (1): B1 +// CHECK: [B1] +// CHECK-NEXT: 1: int i; +// CHECK-NEXT: 2: int j; +// CHECK-NEXT: 3: 1 +// CHECK-NEXT: 4: int k = 1; +// CHECK-NEXT: 5: int l; +// CHECK-NEXT: 6: 2 +// CHECK-NEXT: 7: int m = 2; +// CHECK-NEXT: CXXConstructExpr +// CHECK-NEXT: 9: struct standalone myStandalone; +// CHECK-NEXT: CXXConstructExpr +// CHECK-NEXT: 11: struct myAnon; +// CHECK-NEXT: CXXConstructExpr +// CHECK-NEXT: 13: struct named myNamed; +// CHECK-NEXT: Preds (1): B2 +// CHECK-NEXT: Succs (1): B0 +void checkDeclStmts() { + int i, j; + int k = 1, l, m = 2; + + struct standalone { int x, y; }; + struct standalone myStandalone; + + struct { int x, y; } myAnon; + + struct named { int x, y; } myNamed; + + static_assert(1, "abc"); +} diff --git a/test/Analysis/edges-new.mm b/test/Analysis/edges-new.mm index 6784ae13ed..ebbb097dc7 100644 --- a/test/Analysis/edges-new.mm +++ b/test/Analysis/edges-new.mm @@ -1388,40 +1388,6 @@ void variousLoops(id input) { // CHECK-NEXT: // CHECK-NEXT: // CHECK-NEXT: line81 -// CHECK-NEXT: col10 -// CHECK-NEXT: file0 -// CHECK-NEXT: -// CHECK-NEXT: -// CHECK-NEXT: line81 -// CHECK-NEXT: col10 -// CHECK-NEXT: file0 -// CHECK-NEXT: -// CHECK-NEXT: -// CHECK-NEXT: end -// CHECK-NEXT: -// CHECK-NEXT: -// CHECK-NEXT: line81 -// CHECK-NEXT: col24 -// CHECK-NEXT: file0 -// CHECK-NEXT: -// CHECK-NEXT: -// CHECK-NEXT: line81 -// CHECK-NEXT: col24 -// CHECK-NEXT: file0 -// CHECK-NEXT: -// CHECK-NEXT: -// CHECK-NEXT: -// CHECK-NEXT: -// CHECK-NEXT: -// CHECK-NEXT: -// CHECK-NEXT: kindcontrol -// CHECK-NEXT: edges -// CHECK-NEXT: -// CHECK-NEXT: -// CHECK-NEXT: start -// CHECK-NEXT: -// CHECK-NEXT: -// CHECK-NEXT: line81 // CHECK-NEXT: col24 // CHECK-NEXT: file0 // CHECK-NEXT: @@ -9185,40 +9151,6 @@ void variousLoops(id input) { // CHECK-NEXT: path // CHECK-NEXT: // CHECK-NEXT: -// CHECK-NEXT: kindcontrol -// CHECK-NEXT: edges -// CHECK-NEXT: -// CHECK-NEXT: -// CHECK-NEXT: start -// CHECK-NEXT: -// CHECK-NEXT: -// CHECK-NEXT: line407 -// CHECK-NEXT: col3 -// CHECK-NEXT: file0 -// CHECK-NEXT: -// CHECK-NEXT: -// CHECK-NEXT: line407 -// CHECK-NEXT: col8 -// CHECK-NEXT: file0 -// CHECK-NEXT: -// CHECK-NEXT: -// CHECK-NEXT: end -// CHECK-NEXT: -// CHECK-NEXT: -// CHECK-NEXT: line413 -// CHECK-NEXT: col3 -// CHECK-NEXT: file0 -// CHECK-NEXT: -// CHECK-NEXT: -// CHECK-NEXT: line413 -// CHECK-NEXT: col7 -// CHECK-NEXT: file0 -// CHECK-NEXT: -// CHECK-NEXT: -// CHECK-NEXT: -// CHECK-NEXT: -// CHECK-NEXT: -// CHECK-NEXT: // CHECK-NEXT: kindevent // CHECK-NEXT: location // CHECK-NEXT: @@ -9256,12 +9188,12 @@ void variousLoops(id input) { // CHECK-NEXT: // CHECK-NEXT: // CHECK-NEXT: line413 -// CHECK-NEXT: col3 +// CHECK-NEXT: col10 // CHECK-NEXT: file0 // CHECK-NEXT: // CHECK-NEXT: // CHECK-NEXT: line413 -// CHECK-NEXT: col7 +// CHECK-NEXT: col10 // CHECK-NEXT: file0 // CHECK-NEXT: // CHECK-NEXT: diff --git a/test/Analysis/plist-output-alternate.m b/test/Analysis/plist-output-alternate.m index 93d0421d66..ca6d8ce35c 100644 --- a/test/Analysis/plist-output-alternate.m +++ b/test/Analysis/plist-output-alternate.m @@ -925,12 +925,12 @@ void rdar8331641(int x) { // CHECK-NEXT: // CHECK-NEXT: // CHECK-NEXT: line36 -// CHECK-NEXT: col10 +// CHECK-NEXT: col24 // CHECK-NEXT: file0 // CHECK-NEXT: // CHECK-NEXT: // CHECK-NEXT: line36 -// CHECK-NEXT: col10 +// CHECK-NEXT: col24 // CHECK-NEXT: file0 // CHECK-NEXT: // CHECK-NEXT: @@ -946,12 +946,12 @@ void rdar8331641(int x) { // CHECK-NEXT: // CHECK-NEXT: // CHECK-NEXT: line36 -// CHECK-NEXT: col10 +// CHECK-NEXT: col24 // CHECK-NEXT: file0 // CHECK-NEXT: // CHECK-NEXT: // CHECK-NEXT: line36 -// CHECK-NEXT: col10 +// CHECK-NEXT: col24 // CHECK-NEXT: file0 // CHECK-NEXT: // CHECK-NEXT: diff --git a/test/Analysis/plist-output.m b/test/Analysis/plist-output.m index 3dfd6be2e7..293de71a9c 100644 --- a/test/Analysis/plist-output.m +++ b/test/Analysis/plist-output.m @@ -1062,12 +1062,12 @@ int testFoo(Foo *x) { // CHECK-NEXT: // CHECK-NEXT: // CHECK-NEXT: line36 -// CHECK-NEXT: col10 +// CHECK-NEXT: col24 // CHECK-NEXT: file0 // CHECK-NEXT: // CHECK-NEXT: // CHECK-NEXT: line36 -// CHECK-NEXT: col10 +// CHECK-NEXT: col24 // CHECK-NEXT: file0 // CHECK-NEXT: // CHECK-NEXT: @@ -1083,12 +1083,12 @@ int testFoo(Foo *x) { // CHECK-NEXT: // CHECK-NEXT: // CHECK-NEXT: line36 -// CHECK-NEXT: col10 +// CHECK-NEXT: col24 // CHECK-NEXT: file0 // CHECK-NEXT: // CHECK-NEXT: // CHECK-NEXT: line36 -// CHECK-NEXT: col10 +// CHECK-NEXT: col24 // CHECK-NEXT: file0 // CHECK-NEXT: // CHECK-NEXT: