[PATCH] D146801: [clang] Fix consteval initializers of temporaries
Mariya Podchishchaeva via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Mar 24 04:03:43 PDT 2023
Fznamznon created this revision.
Herald added a project: All.
Fznamznon requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
When a potential immediate invocation is met, it is immediately wrapped by a
`ConstantExpr`. There is also a TreeTransform that removes this `ConstantExpr`
wrapper when corresponding expression evaluation context is popped.
So, in case initializer was an immediate invocation, `CXXTemporaryObjectExpr`
was wrapped by a `ConstantExpr`, and that caused additional unnecessary
`CXXFunctionalCastExpr` to be added, which later confused the TreeTransform
that rebuilds immediate invocations, so it was adding unnecessary
constructor call.
Fixes https://github.com/llvm/llvm-project/issues/60286
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D146801
Files:
clang/lib/Sema/SemaExprCXX.cpp
clang/test/SemaCXX/cxx2a-consteval.cpp
Index: clang/test/SemaCXX/cxx2a-consteval.cpp
===================================================================
--- clang/test/SemaCXX/cxx2a-consteval.cpp
+++ clang/test/SemaCXX/cxx2a-consteval.cpp
@@ -1050,3 +1050,18 @@
}
}
+
+namespace GH60286 {
+
+struct A {
+ int i = 0;
+
+ consteval A() {}
+ A(const A&) { i = 1; }
+ consteval int f() { return i; }
+};
+
+constexpr auto B = A{A{}}.f();
+static_assert(B == 0);
+
+}
Index: clang/lib/Sema/SemaExprCXX.cpp
===================================================================
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -1590,6 +1590,9 @@
Expr *Inner = Result.get();
if (CXXBindTemporaryExpr *BTE = dyn_cast_or_null<CXXBindTemporaryExpr>(Inner))
Inner = BTE->getSubExpr();
+ if (ConstantExpr *CE = dyn_cast_or_null<ConstantExpr>(Inner))
+ if (CE->isImmediateInvocation())
+ Inner = CE->getSubExpr();
if (!isa<CXXTemporaryObjectExpr>(Inner) &&
!isa<CXXScalarValueInitExpr>(Inner)) {
// If we created a CXXTemporaryObjectExpr, that node also represents the
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D146801.508042.patch
Type: text/x-patch
Size: 1081 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230324/0f1e106e/attachment.bin>
More information about the cfe-commits
mailing list