Author: ericwf Date: Thu Oct 8 19:17:57 2015 New Revision: 249787 URL: http://llvm.org/viewvc/llvm-project?rev=249787&view=rev Log: Skip NonNull sema checks in unevaluated contexts.
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 Modified: cfe/trunk/lib/Sema/SemaChecking.cpp cfe/trunk/test/Sema/non-null-warning.c Modified: cfe/trunk/lib/Sema/SemaChecking.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=249787&r1=249786&r2=249787&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaChecking.cpp (original) +++ cfe/trunk/lib/Sema/SemaChecking.cpp Thu Oct 8 19:17:57 2015 @@ -1151,7 +1151,8 @@ static void CheckNonNullArgument(Sema &S 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) { Modified: cfe/trunk/test/Sema/non-null-warning.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/non-null-warning.c?rev=249787&r1=249786&r2=249787&view=diff ============================================================================== --- cfe/trunk/test/Sema/non-null-warning.c (original) +++ cfe/trunk/test/Sema/non-null-warning.c Thu Oct 8 19:17:57 2015 @@ -37,6 +37,9 @@ int * ret_nonnull() { 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. } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits