[clang] e5e0d87 - [clang][Interp] Implement CXXStdInitializerListExprs
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 26 06:41:07 PDT 2024
Author: Timm Bäder
Date: 2024-06-26T15:40:54+02:00
New Revision: e5e0d8739d4a2b70d7ad317863d7b168e4895b18
URL: https://github.com/llvm/llvm-project/commit/e5e0d8739d4a2b70d7ad317863d7b168e4895b18
DIFF: https://github.com/llvm/llvm-project/commit/e5e0d8739d4a2b70d7ad317863d7b168e4895b18.diff
LOG: [clang][Interp] Implement CXXStdInitializerListExprs
Added:
Modified:
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/ByteCodeExprGen.h
clang/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 7b5aaa02a22c5..3170b2faeaa0b 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -2930,6 +2930,39 @@ bool ByteCodeExprGen<Emitter>::VisitObjCBoxedExpr(const ObjCBoxedExpr *E) {
return this->delegate(E->getSubExpr());
}
+template <class Emitter>
+bool ByteCodeExprGen<Emitter>::VisitCXXStdInitializerListExpr(
+ const CXXStdInitializerListExpr *E) {
+ const Expr *SubExpr = E->getSubExpr();
+ const ConstantArrayType *ArrayType =
+ Ctx.getASTContext().getAsConstantArrayType(SubExpr->getType());
+ const Record *R = getRecord(E->getType());
+ assert(Initializing);
+ assert(SubExpr->isGLValue());
+
+ if (!this->visit(SubExpr))
+ return false;
+ if (!this->emitInitFieldPtr(R->getField(0u)->Offset, E))
+ return false;
+
+ PrimType SecondFieldT = classifyPrim(R->getField(1u)->Decl->getType());
+ if (isIntegralType(SecondFieldT)) {
+ if (!this->emitConst(static_cast<APSInt>(ArrayType->getSize()),
+ SecondFieldT, E))
+ return false;
+ return this->emitInitField(SecondFieldT, R->getField(1u)->Offset, E);
+ }
+ assert(SecondFieldT == PT_Ptr);
+
+ if (!this->emitGetFieldPtr(R->getField(0u)->Offset, E))
+ return false;
+ if (!this->emitConst(static_cast<APSInt>(ArrayType->getSize()), PT_Uint64, E))
+ return false;
+ if (!this->emitArrayElemPtrPop(PT_Uint64, E))
+ return false;
+ return this->emitInitFieldPtr(R->getField(1u)->Offset, E);
+}
+
template <class Emitter> bool ByteCodeExprGen<Emitter>::discard(const Expr *E) {
OptionScope<Emitter> Scope(this, /*NewDiscardResult=*/true,
/*NewInitializing=*/false);
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.h b/clang/lib/AST/Interp/ByteCodeExprGen.h
index 2921ffe49c45f..88e9eddd55be4 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.h
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -177,6 +177,7 @@ class ByteCodeExprGen : public ConstStmtVisitor<ByteCodeExprGen<Emitter>, bool>,
bool VisitShuffleVectorExpr(const ShuffleVectorExpr *E);
bool VisitExtVectorElementExpr(const ExtVectorElementExpr *E);
bool VisitObjCBoxedExpr(const ObjCBoxedExpr *E);
+ bool VisitCXXStdInitializerListExpr(const CXXStdInitializerListExpr *E);
protected:
bool visitExpr(const Expr *E) override;
diff --git a/clang/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp b/clang/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp
index 74aa7cb2abe83..41b4f6dc308d9 100644
--- a/clang/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp
+++ b/clang/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp
@@ -1,4 +1,5 @@
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s -fexperimental-new-constant-interpreter
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -DUNION_TEST -verify %s
#ifdef UNION_TEST
More information about the cfe-commits
mailing list