From cef69ce7791f2b6415ef3991347904381717a1ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Sat, 14 Jan 2023 19:24:49 +0100 Subject: [PATCH] [clang][Interp] Fix record initialization via CallExpr subclasses We can't just use VisitCallExpr() here, as that doesn't handle CallExpr subclasses such as CXXMemberCallExpr. Differential Revision: https://reviews.llvm.org/D141772 --- clang/lib/AST/Interp/ByteCodeExprGen.cpp | 2 +- clang/test/AST/Interp/records.cpp | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp index 1e61bc992448..afa5372a5112 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -1413,7 +1413,7 @@ bool ByteCodeExprGen::visitRecordInitializer(const Expr *Initializer) { if (!this->emitDupPtr(Initializer)) return false; - return this->VisitCallExpr(CE); + return this->visit(CE); } else if (const auto *DIE = dyn_cast(Initializer)) { return this->visitInitializer(DIE->getExpr()); } else if (const auto *CE = dyn_cast(Initializer)) { diff --git a/clang/test/AST/Interp/records.cpp b/clang/test/AST/Interp/records.cpp index c0bfdeb090eb..448e1c0eb722 100644 --- a/clang/test/AST/Interp/records.cpp +++ b/clang/test/AST/Interp/records.cpp @@ -98,12 +98,20 @@ class C { int b; constexpr C() : a(100), b(200) {} + + constexpr C get() const { + return *this; + } }; constexpr C c; static_assert(c.a == 100, ""); static_assert(c.b == 200, ""); +constexpr C c2 = C().get(); +static_assert(c.a == 100, ""); +static_assert(c.b == 200, ""); + constexpr int getB() { C c; int &j = c.b;