@@ -1939,8 +1939,17 @@ bool Compiler<Emitter>::visitInitList(ArrayRef<const Expr *> Inits,
19391939 PrimType TargetT = classifyPrim (Init->getType ());
19401940
19411941 auto Eval = [&](const IntegerLiteral *IL, unsigned ElemIndex) {
1942- if (!this ->emitConst (IL->getValue (), Init))
1943- return false ;
1942+ if (TargetT == PT_Float) {
1943+ if (!this ->emitConst (IL->getValue (), classifyPrim (IL), Init))
1944+ return false ;
1945+ const auto *Sem = &Ctx.getFloatSemantics (CAT->getElementType ());
1946+ if (!this ->emitCastIntegralFloating (classifyPrim (IL), Sem,
1947+ getFPOptions (E), E))
1948+ return false ;
1949+ } else {
1950+ if (!this ->emitConst (IL->getValue (), TargetT, Init))
1951+ return false ;
1952+ }
19441953 return this ->emitInitElem (TargetT, ElemIndex, IL);
19451954 };
19461955 if (!EmbedS->doForEachDataElement (Eval, ElementIndex))
@@ -3181,13 +3190,6 @@ bool Compiler<Emitter>::VisitCXXConstructExpr(const CXXConstructExpr *E) {
31813190 if (T->isRecordType ()) {
31823191 const CXXConstructorDecl *Ctor = E->getConstructor ();
31833192
3184- // Trivial copy/move constructor. Avoid copy.
3185- if (Ctor->isDefaulted () && Ctor->isCopyOrMoveConstructor () &&
3186- Ctor->isTrivial () &&
3187- E->getArg (0 )->isTemporaryObject (Ctx.getASTContext (),
3188- T->getAsCXXRecordDecl ()))
3189- return this ->visitInitializer (E->getArg (0 ));
3190-
31913193 // If we're discarding a construct expression, we still need
31923194 // to allocate a variable and call the constructor and destructor.
31933195 if (DiscardResult) {
@@ -3203,6 +3205,13 @@ bool Compiler<Emitter>::VisitCXXConstructExpr(const CXXConstructExpr *E) {
32033205 return false ;
32043206 }
32053207
3208+ // Trivial copy/move constructor. Avoid copy.
3209+ if (Ctor->isDefaulted () && Ctor->isCopyOrMoveConstructor () &&
3210+ Ctor->isTrivial () &&
3211+ E->getArg (0 )->isTemporaryObject (Ctx.getASTContext (),
3212+ T->getAsCXXRecordDecl ()))
3213+ return this ->visitInitializer (E->getArg (0 ));
3214+
32063215 // Zero initialization.
32073216 if (E->requiresZeroInitialization ()) {
32083217 const Record *R = getRecord (E->getType ());
@@ -4108,8 +4117,7 @@ bool Compiler<Emitter>::VisitCXXStdInitializerListExpr(
41084117
41094118 PrimType SecondFieldT = classifyPrim (R->getField (1u )->Decl ->getType ());
41104119 if (isIntegralType (SecondFieldT)) {
4111- if (!this ->emitConst (static_cast <APSInt>(ArrayType->getSize ()),
4112- SecondFieldT, E))
4120+ if (!this ->emitConst (ArrayType->getSize (), SecondFieldT, E))
41134121 return false ;
41144122 return this ->emitInitField (SecondFieldT, R->getField (1u )->Offset , E);
41154123 }
@@ -4119,7 +4127,7 @@ bool Compiler<Emitter>::VisitCXXStdInitializerListExpr(
41194127 return false ;
41204128 if (!this ->emitExpandPtr (E))
41214129 return false ;
4122- if (!this ->emitConst (static_cast <APSInt>( ArrayType->getSize () ), PT_Uint64, E))
4130+ if (!this ->emitConst (ArrayType->getSize (), PT_Uint64, E))
41234131 return false ;
41244132 if (!this ->emitArrayElemPtrPop (PT_Uint64, E))
41254133 return false ;
@@ -4497,12 +4505,18 @@ bool Compiler<Emitter>::emitConst(T Value, const Expr *E) {
44974505template <class Emitter >
44984506bool Compiler<Emitter>::emitConst(const APSInt &Value, PrimType Ty,
44994507 const Expr *E) {
4508+ return this ->emitConst (static_cast <const APInt &>(Value), Ty, E);
4509+ }
4510+
4511+ template <class Emitter >
4512+ bool Compiler<Emitter>::emitConst(const APInt &Value, PrimType Ty,
4513+ const Expr *E) {
45004514 if (Ty == PT_IntAPS)
45014515 return this ->emitConstIntAPS (Value, E);
45024516 if (Ty == PT_IntAP)
45034517 return this ->emitConstIntAP (Value, E);
45044518
4505- if (Value. isSigned ( ))
4519+ if (isSignedType (Ty ))
45064520 return this ->emitConst (Value.getSExtValue (), Ty, E);
45074521 return this ->emitConst (Value.getZExtValue (), Ty, E);
45084522}
0 commit comments