[clang] [Clang] CXXConstructExpr may be immediate calls. (PR #82179)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Feb 18 09:12:11 PST 2024
https://github.com/cor3ntin created https://github.com/llvm/llvm-project/pull/82179
A CXXConstructExpr may refer to an immediate constructor, in which case it should be substituted in the
enclosing default init expression.
Fixes #82154
>From c44bc36631c0b36f4a8e91f50221cc0f6d85038d Mon Sep 17 00:00:00 2001
From: Corentin Jabot <corentinjabot at gmail.com>
Date: Sun, 18 Feb 2024 18:06:14 +0100
Subject: [PATCH] [Clang] CXXConstructExpr may be immediate calls.
A CXXConstructExpr may refer to an immediate constructor,
in which case it should be substituted in the
enclosing default init expression.
Fixes #82154
---
clang/docs/ReleaseNotes.rst | 2 ++
clang/lib/Sema/SemaExpr.cpp | 6 ++++++
clang/test/CodeGenCXX/cxx2a-consteval.cpp | 17 +++++++++++++++++
3 files changed, 25 insertions(+)
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 06c7d57d73ca70..45ace4191592d3 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -265,6 +265,8 @@ Bug Fixes to C++ Support
- No longer reject valid use of the ``_Alignas`` specifier when declaring a
local variable, which is supported as a C11 extension in C++. Previously, it
was only accepted at namespace scope but not at local function scope.
+- Clang no longer tries to call consteval constructors at runtime when they appear in a member initializer.
+ (`#782154 <https://github.com/llvm/llvm-project/issues/82154>`_`)
Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 4049ab3bf6cafb..37a7db889a6eac 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -6201,6 +6201,12 @@ struct ImmediateCallVisitor : public RecursiveASTVisitor<ImmediateCallVisitor> {
return RecursiveASTVisitor<ImmediateCallVisitor>::VisitStmt(E);
}
+ bool VisitCXXConstructExpr(CXXConstructExpr *E) {
+ if (const FunctionDecl *FD = E->getConstructor())
+ HasImmediateCalls |= FD->isImmediateFunction();
+ return RecursiveASTVisitor<ImmediateCallVisitor>::VisitStmt(E);
+ }
+
// SourceLocExpr are not immediate invocations
// but CXXDefaultInitExpr/CXXDefaultArgExpr containing a SourceLocExpr
// need to be rebuilt so that they refer to the correct SourceLocation and
diff --git a/clang/test/CodeGenCXX/cxx2a-consteval.cpp b/clang/test/CodeGenCXX/cxx2a-consteval.cpp
index 06f1d512accec5..075cab58358abf 100644
--- a/clang/test/CodeGenCXX/cxx2a-consteval.cpp
+++ b/clang/test/CodeGenCXX/cxx2a-consteval.cpp
@@ -258,3 +258,20 @@ void void_call() { // EVAL-FN-LABEL: define {{.*}} @_Z9void_call
void_test();
// EVAL-FN: {{^}}}
}
+
+
+namespace GH82154 {
+struct S1 { consteval S1(int) {} };
+struct S3 { constexpr S3(int) {} };
+
+void f() {
+ struct S2 {
+ S1 s = 0;
+ S3 s2 = 0;
+ };
+ S2 s;
+ // EVAL-FN-LABEL: define {{.*}} void @_ZZN7GH821541fEvEN2S2C2Ev
+ // EVAL-FN-NOT: call void @_ZN7GH821542S1C2Ei
+ // EVAL-FN: call void @_ZN7GH821542S3C2Ei
+}
+}
More information about the cfe-commits
mailing list