[cfe-commits] r172875 - in /cfe/trunk: lib/Analysis/UninitializedValues.cpp test/SemaCXX/uninitialized.cpp
Ted Kremenek
kremenek at apple.com
Fri Jan 18 16:25:06 PST 2013
Author: kremenek
Date: Fri Jan 18 18:25:06 2013
New Revision: 172875
URL: http://llvm.org/viewvc/llvm-project?rev=172875&view=rev
Log:
-Wuninitialized: warn about uninitialized values resulting from ?: that evaluate to lvalues (in C++).
Modified:
cfe/trunk/lib/Analysis/UninitializedValues.cpp
cfe/trunk/test/SemaCXX/uninitialized.cpp
Modified: cfe/trunk/lib/Analysis/UninitializedValues.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/UninitializedValues.cpp?rev=172875&r1=172874&r2=172875&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/UninitializedValues.cpp (original)
+++ cfe/trunk/lib/Analysis/UninitializedValues.cpp Fri Jan 18 18:25:06 2013
@@ -358,6 +358,16 @@
}
void ClassifyRefs::classify(const Expr *E, Class C) {
+ // The result of a ?: could also be an lvalue.
+ E = E->IgnoreParens();
+ if (const ConditionalOperator *CO = dyn_cast<ConditionalOperator>(E)) {
+ const Expr *TrueExpr = CO->getTrueExpr();
+ if (!isa<OpaqueValueExpr>(TrueExpr))
+ classify(TrueExpr, C);
+ classify(CO->getFalseExpr(), C);
+ return;
+ }
+
FindVarResult Var = findVar(E, DC);
if (const DeclRefExpr *DRE = Var.getDeclRefExpr())
Classification[DRE] = std::max(Classification[DRE], C);
Modified: cfe/trunk/test/SemaCXX/uninitialized.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/uninitialized.cpp?rev=172875&r1=172874&r2=172875&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/uninitialized.cpp (original)
+++ cfe/trunk/test/SemaCXX/uninitialized.cpp Fri Jan 18 18:25:06 2013
@@ -41,8 +41,8 @@
int j = far(j);
int k = __alignof__(k);
- int l = k ? l : l; // FIXME: warn here
- int m = 1 + (k ? m : m); // FIXME: warn here
+ int l = k ? l : l; // expected-warning {{variable 'l' is uninitialized when used within its own initialization}}
+ int m = 1 + (k ? m : m); // expected-warning {{'m' is uninitialized when used within its own initialization}}
int n = -n; // expected-warning {{variable 'n' is uninitialized when used within its own initialization}}
for (;;) {
@@ -61,8 +61,8 @@
int j = far(j);
int k = __alignof__(k);
- int l = k ? l : l; // FIXME: warn here
- int m = 1 + (k ? m : m); // FIXME: warn here
+ int l = k ? l : l; // expected-warning {{variable 'l' is uninitialized when used within its own initialization}}
+ int m = 1 + (k ? m : m); // expected-warning {{'m' is uninitialized when used within its own initialization}}
int n = -n; // expected-warning {{variable 'n' is uninitialized when used within its own initialization}}
}
}
More information about the cfe-commits
mailing list