Thread-safety analysis: Fix warning when EXCLUSIVE_LOCKS_REQUIRED
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
diff --git a/lib/Analysis/ThreadSafety.cpp b/lib/Analysis/ThreadSafety.cpp
index e7d9a2d..036d0b8 100644
--- a/lib/Analysis/ThreadSafety.cpp
+++ b/lib/Analysis/ThreadSafety.cpp
@@ -2374,6 +2374,20 @@
}
}
+
+ // 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()];
diff --git a/test/SemaCXX/warn-thread-safety-analysis.cpp b/test/SemaCXX/warn-thread-safety-analysis.cpp
index 4e8893d..0d6aa4c 100644
--- a/test/SemaCXX/warn-thread-safety-analysis.cpp
+++ b/test/SemaCXX/warn-thread-safety-analysis.cpp
@@ -3419,3 +3419,37 @@
}
}; // 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