]> granicus.if.org Git - clang/commitdiff
Disable dead stores checker for template instantations. Fixes <rdar://problem/13213575>.
authorTed Kremenek <kremenek@apple.com>
Mon, 18 Feb 2013 07:18:28 +0000 (07:18 +0000)
committerTed Kremenek <kremenek@apple.com>
Mon, 18 Feb 2013 07:18:28 +0000 (07:18 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175425 91177308-0d34-0410-b5e6-96231b3b80d8

lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
test/Analysis/dead-stores.cpp

index e2f8395da909c487c463e82a99e82b897e4edeb0..f2e3e6d7815e113a24f0667fd7af8c73f8c58541 100644 (file)
@@ -419,6 +419,15 @@ class DeadStoresChecker : public Checker<check::ASTCodeBody> {
 public:
   void checkASTCodeBody(const Decl *D, AnalysisManager& mgr,
                         BugReporter &BR) const {
+
+    // Don't do anything for template instantiations.
+    // Proving that code in a template instantiation is "dead"
+    // means proving that it is dead in all instantiations.
+    // This same problem exists with -Wunreachable-code.
+    if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
+      if (FD->isTemplateInstantiation())
+        return;
+
     if (LiveVariables *L = mgr.getAnalysis<LiveVariables>(D)) {
       CFG &cfg = *mgr.getCFG(D);
       AnalysisDeclContext *AC = mgr.getAnalysisDeclContext(D);
index e1a034b1d021a21ec7ec674c965735886d512ae1..d442c621d87b3c79c85aa8b409396058110b3ea8 100644 (file)
@@ -156,3 +156,21 @@ void testCXX11Using() {
   Int value;
   value = 1; // expected-warning {{never read}}
 }
+
+//===----------------------------------------------------------------------===//
+// Dead stores in template instantiations (do not warn).
+//===----------------------------------------------------------------------===//
+
+template <bool f> int radar13213575_testit(int i) {
+  int x = 5+i; // warning: Value stored to 'x' during its initialization is never read
+  int y = 7;
+  if (f)
+    return x;
+  else
+    return y;
+}
+
+int radar_13213575() {
+  return radar13213575_testit<true>(5) + radar13213575_testit<false>(3);
+}
+