[PATCH] D63642: [analyzer] Add a debug analyzer config to place an event for each tracked condition

2019-07-05 Thread Kristóf Umann via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb55745606fa6: [analyzer] Add a debug analyzer config to 
place an event for each tracked… (authored by Szelethus).

Changed prior to commit:
  https://reviews.llvm.org/D63642?vs=205966=208171#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D63642/new/

https://reviews.llvm.org/D63642

Files:
  clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
  clang/test/Analysis/analyzer-config.c
  clang/test/Analysis/track-control-dependency-conditions.cpp

Index: clang/test/Analysis/track-control-dependency-conditions.cpp
===
--- clang/test/Analysis/track-control-dependency-conditions.cpp
+++ clang/test/Analysis/track-control-dependency-conditions.cpp
@@ -3,7 +3,23 @@
 // RUN:   -analyzer-config track-conditions=true \
 // RUN:   -analyzer-output=text \
 // RUN:   -analyzer-checker=core
+
+// RUN: not %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config track-conditions-debug=true \
+// RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-INVALID-DEBUG
+
+// CHECK-INVALID-DEBUG: (frontend): invalid input for analyzer-config option
+// CHECK-INVALID-DEBUG-SAME:'track-conditions-debug', that expects
+// CHECK-INVALID-DEBUG-SAME:'track-conditions' to also be enabled
 //
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -verify=expected,tracking,debug \
+// RUN:   -analyzer-config track-conditions=true \
+// RUN:   -analyzer-config track-conditions-debug=true \
+// RUN:   -analyzer-output=text \
+// RUN:   -analyzer-checker=core
+
 // RUN: %clang_analyze_cc1 %s -verify \
 // RUN:   -analyzer-output=text \
 // RUN:   -analyzer-checker=core
@@ -30,6 +46,8 @@
 
   if (flag) // expected-note   {{Assuming 'flag' is not equal to 0}}
 // expected-note@-1{{Taking true branch}}
+// debug-note@-2{{Tracking condition 'flag'}}
+
 *x = 5; // expected-warning{{Dereference of null pointer}}
 // expected-note@-1{{Dereference of null pointer}}
 }
@@ -59,6 +77,8 @@
 
   if (flag) // expected-note   {{Assuming 'flag' is not equal to 0}}
 // expected-note@-1{{Taking true branch}}
+// debug-note@-2{{Tracking condition 'flag'}}
+
 *x = 5; // expected-warning{{Dereference of null pointer}}
 // expected-note@-1{{Dereference of null pointer}}
 }
@@ -85,8 +105,11 @@
 
   if (bar) // expected-note   {{Assuming 'bar' is not equal to 0}}
// expected-note@-1{{Taking true branch}}
+   // debug-note@-2{{Tracking condition 'bar'}}
 if (flag) // expected-note   {{Assuming 'flag' is not equal to 0}}
   // expected-note@-1{{Taking true branch}}
+  // debug-note@-2{{Tracking condition 'flag'}}
+
   *x = 5; // expected-warning{{Dereference of null pointer}}
   // expected-note@-1{{Dereference of null pointer}}
 }
@@ -107,7 +130,7 @@
   if (int flag = foo()) // tracking-note{{Calling 'foo'}}
 // tracking-note@-1{{Returning from 'foo'}}
 // tracking-note@-2{{'flag' initialized here}}
-
+// debug-note@-3{{Tracking condition 'flag'}}
 // expected-note@-4{{Assuming 'flag' is not equal to 0}}
 // expected-note@-5{{Taking true branch}}
 
@@ -129,7 +152,7 @@
   if (ConvertsToBool())
 // tracking-note@-1 {{Calling 'ConvertsToBool::operator bool'}}
 // tracking-note@-2{{Returning from 'ConvertsToBool::operator bool'}}
-
+// debug-note@-3{{Tracking condition 'ConvertsToBool()'}}
 // expected-note@-4{{Assuming the condition is true}}
 // expected-note@-5{{Taking true branch}}
 *x = 5; // expected-warning{{Dereference of null pointer}}
@@ -150,8 +173,9 @@
   if (!flipCoin())
 // tracking-note@-1{{Calling 'flipCoin'}}
 // tracking-note@-2{{Returning from 'flipCoin'}}
-// expected-note@-3{{Assuming the condition is true}}
-// expected-note@-4{{Taking true branch}}
+// debug-note@-3{{Tracking condition '!flipCoin()'}}
+// expected-note@-4{{Assuming the condition is true}}
+// expected-note@-5{{Taking true branch}}
 *ptr = 5; // expected-warning{{Dereference of null pointer}}
   // expected-note@-1{{Dereference of null pointer}}
 }
@@ -163,6 +187,7 @@
 bool flipCoin() {
   if (coin()) // tracking-note{{Assuming the condition is false}}
   // tracking-note@-1{{Taking false branch}}
+  // debug-note@-2{{Tracking condition 'coin()'}}
 return true;
   return coin(); // tracking-note{{Returning value}}
 }
@@ -174,8 +199,9 @@
   if (!flipCoin())
 // tracking-note@-1{{Calling 'flipCoin'}}
 // tracking-note@-2{{Returning from 'flipCoin'}}
-// 

[PATCH] D63642: [analyzer] Add a debug analyzer config to place an event for each tracked condition

2019-06-21 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ accepted this revision.
NoQ added a comment.
This revision is now accepted and ready to land.

Aha, yep, nice debug flag!




Comment at: clang/test/Analysis/track-control-dependency-conditions.cpp:16
+// RUN: %clang_analyze_cc1 %s -verify \
+// RUN:   -DTRACKING_CONDITIONS -DTRACKING_CONDITIONS_DEBUG \
+// RUN:   -analyzer-config track-conditions=true \

Pls consider `-verify=` here as well.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D63642/new/

https://reviews.llvm.org/D63642



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D63642: [analyzer] Add a debug analyzer config to place an event for each tracked condition

2019-06-21 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus created this revision.
Szelethus added reviewers: NoQ, baloghadamsoftware, xazax.hun, Charusso, 
rnkovacs, dcoughlin.
Szelethus added a project: clang.
Herald added subscribers: cfe-commits, gamesh411, dkrupp, donat.nagy, 
mikhail.ramalho, a.sidorin, szepet, whisperity.

Exactly what it says on the tin!

I expect this to be especially valuable on production code where control 
dependencies aren't obvious.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D63642

Files:
  clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
  clang/test/Analysis/analyzer-config.c
  clang/test/Analysis/track-control-dependency-conditions.cpp

Index: clang/test/Analysis/track-control-dependency-conditions.cpp
===
--- clang/test/Analysis/track-control-dependency-conditions.cpp
+++ clang/test/Analysis/track-control-dependency-conditions.cpp
@@ -2,7 +2,23 @@
 // RUN:   -analyzer-config track-conditions=true \
 // RUN:   -analyzer-output=text \
 // RUN:   -analyzer-checker=core
+
+// RUN: not %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config track-conditions-debug=true \
+// RUN:   2>&1 | FileCheck %s -check-prefix=CHECK-INVALID-DEBUG
+
+// CHECK-INVALID-DEBUG: (frontend): invalid input for analyzer-config option
+// CHECK-INVALID-DEBUG-SAME:'track-conditions-debug', that expects
+// CHECK-INVALID-DEBUG-SAME:'track-conditions' to also be enabled
 //
+// RUN: %clang_analyze_cc1 %s -verify \
+// RUN:   -DTRACKING_CONDITIONS -DTRACKING_CONDITIONS_DEBUG \
+// RUN:   -analyzer-config track-conditions=true \
+// RUN:   -analyzer-config track-conditions-debug=true \
+// RUN:   -analyzer-output=text \
+// RUN:   -analyzer-checker=core
+
 // RUN: %clang_analyze_cc1 %s -verify \
 // RUN:   -analyzer-output=text \
 // RUN:   -analyzer-checker=core
@@ -35,6 +51,9 @@
 
   if (flag) // expected-note   {{Assuming 'flag' is not equal to 0}}
 // expected-note@-1{{Taking true branch}}
+#ifdef TRACKING_CONDITIONS_DEBUG
+// expected-note@-3{{Tracking condition 'flag'}}
+#endif // TRACKING_CONDITIONS_DEBUG
 *x = 5; // expected-warning{{Dereference of null pointer}}
 // expected-note@-1{{Dereference of null pointer}}
 }
@@ -70,6 +89,9 @@
 
   if (flag) // expected-note   {{Assuming 'flag' is not equal to 0}}
 // expected-note@-1{{Taking true branch}}
+#ifdef TRACKING_CONDITIONS_DEBUG
+// expected-note@-3{{Tracking condition 'flag'}}
+#endif // TRACKING_CONDITIONS_DEBUG
 *x = 5; // expected-warning{{Dereference of null pointer}}
 // expected-note@-1{{Dereference of null pointer}}
 }
@@ -102,8 +124,14 @@
 
   if (bar) // expected-note   {{Assuming 'bar' is not equal to 0}}
// expected-note@-1{{Taking true branch}}
+#ifdef TRACKING_CONDITIONS_DEBUG
+   // expected-note@-3{{Tracking condition 'bar'}}
+#endif // TRACKING_CONDITIONS_DEBUG
 if (flag) // expected-note   {{Assuming 'flag' is not equal to 0}}
   // expected-note@-1{{Taking true branch}}
+#ifdef TRACKING_CONDITIONS_DEBUG
+  // expected-note@-3{{Tracking condition 'flag'}}
+#endif // TRACKING_CONDITIONS_DEBUG
   *x = 5; // expected-warning{{Dereference of null pointer}}
   // expected-note@-1{{Dereference of null pointer}}
 }
@@ -129,9 +157,13 @@
 // expected-note@-2{{Calling 'foo'}}
 // expected-note@-3{{Returning from 'foo'}}
 // expected-note@-4{{'flag' initialized here}}
+#ifdef TRACKING_CONDITIONS_DEBUG
+// expected-note@-6{{Tracking condition 'flag'}}
+#endif // TRACKING_CONDITIONS_DEBUG
 #endif // TRACKING_CONDITIONS
-// expected-note@-6{{Assuming 'flag' is not equal to 0}}
-// expected-note@-7{{Taking true branch}}
+// expected-note@-9{{Assuming 'flag' is not equal to 0}}
+// expected-note@-10{{Taking true branch}}
+
 *x = 5; // expected-warning{{Dereference of null pointer}}
 // expected-note@-1{{Dereference of null pointer}}
 }
@@ -154,9 +186,12 @@
 #ifdef TRACKING_CONDITIONS
 // expected-note@-2 {{Calling 'ConvertsToBool::operator bool'}}
 // expected-note@-3{{Returning from 'ConvertsToBool::operator bool'}}
+#ifdef TRACKING_CONDITIONS_DEBUG
+// expected-note@-5{{Tracking condition 'ConvertsToBool()'}}
+#endif // TRACKING_CONDITIONS_DEBUG
 #endif // TRACKING_CONDITIONS
-// expected-note@-5{{Assuming the condition is true}}
-// expected-note@-6{{Taking true branch}}
+// expected-note@-8{{Assuming the condition is true}}
+// expected-note@-9{{Taking true branch}}
 *x = 5; // expected-warning{{Dereference of null pointer}}
 // expected-note@-1{{Dereference of null pointer}}
 }
@@ -174,6 +209,9 @@
   int *x = 0; // expected-note{{'x' initialized to a null pointer value}}
   if (flag) //