From 68471d29eed2c49f9b439e505b3f24d387d54f97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Wed, 18 Jun 2025 15:17:53 +0200 Subject: =?UTF-8?q?Revert=20"Reapply=20"[clang][bytecode]=20Allocate=20Int?= =?UTF-8?q?egralAP=20and=20Floating=20types=20usi=E2=80=A6=20(#144676)"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 7c15edb306932e41c159f3d69c161ed0d89d47b7. This still breaks clang-armv8-quick: https://lab.llvm.org/buildbot/#/builders/154/builds/17587 --- clang/lib/AST/ByteCode/Compiler.cpp | 112 ++++++++++++++++-------------------- 1 file changed, 49 insertions(+), 63 deletions(-) (limited to 'clang/lib/AST/ByteCode/Compiler.cpp') diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp index 3f884ed..9fe4803 100644 --- a/clang/lib/AST/ByteCode/Compiler.cpp +++ b/clang/lib/AST/ByteCode/Compiler.cpp @@ -748,8 +748,7 @@ bool Compiler::VisitFloatingLiteral(const FloatingLiteral *E) { if (DiscardResult) return true; - APFloat F = E->getValue(); - return this->emitFloat(F, E); + return this->emitConstFloat(E->getValue(), E); } template @@ -4186,10 +4185,8 @@ bool Compiler::visitZeroInitializer(PrimType T, QualType QT, nullptr, E); case PT_MemberPtr: return this->emitNullMemberPtr(0, nullptr, E); - case PT_Float: { - APFloat F = APFloat::getZero(Ctx.getFloatSemantics(QT)); - return this->emitFloat(F, E); - } + case PT_Float: + return this->emitConstFloat(APFloat::getZero(Ctx.getFloatSemantics(QT)), E); case PT_FixedPoint: { auto Sem = Ctx.getASTContext().getFixedPointSemantics(E->getType()); return this->emitConstFixedPoint(FixedPoint::zero(Sem), E); @@ -4677,7 +4674,10 @@ VarCreationState Compiler::visitVarDecl(const VarDecl *VD, if (!visitInitializer(Init)) return false; - return this->emitFinishInitGlobal(Init); + if (!this->emitFinishInit(Init)) + return false; + + return this->emitPopPtr(Init); }; DeclScope LocalScope(this, VD); @@ -4698,45 +4698,51 @@ VarCreationState Compiler::visitVarDecl(const VarDecl *VD, return false; return !Init || (checkDecl() && initGlobal(*GlobalIndex)); - } - // Local variables. - InitLinkScope ILS(this, InitLink::Decl(VD)); + } else { + InitLinkScope ILS(this, InitLink::Decl(VD)); - if (VarT) { - unsigned Offset = this->allocateLocalPrimitive( - VD, *VarT, VD->getType().isConstQualified(), nullptr, ScopeKind::Block, - IsConstexprUnknown); - if (Init) { - // If this is a toplevel declaration, create a scope for the - // initializer. - if (Toplevel) { - LocalScope Scope(this); - if (!this->visit(Init)) - return false; - return this->emitSetLocal(*VarT, Offset, VD) && Scope.destroyLocals(); - } else { - if (!this->visit(Init)) - return false; - return this->emitSetLocal(*VarT, Offset, VD); + if (VarT) { + unsigned Offset = this->allocateLocalPrimitive( + VD, *VarT, VD->getType().isConstQualified(), nullptr, + ScopeKind::Block, IsConstexprUnknown); + if (Init) { + // If this is a toplevel declaration, create a scope for the + // initializer. + if (Toplevel) { + LocalScope Scope(this); + if (!this->visit(Init)) + return false; + return this->emitSetLocal(*VarT, Offset, VD) && Scope.destroyLocals(); + } else { + if (!this->visit(Init)) + return false; + return this->emitSetLocal(*VarT, Offset, VD); + } } - } - } else { - if (std::optional Offset = this->allocateLocal( - VD, VD->getType(), nullptr, ScopeKind::Block, IsConstexprUnknown)) { - if (!Init) - return true; + } else { + if (std::optional Offset = + this->allocateLocal(VD, VD->getType(), nullptr, ScopeKind::Block, + IsConstexprUnknown)) { + if (!Init) + return true; - if (!this->emitGetPtrLocal(*Offset, Init)) - return false; + if (!this->emitGetPtrLocal(*Offset, Init)) + return false; - if (!visitInitializer(Init)) - return false; + if (!visitInitializer(Init)) + return false; + + if (!this->emitFinishInit(Init)) + return false; - return this->emitFinishInitPop(Init); + return this->emitPopPtr(Init); + } + return false; } - return false; + return true; } - return true; + + return false; } template @@ -4745,10 +4751,8 @@ bool Compiler::visitAPValue(const APValue &Val, PrimType ValType, assert(!DiscardResult); if (Val.isInt()) return this->emitConst(Val.getInt(), ValType, E); - else if (Val.isFloat()) { - APFloat F = Val.getFloat(); - return this->emitFloat(F, E); - } + else if (Val.isFloat()) + return this->emitConstFloat(Val.getFloat(), E); if (Val.isLValue()) { if (Val.isNullPointer()) @@ -6129,10 +6133,8 @@ bool Compiler::VisitUnaryOperator(const UnaryOperator *E) { const auto &TargetSemantics = Ctx.getFloatSemantics(E->getType()); if (!this->emitLoadFloat(E)) return false; - APFloat F(TargetSemantics, 1); - if (!this->emitFloat(F, E)) + if (!this->emitConstFloat(llvm::APFloat(TargetSemantics, 1), E)) return false; - if (!this->emitAddf(getFPOptions(E), E)) return false; if (!this->emitStoreFloat(E)) @@ -6174,10 +6176,8 @@ bool Compiler::VisitUnaryOperator(const UnaryOperator *E) { const auto &TargetSemantics = Ctx.getFloatSemantics(E->getType()); if (!this->emitLoadFloat(E)) return false; - APFloat F(TargetSemantics, 1); - if (!this->emitFloat(F, E)) + if (!this->emitConstFloat(llvm::APFloat(TargetSemantics, 1), E)) return false; - if (!this->emitSubf(getFPOptions(E), E)) return false; if (!this->emitStoreFloat(E)) @@ -6953,20 +6953,6 @@ bool Compiler::emitDummyPtr(const DeclTy &D, const Expr *E) { return true; } -template -bool Compiler::emitFloat(const APFloat &F, const Expr *E) { - assert(!DiscardResult && "Should've been checked before"); - - if (Floating::singleWord(F.getSemantics())) - return this->emitConstFloat(Floating(F), E); - - APInt I = F.bitcastToAPInt(); - return this->emitConstFloat( - Floating(const_cast(I.getRawData()), - llvm::APFloatBase::SemanticsToEnum(F.getSemantics())), - E); -} - // This function is constexpr if and only if To, From, and the types of // all subobjects of To and From are types T such that... // (3.1) - is_union_v is false; -- cgit v1.1