[cfe-commits] r141345 - in /cfe/trunk: lib/Analysis/UninitializedValues.cpp test/Sema/uninit-variables.c
Ted Kremenek
kremenek at apple.com
Thu Oct 6 17:42:48 PDT 2011
Author: kremenek
Date: Thu Oct 6 19:42:48 2011
New Revision: 141345
URL: http://llvm.org/viewvc/llvm-project?rev=141345&view=rev
Log:
Fix infinite loop in -Wuninitialized reported in PR 11069.
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=141345&r1=141344&r2=141345&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/UninitializedValues.cpp (original)
+++ cfe/trunk/lib/Analysis/UninitializedValues.cpp Thu Oct 6 19:42:48 2011
@@ -212,13 +212,6 @@
return vals[idx];
}
-void CFGBlockValues::mergeIntoScratch(ValueVector const &source,
- bool isFirst) {
- if (isFirst)
- scratch = source;
- else
- scratch |= source;
-}
#if 0
static void printVector(const CFGBlock *block, ValueVector &bv,
unsigned num) {
@@ -229,8 +222,24 @@
}
llvm::errs() << " : " << num << '\n';
}
+
+static void printVector(const char *name, ValueVector const &bv) {
+ llvm::errs() << name << " : ";
+ for (unsigned i = 0; i < bv.size(); ++i) {
+ llvm::errs() << ' ' << bv[i];
+ }
+ llvm::errs() << "\n";
+}
#endif
+void CFGBlockValues::mergeIntoScratch(ValueVector const &source,
+ bool isFirst) {
+ if (isFirst)
+ scratch = source;
+ else
+ scratch |= source;
+}
+
bool CFGBlockValues::updateValueVectorWithScratch(const CFGBlock *block) {
ValueVector &dst = getValueVector(block, 0);
bool changed = (dst != scratch);
@@ -529,14 +538,9 @@
void TransferFunctions::VisitCastExpr(clang::CastExpr *ce) {
if (ce->getCastKind() == CK_LValueToRValue) {
const FindVarResult &res = findBlockVarDecl(ce->getSubExpr());
- if (const VarDecl *vd = res.getDecl()) {
+ if (res.getDecl()) {
assert(res.getDeclRefExpr() == lastDR);
- if (isUninitialized(vals[vd])) {
- // Record this load of an uninitialized value. Normally this
- // results in a warning, but we delay reporting the issue
- // in case it is wrapped in a void cast, etc.
- lastLoad = ce;
- }
+ lastLoad = ce;
}
}
else if (ce->getCastKind() == CK_NoOp ||
@@ -573,16 +577,19 @@
if (lastLoad == s)
return;
- // If we reach here, we have seen a load of an uninitialized value
- // and it hasn't been casted to void or otherwise handled. In this
- // situation, report the incident.
const DeclRefExpr *DR =
cast<DeclRefExpr>(stripCasts(ac.getASTContext(),
lastLoad->getSubExpr()));
const VarDecl *VD = cast<VarDecl>(DR->getDecl());
- reportUninit(DR, VD, isAlwaysUninit(vals[VD]));
+
+ // If we reach here, we may have seen a load of an uninitialized value
+ // and it hasn't been casted to void or otherwise handled. In this
+ // situation, report the incident.
+ if (isUninitialized(vals[VD]))
+ reportUninit(DR, VD, isAlwaysUninit(vals[VD]));
+
lastLoad = 0;
-
+
if (DR == lastDR) {
lastDR = 0;
return;
Modified: cfe/trunk/test/Sema/uninit-variables.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/uninit-variables.c?rev=141345&r1=141344&r2=141345&view=diff
==============================================================================
--- cfe/trunk/test/Sema/uninit-variables.c (original)
+++ cfe/trunk/test/Sema/uninit-variables.c Thu Oct 6 19:42:48 2011
@@ -391,3 +391,17 @@
return x; // no-warning
}
+// This previously triggered an infinite loop in the analysis.
+void PR11069(int a, int b) {
+ unsigned long flags;
+ for (;;) {
+ if (a && !b)
+ break;
+ }
+ for (;;) {
+ // This does not trigger a warning because it isn't a real use.
+ (void)(flags); // no-warning
+ }
+}
+
+
More information about the cfe-commits
mailing list