]> granicus.if.org Git - clang/commitdiff
Don't construct two CFGs just to run -Wuninitialized. While this causes new warnings...
authorTed Kremenek <kremenek@apple.com>
Thu, 17 Mar 2011 05:29:57 +0000 (05:29 +0000)
committerTed Kremenek <kremenek@apple.com>
Thu, 17 Mar 2011 05:29:57 +0000 (05:29 +0000)
can improve over time.

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

lib/Sema/AnalysisBasedWarnings.cpp
test/SemaCXX/uninit-variables-conditional.cpp [new file with mode: 0644]

index 3d00c7fe7e08c5c2e4132df56c6789697010171f..6522d95ec3c000b061c70a0f1ed44ff517717284 100644 (file)
@@ -611,24 +611,7 @@ AnalysisBasedWarnings::IssueWarnings(sema::AnalysisBasedWarnings::Policy P,
       != Diagnostic::Ignored ||
       Diags.getDiagnosticLevel(diag::warn_maybe_uninit_var, D->getLocStart())
       != Diagnostic::Ignored) {
-    ASTContext &ctx = D->getASTContext();
-    llvm::OwningPtr<CFG> tmpCFG;
-    bool useAlternateCFG = false;
-    if (ctx.getLangOptions().CPlusPlus) {
-      // Temporary workaround: implicit dtors in the CFG can confuse
-      // the path-sensitivity in the uninitialized values analysis.
-      // For now create (if necessary) a separate CFG without implicit dtors.
-      // FIXME: We should not need to do this, as it results in multiple
-      // CFGs getting constructed.
-      CFG::BuildOptions B;
-      B.AddEHEdges = false;
-      B.AddImplicitDtors = false;
-      B.AddInitializers = true;
-      tmpCFG.reset(CFG::buildCFG(D, AC.getBody(), &ctx, B));
-      useAlternateCFG = true;
-    }
-    CFG *cfg = useAlternateCFG ? tmpCFG.get() : AC.getCFG();
-    if (cfg) {
+    if (CFG *cfg = AC.getCFG()) {
       UninitValsDiagReporter reporter(S);
       runUninitializedVariablesAnalysis(*cast<DeclContext>(D), *cfg, AC,
                                         reporter);
diff --git a/test/SemaCXX/uninit-variables-conditional.cpp b/test/SemaCXX/uninit-variables-conditional.cpp
new file mode 100644 (file)
index 0000000..1a82285
--- /dev/null
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -fsyntax-only -Wconditional-uninitialized -fsyntax-only %s -verify
+
+class Foo {
+public:
+  Foo();
+  ~Foo();
+  operator bool();
+};
+
+int bar();
+int baz();
+int init(double *);
+
+// This case flags a false positive under -Wconditional-uninitialized because
+// the destructor in Foo fouls about the minor bit of path-sensitivity in
+// -Wuninitialized.
+double test() {
+  double x; // expected-note {{variable 'x' is declared here}} expected-note{{add initialization to silence this warning}}
+  if (bar() || baz() || Foo() || init(&x)) {
+    return x; // expected-warning {{variable 'x' is possibly uninitialized when used here}}
+  }
+  return 1.0;
+}