]> granicus.if.org Git - clang/commitdiff
Thread-safety analysis: Fix warning when EXCLUSIVE_LOCKS_REQUIRED
authorDeLesley Hutchins <delesley@google.com>
Wed, 19 Sep 2012 19:49:40 +0000 (19:49 +0000)
committerDeLesley Hutchins <delesley@google.com>
Wed, 19 Sep 2012 19:49:40 +0000 (19:49 +0000)
is placed on a function that has no path to the exit block.

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

lib/Analysis/ThreadSafety.cpp
test/SemaCXX/warn-thread-safety-analysis.cpp

index e7d9a2d642c9157b1ba0af9601fe75671d8a09b7..036d0b8888ae776441be1f4d53aa023a473816e6 100644 (file)
@@ -2374,6 +2374,20 @@ void ThreadSafetyAnalyzer::runAnalysis(AnalysisDeclContext &AC) {
     }
   }
 
+
+  // Check to make sure that the exit block is reachable
+  bool ExitUnreachable = true;
+  for (CFGBlock::const_pred_iterator PI = CFGraph->getExit().pred_begin(),
+       PE  = CFGraph->getExit().pred_end(); PI != PE; ++PI) {
+    if (!(*PI)->hasNoReturnElement()) {
+      ExitUnreachable = false;
+      break;
+    }
+  }
+  // Skip the final check if the exit block is unreachable.
+  if (ExitUnreachable)
+    return;
+
   CFGBlockInfo *Initial = &BlockInfo[CFGraph->getEntry().getBlockID()];
   CFGBlockInfo *Final   = &BlockInfo[CFGraph->getExit().getBlockID()];
 
index 4e8893d3ca64de75d767cf1d41753cbb791c9ca3..0d6aa4c79b2dc606da9228f232709486d6040306 100644 (file)
@@ -3419,3 +3419,37 @@ void test2() {
 }
 
 };  // end namespace ComplexNameTest
+
+
+namespace UnreachableExitTest {
+
+class FemmeFatale {
+public:
+  FemmeFatale();
+  ~FemmeFatale() __attribute__((noreturn));
+};
+
+void exitNow() __attribute__((noreturn));
+
+Mutex fatalmu_;
+
+void test1() EXCLUSIVE_LOCKS_REQUIRED(fatalmu_) {
+  exitNow();
+}
+
+void test2() EXCLUSIVE_LOCKS_REQUIRED(fatalmu_) {
+  FemmeFatale femme;
+}
+
+bool c;
+
+void test3() EXCLUSIVE_LOCKS_REQUIRED(fatalmu_) {
+  if (c) {
+    exitNow();
+  }
+  else {
+    FemmeFatale femme;
+  }
+}
+
+}   // end namespace UnreachableExitTest