]> granicus.if.org Git - clang/commitdiff
[Sema] Expose a control flag for integer to pointer ext warning
authorKristina Brooks <kristina@nym.hush.com>
Mon, 14 Jan 2019 18:16:51 +0000 (18:16 +0000)
committerKristina Brooks <kristina@nym.hush.com>
Mon, 14 Jan 2019 18:16:51 +0000 (18:16 +0000)
While building openJDK11u, it seems that some of the code in the
native core libraries make liberal use of integer to pointer
comparisons. We currently have no flag to disabled this warning.
This add such a flag.

Patch by Kader (abdoul-kader keita)

Differential Revision: https://reviews.llvm.org/D56241

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

include/clang/Basic/DiagnosticSemaKinds.td
test/Misc/warning-flags.c
test/Sema/ext-typecheck-comparison-of-pointer-integer.c [new file with mode: 0644]

index 57c3abd048997c71851f6e41ce9c7b31cce8ea5a..78ecc8784ad8d3bb722b6515a797ead169a6068d 100644 (file)
@@ -5875,7 +5875,8 @@ def ext_typecheck_comparison_of_fptr_to_void : Extension<
 def err_typecheck_comparison_of_fptr_to_void : Error<
   "equality comparison between function pointer and void pointer (%0 and %1)">;
 def ext_typecheck_comparison_of_pointer_integer : ExtWarn<
-  "comparison between pointer and integer (%0 and %1)">;
+  "comparison between pointer and integer (%0 and %1)">,
+  InGroup<DiagGroup<"pointer-integer-compare">>;
 def err_typecheck_comparison_of_pointer_integer : Error<
   "comparison between pointer and integer (%0 and %1)">;
 def ext_typecheck_comparison_of_distinct_pointers : ExtWarn<
index b7867591039eb52901a814c5ce5f355b9fbf2e58..05172b220859679fa6e09cc7cc78be3937f88c5b 100644 (file)
@@ -18,7 +18,7 @@ This test serves two purposes:
 
 The list of warnings below should NEVER grow.  It should gradually shrink to 0.
 
-CHECK: Warnings without flags (75):
+CHECK: Warnings without flags (74):
 CHECK-NEXT:   ext_excess_initializers
 CHECK-NEXT:   ext_excess_initializers_in_char_array_initializer
 CHECK-NEXT:   ext_expected_semi_decl_list
@@ -29,7 +29,6 @@ CHECK-NEXT:   ext_missing_whitespace_after_macro_name
 CHECK-NEXT:   ext_new_paren_array_nonconst
 CHECK-NEXT:   ext_plain_complex
 CHECK-NEXT:   ext_template_arg_extra_parens
-CHECK-NEXT:   ext_typecheck_comparison_of_pointer_integer
 CHECK-NEXT:   ext_typecheck_cond_incompatible_operands
 CHECK-NEXT:   ext_typecheck_ordered_comparison_of_pointer_integer
 CHECK-NEXT:   ext_using_undefined_std
diff --git a/test/Sema/ext-typecheck-comparison-of-pointer-integer.c b/test/Sema/ext-typecheck-comparison-of-pointer-integer.c
new file mode 100644 (file)
index 0000000..b928156
--- /dev/null
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only  -verify -DEXPECTWARNING %s 
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only  -verify -Wno-pointer-integer-compare %s 
+
+#ifdef EXPECTWARNING
+// expected-warning@+6 {{comparison between pointer and integer ('int' and 'int *')}}
+#else
+// expected-no-diagnostics 
+#endif
+
+int test_ext_typecheck_comparison_of_pointer_integer(int integer, int * pointer) {
+       return integer != pointer; 
+}