diff options
| author | Ted Kremenek <kremenek@apple.com> | 2011-11-30 21:22:09 +0000 |
|---|---|---|
| committer | Ted Kremenek <kremenek@apple.com> | 2011-11-30 21:22:09 +0000 |
| commit | 7f770032c74b0351eab08b6d7481ec5191b3a1e3 (patch) | |
| tree | 39be853960cf876393b77e739a2e325b1fe3cf8a /clang | |
| parent | a0c69014f876f2839401e336e2b5fb0a46bd826d (diff) | |
| download | bcm5719-llvm-7f770032c74b0351eab08b6d7481ec5191b3a1e3.tar.gz bcm5719-llvm-7f770032c74b0351eab08b6d7481ec5191b3a1e3.zip | |
Don't run -Wunreachable-code on template instantiations. Different instantiations may produce different unreachable code results, and it is very difficult for us to prove that ALL instantiations of a template have specific unreachable code. If we come up with a better solution, then we can revisit this, but this approach will at least greatly reduce the noise of this warning for code that makes use of templates.
llvm-svn: 145520
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/lib/Sema/AnalysisBasedWarnings.cpp | 10 | ||||
| -rw-r--r-- | clang/test/SemaCXX/warn-unreachable.cpp | 22 |
2 files changed, 30 insertions, 2 deletions
diff --git a/clang/lib/Sema/AnalysisBasedWarnings.cpp b/clang/lib/Sema/AnalysisBasedWarnings.cpp index 8b2e269708b..54a26b3253a 100644 --- a/clang/lib/Sema/AnalysisBasedWarnings.cpp +++ b/clang/lib/Sema/AnalysisBasedWarnings.cpp @@ -914,8 +914,14 @@ AnalysisBasedWarnings::IssueWarnings(sema::AnalysisBasedWarnings::Policy P, } // Warning: check for unreachable code - if (P.enableCheckUnreachable) - CheckUnreachable(S, AC); + if (P.enableCheckUnreachable) { + // Only check for unreachable code on non-template instantiations. + // Different template instantiations can effectively change the control-flow + // and it is very difficult to prove that a snippet of code in a template + // is unreachable for all instantiations. + if (S.ActiveTemplateInstantiations.empty()) + CheckUnreachable(S, AC); + } // Check for thread safety violations if (P.enableThreadSafetyAnalysis) { diff --git a/clang/test/SemaCXX/warn-unreachable.cpp b/clang/test/SemaCXX/warn-unreachable.cpp index 604a3c0da38..fa740bac658 100644 --- a/clang/test/SemaCXX/warn-unreachable.cpp +++ b/clang/test/SemaCXX/warn-unreachable.cpp @@ -76,3 +76,25 @@ void test6() { S (halt()); // expected-warning {{will never be executed}} } + +// Don't warn about unreachable code in template instantiations, as +// they may only be unreachable in that specific instantiation. +void isUnreachable(); + +template <typename T> void test_unreachable_templates() { + T::foo(); + isUnreachable(); // no-warning +} + +struct TestUnreachableA { + static void foo() __attribute__((noreturn)); +}; +struct TestUnreachableB { + static void foo(); +}; + +void test_unreachable_templates_harness() { + test_unreachable_templates<TestUnreachableA>(); + test_unreachable_templates<TestUnreachableB>(); +} + |

