On Tuesday 13 of March 2012, David Blaikie wrote:
> On Tue, Mar 13, 2012 at 3:24 PM, David Blaikie <[email protected]> wrote:
> > If you're going to provide a tblgen name for the ConversionNull group,
> > perhaps you could define it above the Conversion group & use the
> > ConversionNull name (rather than using the "conversion-null" string
> > separately/twice) in Conversion's definition.
>
> And reuse the ConversionNull named group in DiagnosticSemaKinds.td
> too. The "conversion-null" string should be written once rather than
> three times.
Updated patch attached.
> > It's probably OK to remove the "DefaultIgnore" flag for this patch
> > too, again to be consistent with GCC (which has this warning on by
> > default).
>
> Hmm, weird - I'm looking at the DiagnosticSemaKinds.td & I'm not sure
> why this warning is actually on by default & your test case is
> passing. (assuming it is)
It is actually not. I simply copy&pasted it to a separate file, and I
ran 'make check', which ran LLVM's checks, and 'make unittest' in clang/,
which didn't run the tests in tests/ either. The NULL tests pass with the
updated patch when I run 'make' in clang/tests/.
> > One caveat is that this warning is currently a little bit broken in
> > Clang. If you initialize an integer of the same size as a pointer, the
> > warning will not be provided. i.e. only one warning is produced from:
> >
> > int i = __null;
> > long l = __null;
> >
> > (__null is the special null value that GNU's stdlib defines NULL to be
> > & how it detects this case) depending on whether you have a 32 bit or
> > 64 bit pointer (assuming you have one of those and that int is 32 bits
> > and long is 64). That's something to fix at some point...
I see. I'll leave that as a separate issue.
--
Lubos Lunak
[email protected]
--- clang/test/SemaCXX/__null.cpp.sav 2011-11-06 14:46:06.000000000 +0100
+++ clang/test/SemaCXX/__null.cpp 2012-03-14 06:40:33.332259119 +0100
@@ -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-conversion-null -fsyntax-only -verify
+// RUN: %clang_cc1 -triple i686-unknown-unknown %s -Wno-conversion-null -fsyntax-only -verify
void f() {
int* i = __null;
--- clang/test/SemaCXX/conversion-gnunull.cpp.sav 2012-03-13 21:43:22.493164031 +0100
+++ clang/test/SemaCXX/conversion-gnunull.cpp 2012-03-14 06:43:38.901259331 +0100
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-apple-darwin %s
+
+#include <stddef.h>
+
+// This file tests -Wconversion-null, 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; 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}}
+}
--- clang/test/SemaCXX/conversion.cpp.sav 2011-11-06 14:46:06.000000000 +0100
+++ clang/test/SemaCXX/conversion.cpp 2012-03-13 21:43:38.246160011 +0100
@@ -52,12 +52,3 @@ namespace test2 {
A() : x(10) {} // expected-warning {{implicit truncation from 'int' to bitfield changes value from 10 to 2}}
};
}
-
-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}}
- 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}}
-}
--- clang/test/Analysis/nullptr.cpp.sav 2012-03-05 11:41:53.000000000 +0100
+++ clang/test/Analysis/nullptr.cpp 2012-03-14 06:39:49.538259178 +0100
@@ -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) {
--- clang/lib/Driver/Tools.cpp.sav 2012-03-07 10:56:50.000000000 +0100
+++ clang/lib/Driver/Tools.cpp 2012-03-13 21:47:45.876535999 +0100
@@ -3162,6 +3162,7 @@ void darwin::CC1::RemoveCC1UnsupportedAr
.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)
--- clang/include/clang/Basic/DiagnosticGroups.td.sav 2012-03-06 22:13:39.000000000 +0100
+++ clang/include/clang/Basic/DiagnosticGroups.td 2012-03-14 06:20:14.457854359 +0100
@@ -28,6 +28,7 @@ def Availability : DiagGroup<"availabili
def AutoImport : DiagGroup<"auto-import">;
def BoolConversions : DiagGroup<"bool-conversions">;
def IntConversions : DiagGroup<"int-conversions">;
+def ConversionNull : DiagGroup<"conversion-null">;
def BuiltinRequiresHeader : DiagGroup<"builtin-requires-header">;
def CXXCompat: DiagGroup<"c++-compat">;
def CastAlign : DiagGroup<"cast-align">;
@@ -274,6 +275,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">,
@@ -281,7 +283,8 @@ def Conversion : DiagGroup<"conversion",
DiagGroup<"string-conversion">,
DiagGroup<"sign-conversion">,
BoolConversions,
- IntConversions]>,
+ IntConversions,
+ ConversionNull]>,
DiagCategory<"Value Conversion Issue">;
def Unused : DiagGroup<"unused",
@@ -317,6 +320,7 @@ def Extra : DiagGroup<"extra", [
def Most : DiagGroup<"most", [
CharSubscript,
Comment,
+ ConversionNull,
DeleteNonVirtualDtor,
Format,
Implicit,
--- clang/include/clang/Basic/DiagnosticSemaKinds.td.sav 2012-03-06 22:13:39.000000000 +0100
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td 2012-03-14 06:20:38.779861303 +0100
@@ -1728,7 +1728,7 @@ def warn_impcast_bool_to_null_pointer :
"expression">, InGroup<BoolConversions>;
def warn_impcast_null_pointer_to_integer : Warning<
"implicit conversion of NULL constant to integer">,
- InGroup<DiagGroup<"conversion">>, DefaultIgnore;
+ InGroup<ConversionNull>;
def warn_impcast_function_to_bool : Warning<
"address of function %q0 will always evaluate to 'true'">,
InGroup<BoolConversions>;
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits