[cfe-commits] r127802 - in /cfe/trunk: lib/Sema/AnalysisBasedWarnings.cpp test/SemaCXX/uninit-variables-conditional.cpp
Ted Kremenek
kremenek at apple.com
Wed Mar 16 22:29:57 PDT 2011
Author: kremenek
Date: Thu Mar 17 00:29:57 2011
New Revision: 127802
URL: http://llvm.org/viewvc/llvm-project?rev=127802&view=rev
Log:
Don't construct two CFGs just to run -Wuninitialized. While this causes new warnings to be flagged under -Wconditional-uninitialized, this is something we
can improve over time.
Added:
cfe/trunk/test/SemaCXX/uninit-variables-conditional.cpp
Modified:
cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
Modified: cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp?rev=127802&r1=127801&r2=127802&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp (original)
+++ cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp Thu Mar 17 00:29:57 2011
@@ -611,24 +611,7 @@
!= 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);
Added: cfe/trunk/test/SemaCXX/uninit-variables-conditional.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/uninit-variables-conditional.cpp?rev=127802&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/uninit-variables-conditional.cpp (added)
+++ cfe/trunk/test/SemaCXX/uninit-variables-conditional.cpp Thu Mar 17 00:29:57 2011
@@ -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;
+}
More information about the cfe-commits
mailing list