Skip to content

[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
merged 5 commits into from
May 28, 2024

Conversation

JOE1994
Copy link
Member

@JOE1994 JOE1994 commented May 26, 2024

Fixes #93369

@JOE1994 JOE1994 requested review from Fznamznon and tbaederr May 26, 2024 03:57
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels May 26, 2024
@JOE1994 JOE1994 changed the title [clang][Sema] Don't emit 'declared here' note for builtin functions w… [clang][Sema] Don't emit 'declared here' note for builtin functions with no decl in source May 26, 2024
@llvmbot
Copy link
Member

llvmbot commented May 26, 2024

@llvm/pr-subscribers-clang

Author: Youngsuk Kim (JOE1994)

Changes

Fixes #93369


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

2 Files Affected:

  • (modified) clang/lib/Sema/SemaLookup.cpp (+10)
  • (modified) clang/test/SemaCXX/invalid-if-constexpr.cpp (+1-1)
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}}
 

Co-authored-by: Timm Baeder <[email protected]>
@tbaederr
Copy link
Contributor

Would be nice if you could add new explicit tests for this.

Copy link
Contributor

@Fznamznon Fznamznon left a 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?

@JOE1994 JOE1994 merged commit f089996 into llvm:main May 28, 2024
9 checks passed
@JOE1994 JOE1994 deleted the fix_93369 branch May 28, 2024 18:00
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"did you mean [builtin function]?" diagnostics print a useless declaration site
5 participants