[clang] [clang][Sema] Don't emit 'declared here' note for builtin functions with no decl in source (PR #93394)

2024-05-28 Thread Youngsuk Kim via cfe-commits

https://github.com/JOE1994 closed 
https://github.com/llvm/llvm-project/pull/93394
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Sema] Don't emit 'declared here' note for builtin functions with no decl in source (PR #93394)

2024-05-28 Thread Youngsuk Kim via cfe-commits

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 
Date: Sat, 25 May 2024 20:42:43 -0500
Subject: [PATCH 1/5] [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 ,
 
   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(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 
Date: Sun, 26 May 2024 05:53:03 -0400
Subject: [PATCH 2/5] Use dyn_cast_if_present

Co-authored-by: Timm Baeder 
---
 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 ,
 
   // For builtin functions which aren't declared anywhere in source,
   // don't emit the "declared here" note.
-  if (auto *FD = dyn_cast_or_null(ChosenDecl);
+  if (const auto *FD = dyn_cast_if_present(ChosenDecl);
   FD && FD->getBuiltinID() &&
   PrevNote.getDiagID() == diag::note_previous_decl &&
   Correction.getCorrectionRange().getBegin() == FD->getBeginLoc()) {

>From e4f190be4f59dec78c8a184d9603ac8856da3900 Mon Sep 17 00:00:00 2001
From: Youngsuk Kim 
Date: Sun, 26 May 2024 10:28:02 -0500
Subject: [PATCH 3/5] Add dedicated test

---
 clang/test/SemaCXX/invalid-if-constexpr.cpp | 1 -
 clang/test/SemaCXX/typo-correction-builtin-func.cpp | 8 
 2 files changed, 8 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaCXX/typo-correction-builtin-func.cpp

diff --git a/clang/test/SemaCXX/invalid-if-constexpr.cpp 
b/clang/test/SemaCXX/invalid-if-constexpr.cpp
index 16d422880e8a9..1fe0bc3415c84 100644
--- a/clang/test/SemaCXX/invalid-if-constexpr.cpp
+++ b/clang/test/SemaCXX/invalid-if-constexpr.cpp
@@ -5,7 +5,6 @@ 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'?}} \
-   // not-expected-note 
{{'__sync_swap' declared here}}
 
 int AA() { return true;} // expected-note {{'AA' declared here}}
 
diff --git a/clang/test/SemaCXX/typo-correction-builtin-func.cpp 
b/clang/test/SemaCXX/typo-correction-builtin-func.cpp
new file mode 100644
index 0..8d369034d1be3
--- /dev/null
+++ b/clang/test/SemaCXX/typo-correction-builtin-func.cpp
@@ -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'?}}
+  

[clang] [clang][Sema] Don't emit 'declared here' note for builtin functions with no decl in source (PR #93394)

2024-05-28 Thread S. B. Tam via cfe-commits


@@ -5,7 +5,6 @@ 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'?}} \

cpplearner wrote:

```suggestion
void a() { if constexpr (__adl_swap<>) {}} // expected-error{{use of undeclared 
identifier '__adl_swap'; did you mean '__sync_swap'?}}
```

https://github.com/llvm/llvm-project/pull/93394
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Sema] Don't emit 'declared here' note for builtin functions with no decl in source (PR #93394)

2024-05-27 Thread Youngsuk Kim via cfe-commits

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 
Date: Sat, 25 May 2024 20:42:43 -0500
Subject: [PATCH 1/4] [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 ,
 
   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(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 
Date: Sun, 26 May 2024 05:53:03 -0400
Subject: [PATCH 2/4] Use dyn_cast_if_present

Co-authored-by: Timm Baeder 
---
 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 ,
 
   // For builtin functions which aren't declared anywhere in source,
   // don't emit the "declared here" note.
-  if (auto *FD = dyn_cast_or_null(ChosenDecl);
+  if (const auto *FD = dyn_cast_if_present(ChosenDecl);
   FD && FD->getBuiltinID() &&
   PrevNote.getDiagID() == diag::note_previous_decl &&
   Correction.getCorrectionRange().getBegin() == FD->getBeginLoc()) {

>From e4f190be4f59dec78c8a184d9603ac8856da3900 Mon Sep 17 00:00:00 2001
From: Youngsuk Kim 
Date: Sun, 26 May 2024 10:28:02 -0500
Subject: [PATCH 3/4] Add dedicated test

---
 clang/test/SemaCXX/invalid-if-constexpr.cpp | 1 -
 clang/test/SemaCXX/typo-correction-builtin-func.cpp | 8 
 2 files changed, 8 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaCXX/typo-correction-builtin-func.cpp

diff --git a/clang/test/SemaCXX/invalid-if-constexpr.cpp 
b/clang/test/SemaCXX/invalid-if-constexpr.cpp
index 16d422880e8a9..1fe0bc3415c84 100644
--- a/clang/test/SemaCXX/invalid-if-constexpr.cpp
+++ b/clang/test/SemaCXX/invalid-if-constexpr.cpp
@@ -5,7 +5,6 @@ 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'?}} \
-   // not-expected-note 
{{'__sync_swap' declared here}}
 
 int AA() { return true;} // expected-note {{'AA' declared here}}
 
diff --git a/clang/test/SemaCXX/typo-correction-builtin-func.cpp 
b/clang/test/SemaCXX/typo-correction-builtin-func.cpp
new file mode 100644
index 0..8d369034d1be3
--- /dev/null
+++ b/clang/test/SemaCXX/typo-correction-builtin-func.cpp
@@ -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'?}}
+  

[clang] [clang][Sema] Don't emit 'declared here' note for builtin functions with no decl in source (PR #93394)

2024-05-27 Thread Youngsuk Kim via cfe-commits


@@ -5897,6 +5897,16 @@ void Sema::diagnoseTypo(const TypoCorrection ,
 
   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(ChosenDecl);
+  FD && FD->getBuiltinID() &&
+  PrevNote.getDiagID() == diag::note_previous_decl &&
+  Correction.getCorrectionRange().getBegin() == FD->getBeginLoc()) {

JOE1994 wrote:

This location checking was motivated by test failure of `Clang :: 
Sema/implicit-decl.c`.

https://github.com/llvm/llvm-project/blob/8760d4ba4cb12d5cac2469f26cd09a2b3acd3c50/clang/test/Sema/implicit-decl.c#L13

I added this check to let Clang emit a **"declared here"** note for a "builtin" 
function (one with non-zero BuiltinID) that has an explicit declaration.

https://github.com/llvm/llvm-project/pull/93394
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Sema] Don't emit 'declared here' note for builtin functions with no decl in source (PR #93394)

2024-05-27 Thread Mariya Podchishchaeva via cfe-commits

https://github.com/Fznamznon commented:

Could you please add a release note?

https://github.com/llvm/llvm-project/pull/93394
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Sema] Don't emit 'declared here' note for builtin functions with no decl in source (PR #93394)

2024-05-27 Thread Mariya Podchishchaeva via cfe-commits


@@ -5897,6 +5897,16 @@ void Sema::diagnoseTypo(const TypoCorrection ,
 
   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(ChosenDecl);
+  FD && FD->getBuiltinID() &&
+  PrevNote.getDiagID() == diag::note_previous_decl &&
+  Correction.getCorrectionRange().getBegin() == FD->getBeginLoc()) {

Fznamznon wrote:

I wonder if checking location is necessary at all?

https://github.com/llvm/llvm-project/pull/93394
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Sema] Don't emit 'declared here' note for builtin functions with no decl in source (PR #93394)

2024-05-27 Thread Mariya Podchishchaeva via cfe-commits

https://github.com/Fznamznon edited 
https://github.com/llvm/llvm-project/pull/93394
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Sema] Don't emit 'declared here' note for builtin functions with no decl in source (PR #93394)

2024-05-26 Thread Youngsuk Kim via cfe-commits


@@ -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}}

JOE1994 wrote:

You are right!

https://github.com/llvm/llvm-project/pull/93394
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Sema] Don't emit 'declared here' note for builtin functions with no decl in source (PR #93394)

2024-05-26 Thread Youngsuk Kim via cfe-commits

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 
Date: Sat, 25 May 2024 20:42:43 -0500
Subject: [PATCH 1/3] [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 ,
 
   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(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 
Date: Sun, 26 May 2024 05:53:03 -0400
Subject: [PATCH 2/3] Use dyn_cast_if_present

Co-authored-by: Timm Baeder 
---
 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 ,
 
   // For builtin functions which aren't declared anywhere in source,
   // don't emit the "declared here" note.
-  if (auto *FD = dyn_cast_or_null(ChosenDecl);
+  if (const auto *FD = dyn_cast_if_present(ChosenDecl);
   FD && FD->getBuiltinID() &&
   PrevNote.getDiagID() == diag::note_previous_decl &&
   Correction.getCorrectionRange().getBegin() == FD->getBeginLoc()) {

>From e4f190be4f59dec78c8a184d9603ac8856da3900 Mon Sep 17 00:00:00 2001
From: Youngsuk Kim 
Date: Sun, 26 May 2024 10:28:02 -0500
Subject: [PATCH 3/3] Add dedicated test

---
 clang/test/SemaCXX/invalid-if-constexpr.cpp | 1 -
 clang/test/SemaCXX/typo-correction-builtin-func.cpp | 8 
 2 files changed, 8 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaCXX/typo-correction-builtin-func.cpp

diff --git a/clang/test/SemaCXX/invalid-if-constexpr.cpp 
b/clang/test/SemaCXX/invalid-if-constexpr.cpp
index 16d422880e8a9..1fe0bc3415c84 100644
--- a/clang/test/SemaCXX/invalid-if-constexpr.cpp
+++ b/clang/test/SemaCXX/invalid-if-constexpr.cpp
@@ -5,7 +5,6 @@ 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'?}} \
-   // not-expected-note 
{{'__sync_swap' declared here}}
 
 int AA() { return true;} // expected-note {{'AA' declared here}}
 
diff --git a/clang/test/SemaCXX/typo-correction-builtin-func.cpp 
b/clang/test/SemaCXX/typo-correction-builtin-func.cpp
new file mode 100644
index 0..8d369034d1be3
--- /dev/null
+++ b/clang/test/SemaCXX/typo-correction-builtin-func.cpp
@@ -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'?}}
+  

[clang] [clang][Sema] Don't emit 'declared here' note for builtin functions with no decl in source (PR #93394)

2024-05-26 Thread Timm Baeder via cfe-commits


@@ -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}}

tbaederr wrote:

I don't think the `not-` prefix actually does anything with `-verify`, does it?

https://github.com/llvm/llvm-project/pull/93394
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Sema] Don't emit 'declared here' note for builtin functions with no decl in source (PR #93394)

2024-05-26 Thread Timm Baeder via cfe-commits

tbaederr wrote:

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

https://github.com/llvm/llvm-project/pull/93394
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Sema] Don't emit 'declared here' note for builtin functions with no decl in source (PR #93394)

2024-05-26 Thread Youngsuk Kim via cfe-commits

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 
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 ,
 
   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(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 
Date: Sun, 26 May 2024 05:53:03 -0400
Subject: [PATCH 2/2] Use dyn_cast_if_present

Co-authored-by: Timm Baeder 
---
 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 ,
 
   // For builtin functions which aren't declared anywhere in source,
   // don't emit the "declared here" note.
-  if (auto *FD = dyn_cast_or_null(ChosenDecl);
+  if (const auto *FD = dyn_cast_if_present(ChosenDecl);
   FD && FD->getBuiltinID() &&
   PrevNote.getDiagID() == diag::note_previous_decl &&
   Correction.getCorrectionRange().getBegin() == FD->getBeginLoc()) {

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Sema] Don't emit 'declared here' note for builtin functions with no decl in source (PR #93394)

2024-05-26 Thread Timm Baeder via cfe-commits


@@ -5897,6 +5897,16 @@ void Sema::diagnoseTypo(const TypoCorrection ,
 
   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(ChosenDecl);

tbaederr wrote:

```suggestion
  if (const auto *FD = dyn_cast_if_present(ChosenDecl);
```

https://github.com/llvm/llvm-project/pull/93394
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Sema] Don't emit 'declared here' note for builtin functions with no decl in source (PR #93394)

2024-05-25 Thread via cfe-commits

llvmbot wrote:




@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
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 ,
 
   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(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}}
 

``




https://github.com/llvm/llvm-project/pull/93394
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Sema] Don't emit 'declared here' note for builtin functions with no decl in source (PR #93394)

2024-05-25 Thread Youngsuk Kim via cfe-commits

https://github.com/JOE1994 edited 
https://github.com/llvm/llvm-project/pull/93394
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Sema] Don't emit 'declared here' note for builtin functions with no decl in source (PR #93394)

2024-05-25 Thread Youngsuk Kim via cfe-commits

https://github.com/JOE1994 edited 
https://github.com/llvm/llvm-project/pull/93394
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits