Skip to content

Commit 99f5fcb

Browse files
committed
[clang][Interp] Try to fix #embed on big-endian machines
Insert a cast to the proper value.
1 parent 01ce74f commit 99f5fcb

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

clang/lib/AST/Interp/ByteCodeExprGen.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,13 +1346,22 @@ bool ByteCodeExprGen<Emitter>::visitInitList(ArrayRef<const Expr *> Inits,
13461346
}
13471347
}
13481348

1349-
auto Eval = [&](Expr *Init, unsigned ElemIndex) {
1350-
return visitArrayElemInit(ElemIndex, Init);
1351-
};
1352-
13531349
unsigned ElementIndex = 0;
13541350
for (const Expr *Init : Inits) {
1355-
if (auto *EmbedS = dyn_cast<EmbedExpr>(Init->IgnoreParenImpCasts())) {
1351+
if (const auto *EmbedS =
1352+
dyn_cast<EmbedExpr>(Init->IgnoreParenImpCasts())) {
1353+
PrimType TargetT = classifyPrim(Init->getType());
1354+
1355+
auto Eval = [&](const Expr *Init, unsigned ElemIndex) {
1356+
PrimType InitT = classifyPrim(Init->getType());
1357+
if (!this->visit(Init))
1358+
return false;
1359+
if (InitT != TargetT) {
1360+
if (!this->emitCast(InitT, TargetT, E))
1361+
return false;
1362+
}
1363+
return this->emitInitElem(TargetT, ElemIndex, Init);
1364+
};
13561365
if (!EmbedS->doForEachDataElement(Eval, ElementIndex))
13571366
return false;
13581367
} else {

0 commit comments

Comments
 (0)