diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 93318871fa9f6e..df7f907a6d183a 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -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 + for comparison between pointers and literal zero. Fixes #GH88090 + Removed Compiler Flags ------------------------- diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td index 47747d8704b6c8..cba3362a47370f 100644 --- a/clang/include/clang/Basic/DiagnosticGroups.td +++ b/clang/include/clang/Basic/DiagnosticGroups.td @@ -714,6 +714,8 @@ 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">; 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 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..6d58352e97e9f7 --- /dev/null +++ b/clang/test/Sema/compare_pointers.c @@ -0,0 +1,27 @@ +// 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){ + int zero = 0; + return a>=zero; // pointer-integer-ordered-warning{{ordered comparison between pointer and integer ('int *' and 'int')}} +}