From: Jordy Rose Date: Wed, 8 Jun 2011 22:47:39 +0000 (+0000) Subject: [analyzer] Look through __extension__ expressions in a GRState's Environment. Fixes... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=22043b5ad4278cba814608f0368813acfcf24b67;p=clang [analyzer] Look through __extension__ expressions in a GRState's Environment. Fixes PR8962. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@132762 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/StaticAnalyzer/Core/Environment.cpp b/lib/StaticAnalyzer/Core/Environment.cpp index a00f9dc10b..e9f5016b36 100644 --- a/lib/StaticAnalyzer/Core/Environment.cpp +++ b/lib/StaticAnalyzer/Core/Environment.cpp @@ -39,6 +39,9 @@ SVal Environment::getSVal(const Stmt *E, SValBuilder& svalBuilder, } for (;;) { + if (const Expr *Ex = dyn_cast(E)) + E = Ex->IgnoreParens(); + switch (E->getStmtClass()) { case Stmt::AddrLabelExprClass: return svalBuilder.makeLoc(cast(E)); @@ -48,13 +51,10 @@ SVal Environment::getSVal(const Stmt *E, SValBuilder& svalBuilder, continue; } case Stmt::ParenExprClass: - // ParenExprs are no-ops. - E = cast(E)->getSubExpr(); - continue; case Stmt::GenericSelectionExprClass: - // GenericSelectionExprs are no-ops. - E = cast(E)->getResultExpr(); - continue; + llvm_unreachable("ParenExprs and GenericSelectionExprs should " + "have been handled by IgnoreParens()"); + return UnknownVal(); case Stmt::CharacterLiteralClass: { const CharacterLiteral* C = cast(E); return svalBuilder.makeIntVal(C->getValue(), C->getType()); diff --git a/test/Analysis/misc-ps.c b/test/Analysis/misc-ps.c index 2d4fdd4637..0729ce2f77 100644 --- a/test/Analysis/misc-ps.c +++ b/test/Analysis/misc-ps.c @@ -36,3 +36,17 @@ int rdar93730392() { return j; } + +int PR8962 (int *t) { + // This should look through the __extension__ no-op. + if (__extension__ (t)) return 0; + return *t; // expected-warning {{null pointer}} +} + +int PR8962_b (int *t) { + // This should still ignore the nested casts + // which aren't handled by a single IgnoreParens() + if (((int)((int)t))) return 0; + return *t; // expected-warning {{null pointer}} +} +