Author: Serge Pavlov Date: 2022-11-17T12:05:28+07:00 New Revision: 1ddd5863088b56f8614fb5a17abd2968c05790c3
URL: https://github.com/llvm/llvm-project/commit/1ddd5863088b56f8614fb5a17abd2968c05790c3 DIFF: https://github.com/llvm/llvm-project/commit/1ddd5863088b56f8614fb5a17abd2968c05790c3.diff LOG: [clang] Missed rounding mode use in constant evaluation Integer-to-float conversion was handled in constant evaluator with default rounding mode. This change fixes the behavior and the conversion is made using rounding mode stored in ImplicitCastExpr node. Differential Revision: https://reviews.llvm.org/D137719 Added: Modified: clang/lib/AST/ExprConstant.cpp clang/test/AST/const-fpfeatures.c Removed: ################################################################################ diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index e17df5da5cb2d..ecf072e070835 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -2648,14 +2648,9 @@ static bool HandleIntToFloatCast(EvalInfo &Info, const Expr *E, QualType SrcType, const APSInt &Value, QualType DestType, APFloat &Result) { Result = APFloat(Info.Ctx.getFloatTypeSemantics(DestType), 1); - APFloat::opStatus St = Result.convertFromAPInt(Value, Value.isSigned(), - APFloat::rmNearestTiesToEven); - if (!Info.InConstantContext && St != llvm::APFloatBase::opOK && - FPO.isFPConstrained()) { - Info.FFDiag(E, diag::note_constexpr_float_arithmetic_strict); - return false; - } - return true; + llvm::RoundingMode RM = getActiveRoundingMode(Info, E); + APFloat::opStatus St = Result.convertFromAPInt(Value, Value.isSigned(), RM); + return checkFloatingPointResult(Info, E, St); } static bool truncateBitfieldValue(EvalInfo &Info, const Expr *E, diff --git a/clang/test/AST/const-fpfeatures.c b/clang/test/AST/const-fpfeatures.c index c29afe6809999..6600ea27405d9 100644 --- a/clang/test/AST/const-fpfeatures.c +++ b/clang/test/AST/const-fpfeatures.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fexperimental-strict-floating-point -S -emit-llvm -triple i386-linux -Wno-unknown-pragmas %s -o - | FileCheck %s +// RUN: %clang_cc1 -S -emit-llvm -triple i386-linux -Wno-unknown-pragmas %s -o - | FileCheck %s // nextUp(1.F) == 0x1.000002p0F @@ -13,6 +13,9 @@ float F3u = 0x1.000001p0; // CHECK: @F2u = {{.*}} float 0x3FF0000020000000 // CHECK: @F3u = {{.*}} float 0x3FF0000020000000 +float FI1u = 0xFFFFFFFFU; +// CHECK: @FI1u = {{.*}} float 0x41F0000000000000 + float _Complex C1u = C0; // CHECK: @C1u = {{.*}} { float, float } { float 0x3FF0000020000000, float 0x3FF0000020000000 } @@ -27,5 +30,8 @@ float F3d = 0x1.000001p0; // CHECK: @F2d = {{.*}} float 1.000000e+00 // CHECK: @F3d = {{.*}} float 1.000000e+00 +float FI1d = 0xFFFFFFFFU; +// CHECK: @FI1d = {{.*}} float 0x41EFFFFFE0000000 + float _Complex C1d = C0; // CHECK: @C1d = {{.*}} { float, float } { float 1.000000e+00, float 1.000000e+00 } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits