Skip to content

Commit f089996

Browse files
JOE1994tbaederrcpplearner
authored
[clang][Sema] Don't emit 'declared here' note for builtin functions with no decl in source (#93394)
Fixes #93369 --------- Co-authored-by: Timm Baeder <[email protected]> Co-authored-by: S. B. Tam <[email protected]>
1 parent 0b2094c commit f089996

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,9 @@ Improvements to Clang's diagnostics
541541
- Clang emits a ``-Wparentheses`` warning for expressions with consecutive comparisons like ``x < y < z``.
542542
Fixes #GH20456.
543543

544+
- Clang no longer emits a "declared here" note for a builtin function that has no declaration in source.
545+
Fixes #GH93369.
546+
544547
Improvements to Clang's time-trace
545548
----------------------------------
546549

clang/lib/Sema/SemaLookup.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5897,6 +5897,16 @@ void Sema::diagnoseTypo(const TypoCorrection &Correction,
58975897

58985898
NamedDecl *ChosenDecl =
58995899
Correction.isKeyword() ? nullptr : Correction.getFoundDecl();
5900+
5901+
// For builtin functions which aren't declared anywhere in source,
5902+
// don't emit the "declared here" note.
5903+
if (const auto *FD = dyn_cast_if_present<FunctionDecl>(ChosenDecl);
5904+
FD && FD->getBuiltinID() &&
5905+
PrevNote.getDiagID() == diag::note_previous_decl &&
5906+
Correction.getCorrectionRange().getBegin() == FD->getBeginLoc()) {
5907+
ChosenDecl = nullptr;
5908+
}
5909+
59005910
if (PrevNote.getDiagID() && ChosenDecl)
59015911
Diag(ChosenDecl->getLocation(), PrevNote)
59025912
<< CorrectedQuotedStr << (ErrorRecovery ? FixItHint() : FixTypo);

clang/test/SemaCXX/invalid-if-constexpr.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ namespace GH61885 {
44
void similar() { // expected-note {{'similar' declared here}}
55
if constexpr (similer<>) {} // expected-error {{use of undeclared identifier 'similer'; did you mean 'similar'?}}
66
}
7-
void a() { if constexpr (__adl_swap<>) {}} // expected-error{{use of undeclared identifier '__adl_swap'; did you mean '__sync_swap'?}} \
8-
// expected-note {{'__sync_swap' declared here}}
7+
void a() { if constexpr (__adl_swap<>) {}} // expected-error{{use of undeclared identifier '__adl_swap'; did you mean '__sync_swap'?}}
98

109
int AA() { return true;} // expected-note {{'AA' declared here}}
1110

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// RUN: %clang_cc1 -fsyntax-only -verify %s
2+
3+
// Test that clang does not emit 'declared here' note for builtin functions that don't have a declaration in source.
4+
5+
void t0() {
6+
constexpr float A = __builtin_isinfinity(); // expected-error {{use of undeclared identifier '__builtin_isinfinity'; did you mean '__builtin_isfinite'?}}
7+
// expected-error@-1 {{too few arguments to function call, expected 1, have 0}}
8+
}

0 commit comments

Comments
 (0)