[Sema] Revert the change in r200622 that allowed integer casts to silence -Wnon-liter...
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Tue, 11 Feb 2014 17:53:22 +0000 (17:53 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Tue, 11 Feb 2014 17:53:22 +0000 (17:53 +0000)
It is actually useful to warn in such cases, thanks to Dmitri for pushing on this and making us see the light!

Related to rdar://15925483 and rdar://15922612. The latter radar is where the usefulness of the warning is most clear.

llvm-svn: 201165

clang/lib/AST/Expr.cpp
clang/test/Sema/warn-null.c

index 649f358..3f5833c 100644 (file)
@@ -3061,9 +3061,6 @@ Expr::isNullPointerConstant(ASTContext &Ctx,
             Pointee->isVoidType() &&                              // to void*
             CE->getSubExpr()->getType()->isIntegerType())         // from int.
           return CE->getSubExpr()->isNullPointerConstant(Ctx, NPC);
-      // Or an integer cast.
-      } else if (CE->getType()->isIntegerType()) {
-        return CE->getSubExpr()->isNullPointerConstant(Ctx, NPC);
       }
     }
   } else if (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(this)) {
index 28ec631..3bf2aed 100644 (file)
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 %s -verify
 
-#define NLL (unsigned long long)0
+#define SOME_ADDR (unsigned long long)0
 
 // PR10837: Warn if a non-pointer-typed expression is folded to a null pointer
 int *p = 0;
@@ -10,5 +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;
+  p = SOME_ADDR; // expected-warning{{expression which evaluates to zero treated as a null pointer constant}}
 }