llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) <details> <summary>Changes</summary> And deduplicate the code. --- Full diff: https://github.com/llvm/llvm-project/pull/207592.diff 2 Files Affected: - (modified) clang/lib/AST/ByteCode/Interp.cpp (+33) - (modified) clang/lib/AST/ByteCode/Interp.h (+4-44) ``````````diff diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp index 7884aa5b5b745..63364287cc859 100644 --- a/clang/lib/AST/ByteCode/Interp.cpp +++ b/clang/lib/AST/ByteCode/Interp.cpp @@ -3088,6 +3088,39 @@ bool CopyMemberPtrPath(InterpState &S, const RecordDecl *Entry, return true; } +template <bool Signed> +static bool floatAPCast(InterpState &S, CodePtr OpPC, const Floating &F, + uint32_t BitWidth, uint32_t FPOI) { + APSInt Result(BitWidth, /*IsUnsigned=*/!Signed); + auto Status = F.convertToInteger(Result); + + // Float-to-Integral overflow check. + if ((Status & APFloat::opStatus::opInvalidOp) && F.isFinite() && + !handleOverflow(S, OpPC, F.getAPFloat())) + return false; + + FPOptions FPO = FPOptions::getFromOpaqueInt(FPOI); + + auto ResultAP = S.allocAP<IntegralAP<Signed>>(BitWidth); + ResultAP.copy(Result); + + S.Stk.push<IntegralAP<Signed>>(ResultAP); + + return CheckFloatResult(S, OpPC, F, Status, FPO); +} + +bool CastFloatingIntegralAP(InterpState &S, CodePtr OpPC, uint32_t BitWidth, + uint32_t FPOI) { + Floating F = S.Stk.pop<Floating>(); + return floatAPCast<false>(S, OpPC, F, BitWidth, FPOI); +} + +bool CastFloatingIntegralAPS(InterpState &S, CodePtr OpPC, uint32_t BitWidth, + uint32_t FPOI) { + Floating F = S.Stk.pop<Floating>(); + return floatAPCast<true>(S, OpPC, F, BitWidth, FPOI); +} + // FIXME: Would be nice to generate this instead of hardcoding it here. constexpr bool OpReturns(Opcode Op) { return Op == OP_RetVoid || Op == OP_RetValue || Op == OP_NoRet || diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h index 13e7798fcf365..4b8fc93909697 100644 --- a/clang/lib/AST/ByteCode/Interp.h +++ b/clang/lib/AST/ByteCode/Interp.h @@ -146,6 +146,10 @@ bool isConstexprUnknown(const Pointer &P); bool isConstexprUnknown(const Block *B); bool DynamicCast(InterpState &S, CodePtr OpPC, const Type *DestType, bool IsReferenceCast); +bool CastFloatingIntegralAP(InterpState &S, CodePtr OpPC, uint32_t BitWidth, + uint32_t FPOI); +bool CastFloatingIntegralAPS(InterpState &S, CodePtr OpPC, uint32_t BitWidth, + uint32_t FPOI); enum class ShiftDir { Left, Right }; @@ -2947,50 +2951,6 @@ bool CastFloatingIntegral(InterpState &S, CodePtr OpPC, uint32_t FPOI) { } } -static inline bool CastFloatingIntegralAP(InterpState &S, CodePtr OpPC, - uint32_t BitWidth, uint32_t FPOI) { - const Floating &F = S.Stk.pop<Floating>(); - - APSInt Result(BitWidth, /*IsUnsigned=*/true); - auto Status = F.convertToInteger(Result); - - // Float-to-Integral overflow check. - if ((Status & APFloat::opStatus::opInvalidOp) && F.isFinite() && - !handleOverflow(S, OpPC, F.getAPFloat())) - return false; - - FPOptions FPO = FPOptions::getFromOpaqueInt(FPOI); - - auto ResultAP = S.allocAP<IntegralAP<false>>(BitWidth); - ResultAP.copy(Result); - - S.Stk.push<IntegralAP<false>>(ResultAP); - - return CheckFloatResult(S, OpPC, F, Status, FPO); -} - -static inline bool CastFloatingIntegralAPS(InterpState &S, CodePtr OpPC, - uint32_t BitWidth, uint32_t FPOI) { - const Floating &F = S.Stk.pop<Floating>(); - - APSInt Result(BitWidth, /*IsUnsigned=*/false); - auto Status = F.convertToInteger(Result); - - // Float-to-Integral overflow check. - if ((Status & APFloat::opStatus::opInvalidOp) && F.isFinite() && - !handleOverflow(S, OpPC, F.getAPFloat())) - return false; - - FPOptions FPO = FPOptions::getFromOpaqueInt(FPOI); - - auto ResultAP = S.allocAP<IntegralAP<true>>(BitWidth); - ResultAP.copy(Result); - - S.Stk.push<IntegralAP<true>>(ResultAP); - - return CheckFloatResult(S, OpPC, F, Status, FPO); -} - bool CheckPointerToIntegralCast(InterpState &S, CodePtr OpPC, const Pointer &Ptr, unsigned BitWidth); bool CheckIntegralAddressCast(InterpState &S, CodePtr OpPC, unsigned BitWidth); `````````` </details> https://github.com/llvm/llvm-project/pull/207592 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
