-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[Clang] Add '-Warray-compare' flag for C++ below version 20 #118031
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
AmrDeveloper
merged 13 commits into
llvm:main
from
AmrDeveloper:clang_wran_array_compare
Dec 4, 2024
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
9451a1e
Add support for '-Warray-compare' compiler flag
AmrDeveloper 6de4cba
Add lit test for array-comparison
AmrDeveloper fe4fab8
Add test file to handle warn array comparion cases
AmrDeveloper bece937
Update comment to add warning case in C++1a versions
AmrDeveloper ef7485c
Update Test file to expect warning in C++ mode
AmrDeveloper b2034a4
Update Cpp array compare warnings
AmrDeveloper 49730e1
Inline diagnostic group | Remove unneeded variable
AmrDeveloper 80ecba0
Update Diagnostic message for array comparion
AmrDeveloper b98e0f8
Merge branch 'llvm:main' into clang_wran_array_compare
AmrDeveloper 55e3489
Inline diagnostic group
AmrDeveloper cc67aa8
Update the release note
AmrDeveloper d3ff02d
Fix releasenote indentation
AmrDeveloper 3636a8f
Remove inlined Diagnostic group
AmrDeveloper File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| // RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify %s -verify=expected,not-cxx20 | ||
| // RUN: %clang_cc1 -std=c++20 -fsyntax-only -Wno-deprecated-array-compare -verify %s -verify=expected,not-cxx20 | ||
| // RUN: %clang_cc1 -std=c++20 -fsyntax-only -Wdeprecated -verify %s -verify=expected,cxx20 | ||
|
|
||
| typedef struct { | ||
| char str[16]; | ||
| int id[16]; | ||
| } Object; | ||
|
|
||
| bool object_equal(const Object &obj1, const Object &obj2) { | ||
| if (obj1.str != obj2.str) // not-cxx20-warning {{comparison between two arrays compare their addresses}} cxx20-warning {{comparison between two arrays is deprecated}} | ||
| return false; | ||
| if (obj1.id != obj2.id) // not-cxx20-warning {{comparison between two arrays compare their addresses}} cxx20-warning {{comparison between two arrays is deprecated}} | ||
| return false; | ||
| return true; | ||
| } | ||
|
|
||
|
|
||
| void foo(int (&array1)[2], int (&array2)[2]) { | ||
| if (array1 == array2) { } // not-cxx20-warning {{comparison between two arrays compare their addresses}} cxx20-warning {{comparison between two arrays is deprecated}} | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| // RUN: %clang_cc1 -fsyntax-only -verify %s | ||
| // expected-no-diagnostics | ||
| // RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify %s -verify=expected,not-cxx20 | ||
| // RUN: %clang_cc1 -std=c++20 -fsyntax-only -Wdeprecated -verify %s -verify=expected,cxx20 | ||
|
|
||
| void f(int (&array1)[2], int (&array2)[2]) { | ||
| if (array1 == array2) { } // no warning | ||
| if (array1 == array2) { } // not-cxx20-warning {{comparison between two arrays compare their addresses}} cxx20-warning {{comparison between two arrays is deprecated}} | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to overlap w/
warn_stringcomparewe probably want to do some special handling here since string literals are a special case of arrays and they have their own comparison functions.We can do this as part of the C++26 feature implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CC @erichkeane
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oooh, thats a great concern! I think you're right, but I think as well that it is ok to do in the followup