aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJordy Rose <jediknil@belkadan.com>2011-06-08 22:47:39 +0000
committerJordy Rose <jediknil@belkadan.com>2011-06-08 22:47:39 +0000
commit22043b5ad4278cba814608f0368813acfcf24b67 (patch)
tree4a48d0557ab0e4131c3f66d0693236666480f982
parentf9f8c1d291d9202054f3f225fdd240e771e1427f (diff)
[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
-rw-r--r--lib/StaticAnalyzer/Core/Environment.cpp12
-rw-r--r--test/Analysis/misc-ps.c14
2 files changed, 20 insertions, 6 deletions
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<Expr>(E))
+ E = Ex->IgnoreParens();
+
switch (E->getStmtClass()) {
case Stmt::AddrLabelExprClass:
return svalBuilder.makeLoc(cast<AddrLabelExpr>(E));
@@ -48,13 +51,10 @@ SVal Environment::getSVal(const Stmt *E, SValBuilder& svalBuilder,
continue;
}
case Stmt::ParenExprClass:
- // ParenExprs are no-ops.
- E = cast<ParenExpr>(E)->getSubExpr();
- continue;
case Stmt::GenericSelectionExprClass:
- // GenericSelectionExprs are no-ops.
- E = cast<GenericSelectionExpr>(E)->getResultExpr();
- continue;
+ llvm_unreachable("ParenExprs and GenericSelectionExprs should "
+ "have been handled by IgnoreParens()");
+ return UnknownVal();
case Stmt::CharacterLiteralClass: {
const CharacterLiteral* C = cast<CharacterLiteral>(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}}
+}
+