[clang] Add new flag -Wpointer-integer-ordered-compare (PR #88489)
Bhuminjay Soni via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 12 02:34:05 PDT 2024
https://github.com/11happy updated https://github.com/llvm/llvm-project/pull/88489
>From bc08f479ba483e1582304ca103dbd92481108f12 Mon Sep 17 00:00:00 2001
From: 11happy <soni5happy at gmail.com>
Date: Fri, 12 Apr 2024 14:56:42 +0530
Subject: [PATCH 1/2] add new flag -Wpointer-integer-ordered-compare
Signed-off-by: 11happy <soni5happy at gmail.com>
---
clang/docs/ReleaseNotes.rst | 6 ++++
clang/include/clang/Basic/DiagnosticGroups.td | 3 +-
.../clang/Basic/DiagnosticSemaKinds.td | 8 +++--
clang/test/Misc/warning-flags.c | 5 ++--
clang/test/Sema/compare_pointers.c | 30 +++++++++++++++++++
5 files changed, 45 insertions(+), 7 deletions(-)
create mode 100644 clang/test/Sema/compare_pointers.c
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 93318871fa9f6e..e205088c5cd440 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -245,6 +245,12 @@ Modified Compiler Flags
f3 *c = (f3 *)x;
}
+- Added a new diagnostic flag ``-Wpointer-integer-ordered-compare`` which is
+ grouped under ``-Wpointer-integer-compare`` and moved previously
+ ungrouped diagnostics ``ext_typecheck_ordered_comparison_of_pointer_integer``,
+ ``ext_typecheck_ordered_comparison_of_pointer_and_zero`` under
+ ``-Wpointer-integer-ordered-compare``. Fixes #GH88090
+
Removed Compiler Flags
-------------------------
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td
index 47747d8704b6c8..2cf56574650839 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -714,10 +714,11 @@ def HeaderHygiene : DiagGroup<"header-hygiene">;
def DuplicateDeclSpecifier : DiagGroup<"duplicate-decl-specifier">;
def CompareDistinctPointerType : DiagGroup<"compare-distinct-pointer-types">;
def GNUUnionCast : DiagGroup<"gnu-union-cast">;
+def PointerIntegerOrderedCompare : DiagGroup<"pointer-integer-ordered-compare">;
+def PointerIntegerCompare : DiagGroup<"pointer-integer-compare",[PointerIntegerOrderedCompare]>;
def GNUVariableSizedTypeNotAtEnd : DiagGroup<"gnu-variable-sized-type-not-at-end">;
def Varargs : DiagGroup<"varargs">;
def XorUsedAsPow : DiagGroup<"xor-used-as-pow">;
-
def Unsequenced : DiagGroup<"unsequenced">;
// GCC name for -Wunsequenced
def : DiagGroup<"sequence-point", [Unsequenced]>;
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 180e913155d67c..a5632a3f6f61da 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -7272,9 +7272,11 @@ def err_typecheck_sub_ptr_compatible : Error<
"%diff{$ and $ are not pointers to compatible types|"
"pointers to incompatible types}0,1">;
def ext_typecheck_ordered_comparison_of_pointer_integer : ExtWarn<
- "ordered comparison between pointer and integer (%0 and %1)">;
+ "ordered comparison between pointer and integer (%0 and %1)">,
+ InGroup<PointerIntegerOrderedCompare>;
def ext_typecheck_ordered_comparison_of_pointer_and_zero : Extension<
- "ordered comparison between pointer and zero (%0 and %1) is an extension">;
+ "ordered comparison between pointer and zero (%0 and %1) is an extension">,
+ InGroup<PointerIntegerOrderedCompare>;
def err_typecheck_ordered_comparison_of_pointer_and_zero : Error<
"ordered comparison between pointer and zero (%0 and %1)">;
def err_typecheck_three_way_comparison_of_pointer_and_zero : Error<
@@ -7299,7 +7301,7 @@ 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)">,
- InGroup<DiagGroup<"pointer-integer-compare">>;
+ InGroup<PointerIntegerCompare>;
def err_typecheck_comparison_of_pointer_integer : Error<
"comparison between pointer and integer (%0 and %1)">;
def ext_typecheck_comparison_of_distinct_pointers : ExtWarn<
diff --git a/clang/test/Misc/warning-flags.c b/clang/test/Misc/warning-flags.c
index dd73331913c6f6..8c0e151613bd82 100644
--- a/clang/test/Misc/warning-flags.c
+++ b/clang/test/Misc/warning-flags.c
@@ -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 (66):
+CHECK: Warnings without flags (65):
CHECK-NEXT: ext_expected_semi_decl_list
CHECK-NEXT: ext_explicit_specialization_storage_class
@@ -28,7 +28,6 @@ CHECK-NEXT: ext_plain_complex
CHECK-NEXT: ext_template_arg_extra_parens
CHECK-NEXT: ext_template_spec_extra_headers
CHECK-NEXT: ext_typecheck_cond_incompatible_operands
-CHECK-NEXT: ext_typecheck_ordered_comparison_of_pointer_integer
CHECK-NEXT: ext_using_undefined_std
CHECK-NEXT: pp_invalid_string_literal
CHECK-NEXT: pp_out_of_date_dependency
@@ -89,4 +88,4 @@ CHECK-NEXT: warn_weak_import
The list of warnings in -Wpedantic should NEVER grow.
-CHECK: Number in -Wpedantic (not covered by other -W flags): 26
+CHECK: Number in -Wpedantic (not covered by other -W flags): 25
diff --git a/clang/test/Sema/compare_pointers.c b/clang/test/Sema/compare_pointers.c
new file mode 100644
index 00000000000000..07592ea17a3193
--- /dev/null
+++ b/clang/test/Sema/compare_pointers.c
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 -Wno-pointer-integer-compare -Wpointer-integer-ordered-compare -fsyntax-only -verify=pointer-integer-ordered %s
+// RUN: %clang_cc1 -Wpointer-integer-compare -Wno-pointer-integer-ordered-compare -fsyntax-only -verify=pointer-integer %s
+
+void test1(int *a){
+ int b = 1;
+ short c = 1;
+ if(c<a) {}; // pointer-integer-ordered-warning{{ordered comparison between pointer and integer ('short' and 'int *')}}
+ if(a!=b) {}; // pointer-integer-warning{{comparison between pointer and integer ('int *' and 'int')}}
+ if(a == b) {}; // pointer-integer-warning{{comparison between pointer and integer ('int *' and 'int')}}
+}
+
+int test2(int *a){
+ return a>=0; // pointer-integer-ordered-warning{{ordered comparison between pointer and zero ('int *' and 'int') is an extension}}
+}
+
+int test3(int *a){
+ return a>=1; // pointer-integer-ordered-warning{{ordered comparison between pointer and integer ('int *' and 'int')}}
+}
+
+int test4(int *a){
+ return a>1; // pointer-integer-ordered-warning{{ordered comparison between pointer and integer ('int *' and 'int')}}
+}
+int test5(int *a){
+ int zero = 0;
+ return a>=zero; // pointer-integer-ordered-warning{{ordered comparison between pointer and integer ('int *' and 'int')}}
+}
+
+
+
+
>From d364a86357fbdc90921cbe3d5a777f30da14d33d Mon Sep 17 00:00:00 2001
From: 11happy <soni5happy at gmail.com>
Date: Fri, 12 Apr 2024 15:03:51 +0530
Subject: [PATCH 2/2] remove whitespace
Signed-off-by: 11happy <soni5happy at gmail.com>
---
clang/test/Sema/compare_pointers.c | 4 ----
1 file changed, 4 deletions(-)
diff --git a/clang/test/Sema/compare_pointers.c b/clang/test/Sema/compare_pointers.c
index 07592ea17a3193..426dcde2b8e9f6 100644
--- a/clang/test/Sema/compare_pointers.c
+++ b/clang/test/Sema/compare_pointers.c
@@ -24,7 +24,3 @@ int test5(int *a){
int zero = 0;
return a>=zero; // pointer-integer-ordered-warning{{ordered comparison between pointer and integer ('int *' and 'int')}}
}
-
-
-
-
More information about the cfe-commits
mailing list