]> granicus.if.org Git - clang/commitdiff
[analyzer] Skip checking blocks in dependent contexts.
authorDevin Coughlin <dcoughlin@apple.com>
Wed, 18 Nov 2015 22:46:52 +0000 (22:46 +0000)
committerDevin Coughlin <dcoughlin@apple.com>
Wed, 18 Nov 2015 22:46:52 +0000 (22:46 +0000)
Since we don't check functions in dependent contexts, we should skip blocks
in those contexts as well. This avoids an assertion failure when the
DeadStoresChecker attempts to evaluate an array subscript expression with
a dependent name type.

rdar://problem/23564220

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@253516 91177308-0d34-0410-b5e6-96231b3b80d8

lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
test/Analysis/dead-stores.cpp

index ca92ffe8f01d6c4ee7e9d057b7513c15b7840393..bbcd23c8a25a2bbea941d175beb6f824d607571c 100644 (file)
@@ -368,7 +368,11 @@ public:
   bool VisitBlockDecl(BlockDecl *BD) {
     if (BD->hasBody()) {
       assert(RecVisitorMode == AM_Syntax || Mgr->shouldInlineCall() == false);
-      HandleCode(BD, RecVisitorMode);
+      // Since we skip function template definitions, we should skip blocks
+      // declared in those functions as well.
+      if (!BD->isDependentContext()) {
+        HandleCode(BD, RecVisitorMode);
+      }
     }
     return true;
   }
index 2027ee6be1f8726bf954598fc74f2184ebb600f1..78cba161065f1671735bb7fb26e5da4b7e0249ff 100644 (file)
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -std=c++11 -analyze -analyzer-checker=deadcode.DeadStores -verify -Wno-unreachable-code %s
-// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -std=c++11 -analyze -analyzer-store=region -analyzer-constraints=range -analyzer-checker=deadcode.DeadStores -verify -Wno-unreachable-code %s
+// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fblocks -std=c++11 -analyze -analyzer-checker=deadcode.DeadStores -verify -Wno-unreachable-code %s
+// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fblocks -std=c++11 -analyze -analyzer-store=region -analyzer-constraints=range -analyzer-checker=deadcode.DeadStores -verify -Wno-unreachable-code %s
 
 //===----------------------------------------------------------------------===//
 // Basic dead store checking (but in C++ mode).
@@ -174,6 +174,20 @@ int radar_13213575() {
   return radar13213575_testit<true>(5) + radar13213575_testit<false>(3);
 }
 
+template <class T>
+void test_block_in_dependent_context(typename T::some_t someArray) {
+  ^{
+     int i = someArray[0]; // no-warning
+  }();
+}
+
+void test_block_in_non_dependent_context(int *someArray) {
+  ^{
+     int i = someArray[0]; // expected-warning {{Value stored to 'i' during its initialization is never read}}
+  }();
+}
+
+
 //===----------------------------------------------------------------------===//
 // Dead store checking involving lambdas.
 //===----------------------------------------------------------------------===//