]> granicus.if.org Git - clang/commitdiff
[Sema] For -Wnon-literal-null-conversion warning, look through integer casts, which...
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Fri, 31 Jan 2014 07:51:32 +0000 (07:51 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Fri, 31 Jan 2014 07:51:32 +0000 (07:51 +0000)
by some projects in their null macro.

rdar://15925483

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@200521 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaOverload.cpp
test/Sema/warn-null.c

index 8e52e620a775500a2217b9915a42c26478dd6269..9d70d9f3e48f9193f736e8fbf5b322e8e8ad7dde 100644 (file)
@@ -2622,6 +2622,19 @@ bool Sema::FunctionParamTypesAreEqual(const FunctionProtoType *OldType,
   return true;
 }
 
+static Expr *ignoreIntegerCasts(Expr *E) {
+  while (true) {
+    if (ExplicitCastExpr *ECE = dyn_cast<ExplicitCastExpr>(E)) {
+      if (ECE->getType()->isIntegerType()) {
+        E = ECE->getSubExpr();
+        continue;
+      }
+    }
+
+    return E;
+  }
+}
+
 /// CheckPointerConversion - Check the pointer conversion from the
 /// expression From to the type ToType. This routine checks for
 /// ambiguous or inaccessible derived-to-base pointer
@@ -2638,7 +2651,8 @@ bool Sema::CheckPointerConversion(Expr *From, QualType ToType,
   Kind = CK_BitCast;
 
   if (!IsCStyleOrFunctionalCast && !FromType->isAnyPointerType() &&
-      From->isNullPointerConstant(Context, Expr::NPC_ValueDependentIsNotNull) ==
+      ignoreIntegerCasts(From)->
+        isNullPointerConstant(Context, Expr::NPC_ValueDependentIsNotNull) ==
       Expr::NPCK_ZeroExpression) {
     if (Context.hasSameUnqualifiedType(From->getType(), Context.BoolTy))
       DiagRuntimeBehavior(From->getExprLoc(), From,
index 28fb6a5f691c57c7b5da6ba9fa131714690ae225..28ec631415ddf6e2d99e353781857399beb95dba 100644 (file)
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 %s -verify
 
+#define NLL (unsigned long long)0
+
 // PR10837: Warn if a non-pointer-typed expression is folded to a null pointer
 int *p = 0;
 int *q = '\0'; // expected-warning{{expression which evaluates to zero treated as a null pointer constant}}
@@ -8,4 +10,5 @@ void f() {
   p = 0;
   q = '\0'; // expected-warning{{expression which evaluates to zero treated as a null pointer constant}}
   r = 1 - 1; // expected-warning{{expression which evaluates to zero treated as a null pointer constant}}
+  p = NLL;
 }