-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang][Sema] Don't emit 'declared here' note for builtin functions with no decl in source #93394
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
Conversation
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
…ith no decl in source Fixes llvm#93369
@llvm/pr-subscribers-clang Author: Youngsuk Kim (JOE1994) ChangesFixes #93369 Full diff: https://github.com/llvm/llvm-project/pull/93394.diff 2 Files Affected:
diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp
index ef0a655b631ab..348f9e5b8f530 100644
--- a/clang/lib/Sema/SemaLookup.cpp
+++ b/clang/lib/Sema/SemaLookup.cpp
@@ -5897,6 +5897,16 @@ void Sema::diagnoseTypo(const TypoCorrection &Correction,
NamedDecl *ChosenDecl =
Correction.isKeyword() ? nullptr : Correction.getFoundDecl();
+
+ // For builtin functions which aren't declared anywhere in source,
+ // don't emit the "declared here" note.
+ if (auto *FD = dyn_cast_or_null<FunctionDecl>(ChosenDecl);
+ FD && FD->getBuiltinID() &&
+ PrevNote.getDiagID() == diag::note_previous_decl &&
+ Correction.getCorrectionRange().getBegin() == FD->getBeginLoc()) {
+ ChosenDecl = nullptr;
+ }
+
if (PrevNote.getDiagID() && ChosenDecl)
Diag(ChosenDecl->getLocation(), PrevNote)
<< CorrectedQuotedStr << (ErrorRecovery ? FixItHint() : FixTypo);
diff --git a/clang/test/SemaCXX/invalid-if-constexpr.cpp b/clang/test/SemaCXX/invalid-if-constexpr.cpp
index 7643c47488f05..16d422880e8a9 100644
--- a/clang/test/SemaCXX/invalid-if-constexpr.cpp
+++ b/clang/test/SemaCXX/invalid-if-constexpr.cpp
@@ -5,7 +5,7 @@ void similar() { // expected-note {{'similar' declared here}}
if constexpr (similer<>) {} // expected-error {{use of undeclared identifier 'similer'; did you mean 'similar'?}}
}
void a() { if constexpr (__adl_swap<>) {}} // expected-error{{use of undeclared identifier '__adl_swap'; did you mean '__sync_swap'?}} \
- // expected-note {{'__sync_swap' declared here}}
+ // not-expected-note {{'__sync_swap' declared here}}
int AA() { return true;} // expected-note {{'AA' declared here}}
|
tbaederr
reviewed
May 26, 2024
Co-authored-by: Timm Baeder <[email protected]>
Would be nice if you could add new explicit tests for this. |
tbaederr
reviewed
May 26, 2024
Fznamznon
reviewed
May 27, 2024
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.
Could you please add a release note?
cpplearner
reviewed
May 28, 2024
Co-authored-by: S. B. Tam <[email protected]>
vg0204
pushed a commit
to vg0204/llvm-project
that referenced
this pull request
May 29, 2024
…ith no decl in source (llvm#93394) Fixes llvm#93369 --------- Co-authored-by: Timm Baeder <[email protected]> Co-authored-by: S. B. Tam <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
clang:frontend
Language frontend issues, e.g. anything involving "Sema"
clang
Clang issues not falling into any other category
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.
Fixes #93369