[cfe-commits] r158744 - in /cfe/trunk: lib/Sema/SemaChecking.cpp test/FixIt/fixit.cpp test/SemaCXX/conversion.cpp

David Blaikie dblaikie at gmail.com
Tue Jun 19 14:19:06 PDT 2012


Author: dblaikie
Date: Tue Jun 19 16:19:06 2012
New Revision: 158744

URL: http://llvm.org/viewvc/llvm-project?rev=158744&view=rev
Log:
Enable -Wnull-conversion for non-integral target types (eg: double).

Modified:
    cfe/trunk/lib/Sema/SemaChecking.cpp
    cfe/trunk/test/FixIt/fixit.cpp
    cfe/trunk/test/SemaCXX/conversion.cpp

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=158744&r1=158743&r2=158744&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Tue Jun 19 16:19:06 2012
@@ -4279,11 +4279,10 @@
     return;
   }
 
-  if (!Source->isIntegerType() || !Target->isIntegerType())
-    return;
-
   if ((E->isNullPointerConstant(S.Context, Expr::NPC_ValueDependentIsNotNull)
-           == Expr::NPCK_GNUNull) && Target->isIntegerType()) {
+           == Expr::NPCK_GNUNull) && !Target->isAnyPointerType()
+      && !Target->isBlockPointerType() && !Target->isFunctionPointerType()
+      && !Target->isMemberFunctionPointerType()) {
     SourceLocation Loc = E->getSourceRange().getBegin();
     if (Loc.isMacroID())
       Loc = S.SourceMgr.getImmediateExpansionRange(Loc).first;
@@ -4291,9 +4290,11 @@
       S.Diag(Loc, diag::warn_impcast_null_pointer_to_integer)
           << T << clang::SourceRange(CC)
           << FixItHint::CreateReplacement(Loc, S.getFixItZeroLiteralForType(T));
-    return;
   }
 
+  if (!Source->isIntegerType() || !Target->isIntegerType())
+    return;
+
   // TODO: remove this early return once the false positives for constant->bool
   // in templates, macros, etc, are reduced or removed.
   if (Target->isSpecificBuiltinType(BuiltinType::Bool))

Modified: cfe/trunk/test/FixIt/fixit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/FixIt/fixit.cpp?rev=158744&r1=158743&r2=158744&view=diff
==============================================================================
--- cfe/trunk/test/FixIt/fixit.cpp (original)
+++ cfe/trunk/test/FixIt/fixit.cpp Tue Jun 19 16:19:06 2012
@@ -219,6 +219,7 @@
 
 #define NULL __null
 char c = NULL; // expected-warning {{implicit conversion of NULL constant to 'char'}}
+double dbl = NULL; // expected-warning {{implicit conversion of NULL constant to 'double'}}
 
 namespace arrow_suggest {
 

Modified: cfe/trunk/test/SemaCXX/conversion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/conversion.cpp?rev=158744&r1=158743&r2=158744&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/conversion.cpp (original)
+++ cfe/trunk/test/SemaCXX/conversion.cpp Tue Jun 19 16:19:06 2012
@@ -69,6 +69,7 @@
   char ch = NULL; // expected-warning {{implicit conversion of NULL constant to 'char'}}
   unsigned char uch = NULL; // expected-warning {{implicit conversion of NULL constant to 'unsigned char'}}
   short sh = NULL; // expected-warning {{implicit conversion of NULL constant to 'short'}}
+  double dbl = NULL; // expected-warning {{implicit conversion of NULL constant to 'double'}}
 
   // Use FileCheck to ensure we don't get any unnecessary macro-expansion notes 
   // (that don't appear as 'real' notes & can't be seen/tested by -verify)





More information about the cfe-commits mailing list