[clang] [clang]Avoid diagnose invalid consteval call for invalid function decl (PR #68646)

2023-10-10 Thread Congcong Cai via cfe-commits

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


[clang] [clang]Avoid diagnose invalid consteval call for invalid function decl (PR #68646)

2023-10-10 Thread via cfe-commits

https://github.com/cor3ntin approved this pull request.

I was about to work on that and figured the fix would be along those lines! 
Glad you got to it first, thanks!

The changes look great

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


[clang] [clang]Avoid diagnose invalid consteval call for invalid function decl (PR #68646)

2023-10-10 Thread via cfe-commits


@@ -358,6 +358,8 @@ Bug Fixes in This Version
   Fixes (`#67690 `_)
 - Fixes a ``clang-17`` regression where ``LLVM_UNREACHABLE_OPTIMIZE=OFF``
   cannot be used with ``Release`` mode builds. (`#68237 
`_).
+- Fix crash in evaluating ``constexpr`` value for invalid template function.

cor3ntin wrote:

```suggestion
- Fix crash when evaluating an invalid immediate function template.
```

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


[clang] [clang]Avoid diagnose invalid consteval call for invalid function decl (PR #68646)

2023-10-09 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 updated 
https://github.com/llvm/llvm-project/pull/68646

>From ffc9412252cd0e046978f183384375580bd31245 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Tue, 10 Oct 2023 07:52:06 +0800
Subject: [PATCH 1/3] [clang]Avoid diagnoise invalid consteval call for invalid
 function decl

Fixes:#68542
It is meaningless to diagnoise further error for a invalid function declaration.
---
 clang/lib/Sema/SemaExpr.cpp|  3 ++-
 clang/test/SemaCXX/PR68542.cpp | 20 
 2 files changed, 22 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaCXX/PR68542.cpp

diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 9c5f96eebd04165..2e01b82b13d819e 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -18406,9 +18406,10 @@ static void EvaluateAndDiagnoseImmediateInvocation(
   FD = Call->getConstructor();
 else if (auto *Cast = dyn_cast(InnerExpr))
   FD = dyn_cast_or_null(Cast->getConversionFunction());
-
 assert(FD && FD->isImmediateFunction() &&
"could not find an immediate function in this expression");
+if (FD->isInvalidDecl())
+  return;
 SemaRef.Diag(CE->getBeginLoc(), diag::err_invalid_consteval_call)
 << FD << FD->isConsteval();
 if (auto Context =
diff --git a/clang/test/SemaCXX/PR68542.cpp b/clang/test/SemaCXX/PR68542.cpp
new file mode 100644
index 000..bc94fffe5de289d
--- /dev/null
+++ b/clang/test/SemaCXX/PR68542.cpp
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -verify -std=c++20 -fsyntax-only %s
+
+// expected-note@+2{{candidate constructor (the implicit move constructor) not 
viable: no known conversion from 'int' to 'S &&' for 1st argument}}
+// expected-note@+1{{candidate constructor (the implicit copy constructor) not 
viable: no known conversion from 'int' to 'const S &' for 1st argument}}
+struct S {
+int e;
+};
+
+template
+consteval int get_format() {
+   return nullptr; // expected-error{{cannot initialize return object of 
type 'int' with an rvalue of type 'std::nullptr_t'}}
+}
+
+template
+constexpr S f(T) noexcept {
+   return get_format(); // expected-error{{no viable conversion from 
returned value of type 'int' to function return type 'S'}}
+}
+
+// expected-note@+1{{in instantiation of function template specialization 
'f' requested here}}
+constexpr S x = f(0); // expected-error{{constexpr variable 'x' must be 
initialized by a constant expression}}
\ No newline at end of file

>From 3f48ddf36577c1750c59d80a0b803197ef7b85b0 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Tue, 10 Oct 2023 09:54:16 +0800
Subject: [PATCH 2/3] release note

---
 clang/docs/ReleaseNotes.rst | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ea737fdb5fdad15..31f4844f22ed37b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -358,6 +358,8 @@ Bug Fixes in This Version
   Fixes (`#67690 `_)
 - Fixes a ``clang-17`` regression where ``LLVM_UNREACHABLE_OPTIMIZE=OFF``
   cannot be used with ``Release`` mode builds. (`#68237 
`_).
+- Fix crash in evaluating ``constexpr`` value for invalid template function.
+  Fixes (`#68542 `_)
 
 Bug Fixes to Compiler Builtins
 ^^

>From f3c8ba15dae0511004975ea54ea0965017d95588 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Tue, 10 Oct 2023 10:07:44 +0800
Subject: [PATCH 3/3] update test

---
 clang/lib/Sema/SemaExpr.cpp| 1 +
 clang/test/SemaCXX/PR68542.cpp | 8 
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 2e01b82b13d819e..7ede275bb5a05e1 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -18406,6 +18406,7 @@ static void EvaluateAndDiagnoseImmediateInvocation(
   FD = Call->getConstructor();
 else if (auto *Cast = dyn_cast(InnerExpr))
   FD = dyn_cast_or_null(Cast->getConversionFunction());
+
 assert(FD && FD->isImmediateFunction() &&
"could not find an immediate function in this expression");
 if (FD->isInvalidDecl())
diff --git a/clang/test/SemaCXX/PR68542.cpp b/clang/test/SemaCXX/PR68542.cpp
index bc94fffe5de289d..fc767a78c8b0013 100644
--- a/clang/test/SemaCXX/PR68542.cpp
+++ b/clang/test/SemaCXX/PR68542.cpp
@@ -1,7 +1,5 @@
 // RUN: %clang_cc1 -verify -std=c++20 -fsyntax-only %s
 
-// expected-note@+2{{candidate constructor (the implicit move constructor) not 
viable: no known conversion from 'int' to 'S &&' for 1st argument}}
-// expected-note@+1{{candidate constructor (the implicit copy constructor) not 
viable: no known conversion from 'int' to 'const S &' for 1st argument}}
 struct S {
 int e;
 };
@@ -16,5 +14,7 @@ constexpr S f(T) noexcept {
return get_format(); // 

[clang] [clang]Avoid diagnose invalid consteval call for invalid function decl (PR #68646)

2023-10-09 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 updated 
https://github.com/llvm/llvm-project/pull/68646

>From ffc9412252cd0e046978f183384375580bd31245 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Tue, 10 Oct 2023 07:52:06 +0800
Subject: [PATCH 1/2] [clang]Avoid diagnoise invalid consteval call for invalid
 function decl

Fixes:#68542
It is meaningless to diagnoise further error for a invalid function declaration.
---
 clang/lib/Sema/SemaExpr.cpp|  3 ++-
 clang/test/SemaCXX/PR68542.cpp | 20 
 2 files changed, 22 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaCXX/PR68542.cpp

diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 9c5f96eebd04165..2e01b82b13d819e 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -18406,9 +18406,10 @@ static void EvaluateAndDiagnoseImmediateInvocation(
   FD = Call->getConstructor();
 else if (auto *Cast = dyn_cast(InnerExpr))
   FD = dyn_cast_or_null(Cast->getConversionFunction());
-
 assert(FD && FD->isImmediateFunction() &&
"could not find an immediate function in this expression");
+if (FD->isInvalidDecl())
+  return;
 SemaRef.Diag(CE->getBeginLoc(), diag::err_invalid_consteval_call)
 << FD << FD->isConsteval();
 if (auto Context =
diff --git a/clang/test/SemaCXX/PR68542.cpp b/clang/test/SemaCXX/PR68542.cpp
new file mode 100644
index 000..bc94fffe5de289d
--- /dev/null
+++ b/clang/test/SemaCXX/PR68542.cpp
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -verify -std=c++20 -fsyntax-only %s
+
+// expected-note@+2{{candidate constructor (the implicit move constructor) not 
viable: no known conversion from 'int' to 'S &&' for 1st argument}}
+// expected-note@+1{{candidate constructor (the implicit copy constructor) not 
viable: no known conversion from 'int' to 'const S &' for 1st argument}}
+struct S {
+int e;
+};
+
+template
+consteval int get_format() {
+   return nullptr; // expected-error{{cannot initialize return object of 
type 'int' with an rvalue of type 'std::nullptr_t'}}
+}
+
+template
+constexpr S f(T) noexcept {
+   return get_format(); // expected-error{{no viable conversion from 
returned value of type 'int' to function return type 'S'}}
+}
+
+// expected-note@+1{{in instantiation of function template specialization 
'f' requested here}}
+constexpr S x = f(0); // expected-error{{constexpr variable 'x' must be 
initialized by a constant expression}}
\ No newline at end of file

>From 3f48ddf36577c1750c59d80a0b803197ef7b85b0 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Tue, 10 Oct 2023 09:54:16 +0800
Subject: [PATCH 2/2] release note

---
 clang/docs/ReleaseNotes.rst | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ea737fdb5fdad15..31f4844f22ed37b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -358,6 +358,8 @@ Bug Fixes in This Version
   Fixes (`#67690 `_)
 - Fixes a ``clang-17`` regression where ``LLVM_UNREACHABLE_OPTIMIZE=OFF``
   cannot be used with ``Release`` mode builds. (`#68237 
`_).
+- Fix crash in evaluating ``constexpr`` value for invalid template function.
+  Fixes (`#68542 `_)
 
 Bug Fixes to Compiler Builtins
 ^^

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


[clang] [clang]Avoid diagnose invalid consteval call for invalid function decl (PR #68646)

2023-10-09 Thread Erich Keane via cfe-commits


@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -verify -std=c++20 -fsyntax-only %s
+
+// expected-note@+2{{candidate constructor (the implicit move constructor) not 
viable: no known conversion from 'int' to 'S &&' for 1st argument}}

erichkeane wrote:

Can you use the bookmark feature to put these notes next to the error they are 
associated with?  I'm not positive where the errors are here.

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


[clang] [clang]Avoid diagnose invalid consteval call for invalid function decl (PR #68646)

2023-10-09 Thread Erich Keane via cfe-commits

https://github.com/erichkeane commented:

Needs a release note, plus a couple nits.  Otherwise LGTM!

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


[clang] [clang]Avoid diagnose invalid consteval call for invalid function decl (PR #68646)

2023-10-09 Thread Erich Keane via cfe-commits


@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -verify -std=c++20 -fsyntax-only %s
+
+// expected-note@+2{{candidate constructor (the implicit move constructor) not 
viable: no known conversion from 'int' to 'S &&' for 1st argument}}
+// expected-note@+1{{candidate constructor (the implicit copy constructor) not 
viable: no known conversion from 'int' to 'const S &' for 1st argument}}
+struct S {
+int e;
+};
+
+template
+consteval int get_format() {
+   return nullptr; // expected-error{{cannot initialize return object of 
type 'int' with an rvalue of type 'std::nullptr_t'}}
+}
+
+template
+constexpr S f(T) noexcept {
+   return get_format(); // expected-error{{no viable conversion from 
returned value of type 'int' to function return type 'S'}}
+}
+
+// expected-note@+1{{in instantiation of function template specialization 
'f' requested here}}
+constexpr S x = f(0); // expected-error{{constexpr variable 'x' must be 
initialized by a constant expression}}

erichkeane wrote:

Need newline at end of file.

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


[clang] [clang]Avoid diagnose invalid consteval call for invalid function decl (PR #68646)

2023-10-09 Thread Erich Keane via cfe-commits


@@ -18406,9 +18406,10 @@ static void EvaluateAndDiagnoseImmediateInvocation(
   FD = Call->getConstructor();
 else if (auto *Cast = dyn_cast(InnerExpr))
   FD = dyn_cast_or_null(Cast->getConversionFunction());
-

erichkeane wrote:

Unrelated change.

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


[clang] [clang]Avoid diagnose invalid consteval call for invalid function decl (PR #68646)

2023-10-09 Thread Erich Keane via cfe-commits

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


[clang] [clang]Avoid diagnose invalid consteval call for invalid function decl (PR #68646)

2023-10-09 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Congcong Cai (HerrCai0907)


Changes

Fixes:#68542
It is meaningless to diagnose further error for a invalid function declaration.

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


2 Files Affected:

- (modified) clang/lib/Sema/SemaExpr.cpp (+2-1) 
- (added) clang/test/SemaCXX/PR68542.cpp (+20) 


``diff
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 9c5f96eebd04165..2e01b82b13d819e 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -18406,9 +18406,10 @@ static void EvaluateAndDiagnoseImmediateInvocation(
   FD = Call->getConstructor();
 else if (auto *Cast = dyn_cast(InnerExpr))
   FD = dyn_cast_or_null(Cast->getConversionFunction());
-
 assert(FD && FD->isImmediateFunction() &&
"could not find an immediate function in this expression");
+if (FD->isInvalidDecl())
+  return;
 SemaRef.Diag(CE->getBeginLoc(), diag::err_invalid_consteval_call)
 << FD << FD->isConsteval();
 if (auto Context =
diff --git a/clang/test/SemaCXX/PR68542.cpp b/clang/test/SemaCXX/PR68542.cpp
new file mode 100644
index 000..bc94fffe5de289d
--- /dev/null
+++ b/clang/test/SemaCXX/PR68542.cpp
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -verify -std=c++20 -fsyntax-only %s
+
+// expected-note@+2{{candidate constructor (the implicit move constructor) not 
viable: no known conversion from 'int' to 'S &&' for 1st argument}}
+// expected-note@+1{{candidate constructor (the implicit copy constructor) not 
viable: no known conversion from 'int' to 'const S &' for 1st argument}}
+struct S {
+int e;
+};
+
+template
+consteval int get_format() {
+   return nullptr; // expected-error{{cannot initialize return object of 
type 'int' with an rvalue of type 'std::nullptr_t'}}
+}
+
+template
+constexpr S f(T) noexcept {
+   return get_format(); // expected-error{{no viable conversion from 
returned value of type 'int' to function return type 'S'}}
+}
+
+// expected-note@+1{{in instantiation of function template specialization 
'f' requested here}}
+constexpr S x = f(0); // expected-error{{constexpr variable 'x' must be 
initialized by a constant expression}}
\ No newline at end of file

``




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


[clang] [clang]Avoid diagnose invalid consteval call for invalid function decl (PR #68646)

2023-10-09 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 created 
https://github.com/llvm/llvm-project/pull/68646

Fixes:#68542
It is meaningless to diagnose further error for a invalid function declaration.

>From ffc9412252cd0e046978f183384375580bd31245 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Tue, 10 Oct 2023 07:52:06 +0800
Subject: [PATCH] [clang]Avoid diagnoise invalid consteval call for invalid
 function decl

Fixes:#68542
It is meaningless to diagnoise further error for a invalid function declaration.
---
 clang/lib/Sema/SemaExpr.cpp|  3 ++-
 clang/test/SemaCXX/PR68542.cpp | 20 
 2 files changed, 22 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaCXX/PR68542.cpp

diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 9c5f96eebd04165..2e01b82b13d819e 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -18406,9 +18406,10 @@ static void EvaluateAndDiagnoseImmediateInvocation(
   FD = Call->getConstructor();
 else if (auto *Cast = dyn_cast(InnerExpr))
   FD = dyn_cast_or_null(Cast->getConversionFunction());
-
 assert(FD && FD->isImmediateFunction() &&
"could not find an immediate function in this expression");
+if (FD->isInvalidDecl())
+  return;
 SemaRef.Diag(CE->getBeginLoc(), diag::err_invalid_consteval_call)
 << FD << FD->isConsteval();
 if (auto Context =
diff --git a/clang/test/SemaCXX/PR68542.cpp b/clang/test/SemaCXX/PR68542.cpp
new file mode 100644
index 000..bc94fffe5de289d
--- /dev/null
+++ b/clang/test/SemaCXX/PR68542.cpp
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -verify -std=c++20 -fsyntax-only %s
+
+// expected-note@+2{{candidate constructor (the implicit move constructor) not 
viable: no known conversion from 'int' to 'S &&' for 1st argument}}
+// expected-note@+1{{candidate constructor (the implicit copy constructor) not 
viable: no known conversion from 'int' to 'const S &' for 1st argument}}
+struct S {
+int e;
+};
+
+template
+consteval int get_format() {
+   return nullptr; // expected-error{{cannot initialize return object of 
type 'int' with an rvalue of type 'std::nullptr_t'}}
+}
+
+template
+constexpr S f(T) noexcept {
+   return get_format(); // expected-error{{no viable conversion from 
returned value of type 'int' to function return type 'S'}}
+}
+
+// expected-note@+1{{in instantiation of function template specialization 
'f' requested here}}
+constexpr S x = f(0); // expected-error{{constexpr variable 'x' must be 
initialized by a constant expression}}
\ No newline at end of file

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