[clang] [clang][Sema] Don't emit 'declared here' note for builtin functions with no decl in source (PR #93394)
Youngsuk Kim via cfe-commits
cfe-commits at lists.llvm.org
Sun May 26 02:53:10 PDT 2024
https://github.com/JOE1994 updated https://github.com/llvm/llvm-project/pull/93394
>From 00c93043fca8f8a1f20634ea1b281c60926bd571 Mon Sep 17 00:00:00 2001
From: Youngsuk Kim <youngsuk.kim at hpe.com>
Date: Sat, 25 May 2024 20:42:43 -0500
Subject: [PATCH 1/2] [clang][Sema] Don't emit 'declared here' note for builtin
functions with no decl in source
Fixes #93369
---
clang/lib/Sema/SemaLookup.cpp | 10 ++++++++++
clang/test/SemaCXX/invalid-if-constexpr.cpp | 2 +-
2 files changed, 11 insertions(+), 1 deletion(-)
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}}
>From 42bbff26459b71e9d77c4d907703930e12db8958 Mon Sep 17 00:00:00 2001
From: Youngsuk Kim <joseph942010 at gmail.com>
Date: Sun, 26 May 2024 05:53:03 -0400
Subject: [PATCH 2/2] Use dyn_cast_if_present
Co-authored-by: Timm Baeder <tbaeder at redhat.com>
---
clang/lib/Sema/SemaLookup.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp
index 348f9e5b8f530..be6ea20a956a3 100644
--- a/clang/lib/Sema/SemaLookup.cpp
+++ b/clang/lib/Sema/SemaLookup.cpp
@@ -5900,7 +5900,7 @@ void Sema::diagnoseTypo(const TypoCorrection &Correction,
// 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);
+ if (const auto *FD = dyn_cast_if_present<FunctionDecl>(ChosenDecl);
FD && FD->getBuiltinID() &&
PrevNote.getDiagID() == diag::note_previous_decl &&
Correction.getCorrectionRange().getBegin() == FD->getBeginLoc()) {
More information about the cfe-commits
mailing list