Summary:
Currently when a function annotated with __attribute__((nonnull)) is called in an unevaluated context with a null argument a -Wnonnull warning is emitted.
This warning seems like a false positive unless the call expression is potentially evaluated. Change this behavior so that the non-null warnings use DiagRuntimeBehavior so they wont emit when they won't be evaluated.
Reviewers: majnemer, rsmith
Subscribers: mclow.lists, cfe-commits
Differential Revision: http://reviews.llvm.org/D13408
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@249787
91177308-0d34-0410-b5e6-
96231b3b80d8
const Expr *ArgExpr,
SourceLocation CallSiteLoc) {
if (CheckNonNullExpr(S, ArgExpr))
- S.Diag(CallSiteLoc, diag::warn_null_arg) << ArgExpr->getSourceRange();
+ S.DiagRuntimeBehavior(CallSiteLoc, ArgExpr,
+ S.PDiag(diag::warn_null_arg) << ArgExpr->getSourceRange());
}
bool Sema::GetFormatNSStringIdx(const FormatAttr *Format, unsigned &Idx) {
return 0; // expected-warning {{null returned from function that requires a non-null return value}}
}
+#define SAFE_CALL(X) if (X) foo(X)
int main () {
foo(0); // expected-warning {{null passed to a callee that requires a non-null argument}}
+ (void)sizeof(foo(0)); // expect no diagnostic in unevaluated context.
+ SAFE_CALL(0); // expect no diagnostic for unreachable code.
}