return 0;
}
-bool bugreporter::trackNullOrUndefValue(const ExplodedNode *N,
- const Stmt *S,
- BugReport &report, bool IsArg) {
- if (!S || !N)
- return false;
-
- if (const ExprWithCleanups *EWC = dyn_cast<ExprWithCleanups>(S))
- S = EWC->getSubExpr();
- if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(S))
- S = OVE->getSourceExpr();
-
- // Peel off the ternary operator.
+static const Expr *peelOffOuterExpr(const Stmt *S,
+ const ExplodedNode *N) {
if (const Expr *Ex = dyn_cast<Expr>(S)) {
Ex = Ex->IgnoreParenCasts();
+ if (const ExprWithCleanups *EWC = dyn_cast<ExprWithCleanups>(Ex))
+ return EWC->getSubExpr();
+ if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(Ex))
+ return OVE->getSourceExpr();
+
+ // Peel off the ternary operator.
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();
+ return CO->getTrueExpr();
} else {
assert(State->isNull(CondVal).isConstrainedFalse());
- S = CO->getFalseExpr();
+ return CO->getFalseExpr();
}
}
}
+ return 0;
+}
+
+bool bugreporter::trackNullOrUndefValue(const ExplodedNode *N,
+ const Stmt *S,
+ BugReport &report, bool IsArg) {
+ if (!S || !N)
+ return false;
+
+ if (const Expr *Ex = peelOffOuterExpr(S, N)) {
+ S = Ex;
+ }
const Expr *Inner = 0;
if (const Expr *Ex = dyn_cast<Expr>(S)) {
NSDictionary *testNilArgNSDictionary2(NSObject *obj) {
return [NSDictionary dictionaryWithObject:obj forKey:0]; // expected-warning {{Argument to 'NSDictionary' method 'dictionaryWithObject:forKey:' cannot be nil}}
}
+
+// Test inline defensive checks suppression.
+void idc(id x) {
+ if (x)
+ ;
+}
+void testIDC(NSMutableDictionary *d, NSString *key) {
+ idc(key);
+ d[key] = @"abc"; // no-warning
+}
+
+@interface Foo
+- (int *)getPtr;
+- (int)getInt;
+@end
+
+void idc2(id x) {
+ if (!x)
+ return;
+}
+
+void testIDC2(Foo *obj) {
+ idc2(obj);
+ *[obj getPtr] = 1; // no-warning
+}
+
+int testIDC3(Foo *obj) {
+ idc2(obj);
+ return 1/[obj getInt];
+}
+