[cfe-commits] r159620 - in /cfe/trunk: lib/Analysis/UninitializedValues.cpp test/Sema/uninit-variables.c
Richard Smith
richard-llvm at metafoo.co.uk
Mon Jul 2 16:23:05 PDT 2012
Author: rsmith
Date: Mon Jul 2 18:23:04 2012
New Revision: 159620
URL: http://llvm.org/viewvc/llvm-project?rev=159620&view=rev
Log:
-Wuninitialized: assume that an __attribute__((returns_twice)) function might
initialize any variable. This is extremely conservative, but is sufficient for
now.
Modified:
cfe/trunk/lib/Analysis/UninitializedValues.cpp
cfe/trunk/test/Sema/uninit-variables.c
Modified: cfe/trunk/lib/Analysis/UninitializedValues.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/UninitializedValues.cpp?rev=159620&r1=159619&r2=159620&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/UninitializedValues.cpp (original)
+++ cfe/trunk/lib/Analysis/UninitializedValues.cpp Mon Jul 2 18:23:04 2012
@@ -116,6 +116,7 @@
BVPair &getValueVectors(const CFGBlock *block, bool shouldLazyCreate);
+ void setAllScratchValues(Value V);
void mergeIntoScratch(ValueVector const &source, bool isFirst);
bool updateValueVectorWithScratch(const CFGBlock *block);
bool updateValueVectors(const CFGBlock *block, const BVPair &newVals);
@@ -240,6 +241,11 @@
}
#endif
+void CFGBlockValues::setAllScratchValues(Value V) {
+ for (unsigned I = 0, E = scratch.size(); I != E; ++I)
+ scratch[I] = V;
+}
+
void CFGBlockValues::mergeIntoScratch(ValueVector const &source,
bool isFirst) {
if (isFirst)
@@ -374,6 +380,7 @@
void reportUse(const Expr *ex, const VarDecl *vd);
void VisitBlockExpr(BlockExpr *be);
+ void VisitCallExpr(CallExpr *ce);
void VisitDeclStmt(DeclStmt *ds);
void VisitDeclRefExpr(DeclRefExpr *dr);
void VisitUnaryOperator(UnaryOperator *uo);
@@ -576,6 +583,17 @@
}
}
+void TransferFunctions::VisitCallExpr(CallExpr *ce) {
+ // After a call to a function like setjmp or vfork, any variable which is
+ // initialized anywhere within this function may now be initialized. For now,
+ // just assume such a call initializes all variables.
+ // FIXME: Only mark variables as initialized if they have an initializer which
+ // is reachable from here.
+ Decl *Callee = ce->getCalleeDecl();
+ if (Callee && Callee->hasAttr<ReturnsTwiceAttr>())
+ vals.setAllScratchValues(Initialized);
+}
+
void TransferFunctions::VisitDeclRefExpr(DeclRefExpr *dr) {
// Record the last DeclRefExpr seen. This is an lvalue computation.
// We use this value to later detect if a variable "escapes" the analysis.
Modified: cfe/trunk/test/Sema/uninit-variables.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/uninit-variables.c?rev=159620&r1=159619&r2=159620&view=diff
==============================================================================
--- cfe/trunk/test/Sema/uninit-variables.c (original)
+++ cfe/trunk/test/Sema/uninit-variables.c Mon Jul 2 18:23:04 2012
@@ -466,3 +466,22 @@
k = produce();
}
}
+
+typedef char jmp_buf[256];
+extern int setjmp(jmp_buf env); // implicitly returns_twice
+
+void do_stuff_and_longjmp(jmp_buf env, int *result) __attribute__((noreturn));
+
+int returns_twice() {
+ int a; // expected-note {{initialize}}
+ if (!a) { // expected-warning {{variable 'a' is uninitialized}}
+ jmp_buf env;
+ int b;
+ if (setjmp(env) == 0) {
+ do_stuff_and_longjmp(env, &b);
+ } else {
+ a = b; // no warning
+ }
+ }
+ return a;
+}
More information about the cfe-commits
mailing list