aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnna Zaks <ganna@apple.com>2013-03-15 23:34:25 +0000
committerAnna Zaks <ganna@apple.com>2013-03-15 23:34:25 +0000
commitf510f5cd57fa9b7ea6f6e103c65c0df95a55d986 (patch)
treec303571e0a19bb19b87ba3f0a1edf43631e918c0
parentf8ba81e8bbc4d0d424c3b4c3581a9467e972c4de (diff)
downloadclang-f510f5cd57fa9b7ea6f6e103c65c0df95a55d986.tar.gz
[analyzer] BugReporterVisitors: handle the case where a ternary operator is wrapped in a cast.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177205 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/StaticAnalyzer/Core/BugReporterVisitors.cpp19
-rw-r--r--test/Analysis/inlining/false-positive-suppression.c11
2 files changed, 22 insertions, 8 deletions
diff --git a/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp b/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
index d5b4714451..6e5f6b8f2c 100644
--- a/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ b/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -787,14 +787,17 @@ bool bugreporter::trackNullOrUndefValue(const ExplodedNode *N,
S = OVE->getSourceExpr();
// Peel off the ternary operator.
- if (const ConditionalOperator *CO = dyn_cast<ConditionalOperator>(S)) {
- ProgramStateRef State = N->getState();
- SVal CondVal = State->getSVal(CO->getCond(), N->getLocationContext());
- if (State->isNull(CondVal).isConstrainedTrue()) {
- S = CO->getTrueExpr();
- } else {
- assert(State->isNull(CondVal).isConstrainedFalse());
- S = CO->getFalseExpr();
+ if (const Expr *Ex = dyn_cast<Expr>(S)) {
+ Ex = Ex->IgnoreParenCasts();
+ if (const ConditionalOperator *CO = dyn_cast<ConditionalOperator>(Ex)) {
+ ProgramStateRef State = N->getState();
+ SVal CondVal = State->getSVal(CO->getCond(), N->getLocationContext());
+ if (State->isNull(CondVal).isConstrainedTrue()) {
+ S = CO->getTrueExpr();
+ } else {
+ assert(State->isNull(CondVal).isConstrainedFalse());
+ S = CO->getFalseExpr();
+ }
}
}
diff --git a/test/Analysis/inlining/false-positive-suppression.c b/test/Analysis/inlining/false-positive-suppression.c
index fbdb1650ff..31ad891762 100644
--- a/test/Analysis/inlining/false-positive-suppression.c
+++ b/test/Analysis/inlining/false-positive-suppression.c
@@ -202,6 +202,17 @@ void ternaryArg(char cond) {
derefArg(cond ? &x : getNull());
}
+int derefArgCast(char *p) {
+ return *p;
+#ifndef SUPPRESSED
+ // expected-warning@-2 {{Dereference of null pointer}}
+#endif
+}
+void ternaryArgCast(char cond) {
+ static int x;
+ derefArgCast((char*)((unsigned)cond ? &x : getNull()));
+}
+
int derefAssignment(int *p) {
return *p;
#ifndef SUPPRESSED