Skip to content

Commit

Permalink
[clang][Interp] Implement CXXStdInitializerListExprs
Browse files Browse the repository at this point in the history
  • Loading branch information
tbaederr committed Jun 26, 2024
1 parent 6e96e5a commit e5e0d87
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
33 changes: 33 additions & 0 deletions clang/lib/AST/Interp/ByteCodeExprGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions clang/lib/AST/Interp/ByteCodeExprGen.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit e5e0d87

Please sign in to comment.