Author: cor3ntin Date: 2024-02-19T08:45:38+01:00 New Revision: 9d3d6ec665d6284b6ba8c51a57a4a618d67a1697
URL: https://github.com/llvm/llvm-project/commit/9d3d6ec665d6284b6ba8c51a57a4a618d67a1697 DIFF: https://github.com/llvm/llvm-project/commit/9d3d6ec665d6284b6ba8c51a57a4a618d67a1697.diff LOG: [Clang] CXXConstructExpr may be immediate calls. (#82179) A CXXConstructExpr may refer to an immediate constructor, in which case it should be substituted in the enclosing default init expression. Fixes #82154 Added: Modified: clang/docs/ReleaseNotes.rst clang/lib/Sema/SemaExpr.cpp clang/test/CodeGenCXX/cxx2a-consteval.cpp Removed: ################################################################################ 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 +} +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits