[clang] Add new flag -Wpointer-integer-ordered-compare (PR #88489)

2024-04-28 Thread via cfe-commits

https://github.com/vincent-mailhol edited 
https://github.com/llvm/llvm-project/pull/88489
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add new flag -Wpointer-integer-ordered-compare (PR #88489)

2024-04-28 Thread via cfe-commits


@@ -245,6 +245,13 @@ 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``.This also resolves false negative

vincent-mailhol wrote:

Nitpick: put a space after the period.
```suggestion
  ``-Wpointer-integer-ordered-compare``. This also resolves false negative
```

https://github.com/llvm/llvm-project/pull/88489
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add new flag -Wpointer-integer-ordered-compare (PR #88489)

2024-04-28 Thread via cfe-commits

https://github.com/vincent-mailhol approved this pull request.

As far as my understanding of the LLVM project goes, this change looks good to 
me. I am not an expert of this project, but regardless and for what it is 
worth, here is my approval (with one nitpick).

https://github.com/llvm/llvm-project/pull/88489
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add new flag -Wpointer-integer-ordered-compare (PR #88489)

2024-04-26 Thread Bhuminjay Soni via cfe-commits

11happy wrote:

Humble ping! 

https://github.com/llvm/llvm-project/pull/88489
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add new flag -Wpointer-integer-ordered-compare (PR #88489)

2024-04-18 Thread Bhuminjay Soni via cfe-commits


@@ -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=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){

11happy wrote:

done

https://github.com/llvm/llvm-project/pull/88489
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add new flag -Wpointer-integer-ordered-compare (PR #88489)

2024-04-18 Thread Bhuminjay Soni via cfe-commits


@@ -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

11happy wrote:

done

https://github.com/llvm/llvm-project/pull/88489
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add new flag -Wpointer-integer-ordered-compare (PR #88489)

2024-04-18 Thread Bhuminjay Soni via cfe-commits


@@ -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">;
-

11happy wrote:

done

https://github.com/llvm/llvm-project/pull/88489
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add new flag -Wpointer-integer-ordered-compare (PR #88489)

2024-04-18 Thread Bhuminjay Soni via cfe-commits

11happy wrote:

humble reminder @AaronBallman , @shafik 

https://github.com/llvm/llvm-project/pull/88489
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add new flag -Wpointer-integer-ordered-compare (PR #88489)

2024-04-18 Thread Bhuminjay Soni via cfe-commits

11happy wrote:

Hello @vincent-mailhol thank you for the review I have made the suggested 
changed.


https://github.com/llvm/llvm-project/pull/88489
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add new flag -Wpointer-integer-ordered-compare (PR #88489)

2024-04-18 Thread Bhuminjay Soni via cfe-commits

https://github.com/11happy updated 
https://github.com/llvm/llvm-project/pull/88489

>From bc08f479ba483e1582304ca103dbd92481108f12 Mon Sep 17 00:00:00 2001
From: 11happy 
Date: Fri, 12 Apr 2024 14:56:42 +0530
Subject: [PATCH 1/3] add new flag -Wpointer-integer-ordered-compare

Signed-off-by: 11happy 
---
 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;
 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;
 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>;
+  InGroup;
 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 

[clang] Add new flag -Wpointer-integer-ordered-compare (PR #88489)

2024-04-13 Thread via cfe-commits


@@ -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

vincent-mailhol wrote:

Maybe add a sentence to say that this also resolves a false negative for 
comparison between pointers and literal zero.

https://github.com/llvm/llvm-project/pull/88489
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add new flag -Wpointer-integer-ordered-compare (PR #88489)

2024-04-13 Thread via cfe-commits

https://github.com/vincent-mailhol commented:

Thanks for taking care of the issue I created.

For what it is worth, here is my review. I am not a contributor of the llvm 
project, so I only left superficial nitpicks.

https://github.com/llvm/llvm-project/pull/88489
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add new flag -Wpointer-integer-ordered-compare (PR #88489)

2024-04-13 Thread via cfe-commits


@@ -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">;
-

vincent-mailhol wrote:

Nitpick: this line removal is not related to the commit.
```suggestion
```

https://github.com/llvm/llvm-project/pull/88489
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add new flag -Wpointer-integer-ordered-compare (PR #88489)

2024-04-13 Thread via cfe-commits


@@ -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=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){

vincent-mailhol wrote:

Nitpick: add newline between functions
```suggestion
}

int test5(int *a){
```

https://github.com/llvm/llvm-project/pull/88489
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add new flag -Wpointer-integer-ordered-compare (PR #88489)

2024-04-13 Thread via cfe-commits

https://github.com/vincent-mailhol edited 
https://github.com/llvm/llvm-project/pull/88489
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add new flag -Wpointer-integer-ordered-compare (PR #88489)

2024-04-12 Thread Bhuminjay Soni via cfe-commits

https://github.com/11happy updated 
https://github.com/llvm/llvm-project/pull/88489

>From bc08f479ba483e1582304ca103dbd92481108f12 Mon Sep 17 00:00:00 2001
From: 11happy 
Date: Fri, 12 Apr 2024 14:56:42 +0530
Subject: [PATCH 1/2] add new flag -Wpointer-integer-ordered-compare

Signed-off-by: 11happy 
---
 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;
 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;
 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>;
+  InGroup;
 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 

[clang] Add new flag -Wpointer-integer-ordered-compare (PR #88489)

2024-04-12 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Bhuminjay Soni (11happy)


Changes

**Overview:**
This pull request fixes #88090 where a false negative issue related to 
`-Wpointer-integer-compare` failing on comparison between a pointer and zero.

**Testing:**
- Tested the updated code.
- Verified that other functionalities remain unaffected.

**Dependencies:**
- No dependencies on other pull requests.

**CC:**
- @AaronBallman , @shafik 



---
Full diff: https://github.com/llvm/llvm-project/pull/88489.diff


5 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+6) 
- (modified) clang/include/clang/Basic/DiagnosticGroups.td (+2-1) 
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+5-3) 
- (modified) clang/test/Misc/warning-flags.c (+2-3) 
- (added) clang/test/Sema/compare_pointers.c (+30) 


``diff
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;
 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;
 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>;
+  InGroup;
 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 

[clang] Add new flag -Wpointer-integer-ordered-compare (PR #88489)

2024-04-12 Thread Bhuminjay Soni via cfe-commits

https://github.com/11happy created 
https://github.com/llvm/llvm-project/pull/88489

**Overview:**
This pull request fixes #88090 where a false negative issue related to 
`-Wpointer-integer-compare` failing on comparison between a pointer and zero.

**Testing:**
- Tested the updated code.
- Verified that other functionalities remain unaffected.

**Dependencies:**
- No dependencies on other pull requests.

**CC:**
- @AaronBallman , @shafik 



>From bc08f479ba483e1582304ca103dbd92481108f12 Mon Sep 17 00:00:00 2001
From: 11happy 
Date: Fri, 12 Apr 2024 14:56:42 +0530
Subject: [PATCH] add new flag -Wpointer-integer-ordered-compare

Signed-off-by: 11happy 
---
 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;
 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;
 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>;
+  InGroup;
 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: