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 <congcongcai0...@163.com> 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<CastExpr>(InnerExpr)) FD = dyn_cast_or_null<FunctionDecl>(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 000000000000000..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<class T> +consteval int get_format() { + return nullptr; // expected-error{{cannot initialize return object of type 'int' with an rvalue of type 'std::nullptr_t'}} +} + +template<class T> +constexpr S f(T) noexcept { + return get_format<T>(); // 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<int>' 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 <congcongcai0...@163.com> 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 <https://github.com/llvm/llvm-project/issues/67690>`_) - Fixes a ``clang-17`` regression where ``LLVM_UNREACHABLE_OPTIMIZE=OFF`` cannot be used with ``Release`` mode builds. (`#68237 <https://github.com/llvm/llvm-project/issues/68237>`_). +- Fix crash in evaluating ``constexpr`` value for invalid template function. + Fixes (`#68542 <https://github.com/llvm/llvm-project/issues/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