]> granicus.if.org Git - clang/commitdiff
Reapply r152745 (reverted in 152765) now that compiler-rt is fixed.
authorDavid Blaikie <dblaikie@gmail.com>
Thu, 15 Mar 2012 04:50:32 +0000 (04:50 +0000)
committerDavid Blaikie <dblaikie@gmail.com>
Thu, 15 Mar 2012 04:50:32 +0000 (04:50 +0000)
Original commit message:

Provide -Wnull-conversion separately from -Wconversion.

Like GCC, provide a NULL conversion to non-pointer conversion as a separate
flag, on by default. GCC's flag is "conversion-null" which we provide for
cross compatibility, but in the interests of consistency (with
-Wint-conversion, -Wbool-conversion, etc) the canonical Clang flag is called
-Wnull-conversion.

Patch by Lubos Lunak.
Review feedback by myself, Chandler Carruth, and Chad Rosier.

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

include/clang/Basic/DiagnosticGroups.td
include/clang/Basic/DiagnosticSemaKinds.td
lib/Driver/Tools.cpp
test/Analysis/nullptr.cpp
test/SemaCXX/__null.cpp
test/SemaCXX/conversion.cpp

index 26dcc40abaea33dd86c4637d63ca78788e26a2ab..3063b289c73d4ce1c016b8cd1993395238d6286b 100644 (file)
@@ -28,6 +28,7 @@ def Availability : DiagGroup<"availability">;
 def AutoImport : DiagGroup<"auto-import">;
 def BoolConversions : DiagGroup<"bool-conversions">;
 def IntConversions : DiagGroup<"int-conversions">;
+def NullConversion : DiagGroup<"null-conversion">;
 def BuiltinRequiresHeader : DiagGroup<"builtin-requires-header">;
 def CXXCompat: DiagGroup<"c++-compat">;
 def CastAlign : DiagGroup<"cast-align">;
@@ -282,6 +283,7 @@ def Parentheses : DiagGroup<"parentheses",
 //   - conversion warnings with constant sources are on by default
 //   - conversion warnings for literals are on by default
 //   - bool-to-pointer conversion warnings are on by default
+//   - __null-to-integer conversion warnings are on by default
 def Conversion : DiagGroup<"conversion",
                            [DiagGroup<"shorten-64-to-32">,
                             DiagGroup<"constant-conversion">,
@@ -289,6 +291,7 @@ def Conversion : DiagGroup<"conversion",
                             DiagGroup<"string-conversion">,
                             DiagGroup<"sign-conversion">,
                             BoolConversions,
+                            NullConversion,
                             IntConversions]>,
                  DiagCategory<"Value Conversion Issue">;
 
@@ -357,6 +360,9 @@ def : DiagGroup<"all", [Most, Parentheses, Switch]>;
 def : DiagGroup<"", [Extra]>;                   // -W = -Wextra
 def : DiagGroup<"endif-labels", [ExtraTokens]>; // -Wendif-labels=-Wendif-tokens
 def : DiagGroup<"comments", [Comment]>;         // -Wcomments = -Wcomment
+def : DiagGroup<"conversion-null",
+                [NullConversion]>; // -Wconversion-null = -Wnull-conversion
+             
 
 // A warning group for warnings that we want to have on by default in clang,
 // but which aren't on by default in GCC.
index 463db06d0918c262786f1a77b42537204737249a..0670d1f31a411274a4bfef969467b9325a7d25fe 100644 (file)
@@ -1732,7 +1732,7 @@ def warn_impcast_bool_to_null_pointer : Warning<
     "expression">, InGroup<BoolConversions>;
 def warn_impcast_null_pointer_to_integer : Warning<
     "implicit conversion of NULL constant to integer">,
-    InGroup<DiagGroup<"conversion">>, DefaultIgnore;
+    InGroup<NullConversion>;
 def warn_impcast_function_to_bool : Warning<
     "address of function %q0 will always evaluate to 'true'">,
     InGroup<BoolConversions>;
index 780016a8b869f17112e39a3fd4635729300215c1..536897f8792a85317f2d8a98e222b422bfdd11d2 100644 (file)
@@ -3168,6 +3168,7 @@ void darwin::CC1::RemoveCC1UnsupportedArgs(ArgStringList &CmdArgs) const {
         .Case("c++11-narrowing", true)
         .Case("conditional-uninitialized", true)
         .Case("constant-conversion", true)
+        .Case("conversion-null", true)
         .Case("CFString-literal", true)
         .Case("constant-logical-operand", true)
         .Case("custom-atomic-properties", true)
index c0fed872428005343e6e51a044082c3f34195f4f..3119b4fc390c28c117118a19961c6ff317842f00 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -std=c++11 -analyze -analyzer-checker=core -analyzer-store region -verify %s
+// RUN: %clang_cc1 -std=c++11 -Wno-conversion-null -analyze -analyzer-checker=core -analyzer-store region -verify %s
 
 // test to see if nullptr is detected as a null pointer
 void foo1(void) {
index 1989a45fb5f21ae01bc21a59752f57dde402ee3b..56e59c06f16bd11e1227b7a5921722a934051189 100644 (file)
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify
-// RUN: %clang_cc1 -triple i686-unknown-unknown %s -fsyntax-only -verify
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -Wno-null-conversion -fsyntax-only -verify
+// RUN: %clang_cc1 -triple i686-unknown-unknown %s -Wno-null-conversion -fsyntax-only -verify
 
 void f() {
   int* i = __null;
index b069abc263f4aa129820a45c5078fe0a2b50aaa1..d9ba07ab5b5703c4829a5a278e0e3f4e55c250c7 100644 (file)
@@ -53,10 +53,14 @@ namespace test2 {
   };
 }
 
+// This file tests -Wnull-conversion, a subcategory of -Wconversion
+// which is on by default.
+
 void test3() {
   int a = NULL; // expected-warning {{implicit conversion of NULL constant to integer}}
   int b;
   b = NULL; // expected-warning {{implicit conversion of NULL constant to integer}}
+  long l = NULL; // FIXME: this should also warn, but currently does not if sizeof(NULL)==sizeof(inttype)
   int c = ((((NULL)))); // expected-warning {{implicit conversion of NULL constant to integer}}
   int d;
   d = ((((NULL)))); // expected-warning {{implicit conversion of NULL constant to integer}}