aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/AST/ByteCode/Compiler.cpp
diff options
context:
space:
mode:
authorTimm Baeder <tbaeder@redhat.com>2025-08-19 11:04:21 +0200
committerGitHub <noreply@github.com>2025-08-19 11:04:21 +0200
commita1039c1b841853f42eb85f0ad4f368b5b2565cca (patch)
tree39018ffab0b04d1fd1bef1e9a8c9f486023d50ef /clang/lib/AST/ByteCode/Compiler.cpp
parent56ce40bc7378d8d8d94ec788a9d589b1ad990dc7 (diff)
downloadllvm-a1039c1b841853f42eb85f0ad4f368b5b2565cca.zip
llvm-a1039c1b841853f42eb85f0ad4f368b5b2565cca.tar.gz
llvm-a1039c1b841853f42eb85f0ad4f368b5b2565cca.tar.bz2
[clang][bytecode] Fix initializing float elements from #embed (#154285)
Fixes #152885
Diffstat (limited to 'clang/lib/AST/ByteCode/Compiler.cpp')
-rw-r--r--clang/lib/AST/ByteCode/Compiler.cpp26
1 files changed, 20 insertions, 6 deletions
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index f7947bd..e9d937f 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -1939,8 +1939,17 @@ bool Compiler<Emitter>::visitInitList(ArrayRef<const Expr *> Inits,
PrimType TargetT = classifyPrim(Init->getType());
auto Eval = [&](const IntegerLiteral *IL, unsigned ElemIndex) {
- if (!this->emitConst(IL->getValue(), Init))
- return false;
+ if (TargetT == PT_Float) {
+ if (!this->emitConst(IL->getValue(), classifyPrim(IL), Init))
+ return false;
+ const auto *Sem = &Ctx.getFloatSemantics(CAT->getElementType());
+ if (!this->emitCastIntegralFloating(classifyPrim(IL), Sem,
+ getFPOptions(E), E))
+ return false;
+ } else {
+ if (!this->emitConst(IL->getValue(), TargetT, Init))
+ return false;
+ }
return this->emitInitElem(TargetT, ElemIndex, IL);
};
if (!EmbedS->doForEachDataElement(Eval, ElementIndex))
@@ -4108,8 +4117,7 @@ bool Compiler<Emitter>::VisitCXXStdInitializerListExpr(
PrimType SecondFieldT = classifyPrim(R->getField(1u)->Decl->getType());
if (isIntegralType(SecondFieldT)) {
- if (!this->emitConst(static_cast<APSInt>(ArrayType->getSize()),
- SecondFieldT, E))
+ if (!this->emitConst(ArrayType->getSize(), SecondFieldT, E))
return false;
return this->emitInitField(SecondFieldT, R->getField(1u)->Offset, E);
}
@@ -4119,7 +4127,7 @@ bool Compiler<Emitter>::VisitCXXStdInitializerListExpr(
return false;
if (!this->emitExpandPtr(E))
return false;
- if (!this->emitConst(static_cast<APSInt>(ArrayType->getSize()), PT_Uint64, E))
+ if (!this->emitConst(ArrayType->getSize(), PT_Uint64, E))
return false;
if (!this->emitArrayElemPtrPop(PT_Uint64, E))
return false;
@@ -4497,12 +4505,18 @@ bool Compiler<Emitter>::emitConst(T Value, const Expr *E) {
template <class Emitter>
bool Compiler<Emitter>::emitConst(const APSInt &Value, PrimType Ty,
const Expr *E) {
+ return this->emitConst(static_cast<const APInt &>(Value), Ty, E);
+}
+
+template <class Emitter>
+bool Compiler<Emitter>::emitConst(const APInt &Value, PrimType Ty,
+ const Expr *E) {
if (Ty == PT_IntAPS)
return this->emitConstIntAPS(Value, E);
if (Ty == PT_IntAP)
return this->emitConstIntAP(Value, E);
- if (Value.isSigned())
+ if (isSignedType(Ty))
return this->emitConst(Value.getSExtValue(), Ty, E);
return this->emitConst(Value.getZExtValue(), Ty, E);
}