diff options
author | Ted Kremenek <kremenek@apple.com> | 2011-08-08 21:43:08 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2011-08-08 21:43:08 +0000 |
commit | de091aeb4658e986ed8fa5fbce7ab35ef2ae26ec (patch) | |
tree | ca64e962caff5c5b2c77e26c1785323fc4e505d7 /lib/Analysis/UninitializedValues.cpp | |
parent | 5d8c062b8c1e5d42ecfa3c6ad52cf71c966516f0 (diff) |
Fix another -Wuninitialized assertion failure (this one involving bit casts) resulting from the recent -Wuninitialized changes.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@137068 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/UninitializedValues.cpp')
-rw-r--r-- | lib/Analysis/UninitializedValues.cpp | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/lib/Analysis/UninitializedValues.cpp b/lib/Analysis/UninitializedValues.cpp index 009922ae92..8bc9506c85 100644 --- a/lib/Analysis/UninitializedValues.cpp +++ b/lib/Analysis/UninitializedValues.cpp @@ -389,6 +389,20 @@ public: }; } +static const Expr *stripCasts(ASTContext &C, const Expr *Ex) { + while (Ex) { + Ex = Ex->IgnoreParenNoopCasts(C); + if (const CastExpr *CE = dyn_cast<CastExpr>(Ex)) { + if (CE->getCastKind() == CK_LValueBitCast) { + Ex = CE->getSubExpr(); + continue; + } + } + break; + } + return Ex; +} + void TransferFunctions::reportUninit(const DeclRefExpr *ex, const VarDecl *vd, bool isAlwaysUnit) { if (handler) handler->handleUseOfUninitVariable(ex, vd, isAlwaysUnit); @@ -470,9 +484,9 @@ void TransferFunctions::VisitDeclStmt(DeclStmt *ds) { // appropriately, but we need to continue to analyze subsequent uses // of the variable. if (init == lastLoad) { - DeclRefExpr *DR - = cast<DeclRefExpr>(lastLoad-> - getSubExpr()->IgnoreParenNoopCasts(ac.getASTContext())); + const DeclRefExpr *DR + = cast<DeclRefExpr>(stripCasts(ac.getASTContext(), + lastLoad->getSubExpr())); if (DR->getDecl() == vd) { // int x = x; // Propagate uninitialized value, but don't immediately report @@ -544,7 +558,8 @@ void TransferFunctions::VisitCastExpr(clang::CastExpr *ce) { } } } - else if (ce->getCastKind() == CK_NoOp) { + else if (ce->getCastKind() == CK_NoOp || + ce->getCastKind() == CK_LValueBitCast) { skipProcessUses = true; } else if (CStyleCastExpr *cse = dyn_cast<CStyleCastExpr>(ce)) { @@ -580,10 +595,10 @@ void TransferFunctions::ProcessUses(Stmt *s) { // 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. - DeclRefExpr *DR = - cast<DeclRefExpr>(lastLoad->getSubExpr()-> - IgnoreParenNoopCasts(ac.getASTContext())); - VarDecl *VD = cast<VarDecl>(DR->getDecl()); + const DeclRefExpr *DR = + cast<DeclRefExpr>(stripCasts(ac.getASTContext(), + lastLoad->getSubExpr())); + const VarDecl *VD = cast<VarDecl>(DR->getDecl()); reportUninit(DR, VD, isAlwaysUninit(vals[VD])); lastLoad = 0; |