]> granicus.if.org Git - clang/commitdiff
Skip NonNull sema checks in unevaluated contexts.
authorEric Fiselier <eric@efcs.ca>
Fri, 9 Oct 2015 00:17:57 +0000 (00:17 +0000)
committerEric Fiselier <eric@efcs.ca>
Fri, 9 Oct 2015 00:17:57 +0000 (00:17 +0000)
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

lib/Sema/SemaChecking.cpp
test/Sema/non-null-warning.c

index 599a0e4be214626f91dd6dcd01660d9a329ad633..a8d882a635eee29bea139c36fa0ebaafb5701e1e 100644 (file)
@@ -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) {
index 024ef1eca6670a47d95a47937b399dff3c2144b0..7dfa3900cbb572ca5c29eed3e15f94f5d3b4a3e0 100644 (file)
@@ -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.
 }