Skip to content

Commit

Permalink
[clang][Sema] Don't emit 'declared here' note for builtin functions w…
Browse files Browse the repository at this point in the history
…ith no decl in source (#93394)

Fixes #93369

---------

Co-authored-by: Timm Baeder <tbaeder@redhat.com>
Co-authored-by: S. B. Tam <cpplearner@outlook.com>
  • Loading branch information
3 people authored May 28, 2024
1 parent 0b2094c commit f089996
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
3 changes: 3 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,9 @@ Improvements to Clang's diagnostics
- Clang emits a ``-Wparentheses`` warning for expressions with consecutive comparisons like ``x < y < z``.
Fixes #GH20456.

- Clang no longer emits a "declared here" note for a builtin function that has no declaration in source.
Fixes #GH93369.

Improvements to Clang's time-trace
----------------------------------

Expand Down
10 changes: 10 additions & 0 deletions clang/lib/Sema/SemaLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 (const auto *FD = dyn_cast_if_present<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);
Expand Down
3 changes: 1 addition & 2 deletions clang/test/SemaCXX/invalid-if-constexpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ namespace GH61885 {
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}}
void a() { if constexpr (__adl_swap<>) {}} // expected-error{{use of undeclared identifier '__adl_swap'; did you mean '__sync_swap'?}}

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

Expand Down
8 changes: 8 additions & 0 deletions clang/test/SemaCXX/typo-correction-builtin-func.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// RUN: %clang_cc1 -fsyntax-only -verify %s

// Test that clang does not emit 'declared here' note for builtin functions that don't have a declaration in source.

void t0() {
constexpr float A = __builtin_isinfinity(); // expected-error {{use of undeclared identifier '__builtin_isinfinity'; did you mean '__builtin_isfinite'?}}
// expected-error@-1 {{too few arguments to function call, expected 1, have 0}}
}

0 comments on commit f089996

Please sign in to comment.