[cfe-commits] r124278 - in /cfe/trunk: lib/Analysis/UninitializedValuesV2.cpp test/Sema/uninit-variables.c
Ted Kremenek
kremenek at apple.com
Tue Jan 25 20:49:43 PST 2011
Author: kremenek
Date: Tue Jan 25 22:49:43 2011
New Revision: 124278
URL: http://llvm.org/viewvc/llvm-project?rev=124278&view=rev
Log:
Tweak -Wuninitialized-experimental to not emit
a warning for uses of an uninitialized variable
when the use is a void cast, e.g. (void) x.
Modified:
cfe/trunk/lib/Analysis/UninitializedValuesV2.cpp
cfe/trunk/test/Sema/uninit-variables.c
Modified: cfe/trunk/lib/Analysis/UninitializedValuesV2.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/UninitializedValuesV2.cpp?rev=124278&r1=124277&r2=124278&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/UninitializedValuesV2.cpp (original)
+++ cfe/trunk/lib/Analysis/UninitializedValuesV2.cpp Tue Jan 25 22:49:43 2011
@@ -291,6 +291,7 @@
AnalysisContext ∾
UninitVariablesHandler *handler;
const DeclRefExpr *currentDR;
+ const Expr *currentVoidCast;
const bool flagBlockUses;
public:
TransferFunctions(CFGBlockValues &vals, const CFG &cfg,
@@ -298,7 +299,7 @@
UninitVariablesHandler *handler,
bool flagBlockUses)
: vals(vals), cfg(cfg), ac(ac), handler(handler), currentDR(0),
- flagBlockUses(flagBlockUses) {}
+ currentVoidCast(0), flagBlockUses(flagBlockUses) {}
const CFG &getCFG() { return cfg; }
void reportUninit(const DeclRefExpr *ex, const VarDecl *vd);
@@ -446,14 +447,23 @@
SaveAndRestore<const DeclRefExpr*> lastDR(currentDR,
res.getDeclRefExpr());
Visit(ce->getSubExpr());
- if (vals[vd] == Uninitialized) {
+ if (currentVoidCast != ce && vals[vd] == Uninitialized) {
reportUninit(res.getDeclRefExpr(), vd);
// Don't cascade warnings.
vals[vd] = Initialized;
}
return;
}
- }
+ }
+ else if (CStyleCastExpr *cse = dyn_cast<CStyleCastExpr>(ce)) {
+ if (cse->getType()->isVoidType()) {
+ // e.g. (void) x;
+ SaveAndRestore<const Expr *>
+ lastVoidCast(currentVoidCast, cse->getSubExpr()->IgnoreParens());
+ Visit(cse->getSubExpr());
+ return;
+ }
+ }
Visit(ce->getSubExpr());
}
Modified: cfe/trunk/test/Sema/uninit-variables.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/uninit-variables.c?rev=124278&r1=124277&r2=124278&view=diff
==============================================================================
--- cfe/trunk/test/Sema/uninit-variables.c (original)
+++ cfe/trunk/test/Sema/uninit-variables.c Tue Jan 25 22:49:43 2011
@@ -212,3 +212,14 @@
(void) ^{ (void) test32_x; }; // no-warning
}
+void test_33() {
+ int x; // no-warning
+ (void) x;
+}
+
+int test_34() {
+ int x; // expected-warning{{use of uninitialized variable 'x'}} expected-note{{add initialization to silence this warning}}
+ (void) x;
+ return x; // expected-note{{variable 'x' is possibly uninitialized when used here}}
+}
+
More information about the cfe-commits
mailing list