Skip to content

Commit 1ddd586

Browse files
committed
[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
1 parent 2652db4 commit 1ddd586

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

clang/lib/AST/ExprConstant.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2648,14 +2648,9 @@ static bool HandleIntToFloatCast(EvalInfo &Info, const Expr *E,
26482648
QualType SrcType, const APSInt &Value,
26492649
QualType DestType, APFloat &Result) {
26502650
Result = APFloat(Info.Ctx.getFloatTypeSemantics(DestType), 1);
2651-
APFloat::opStatus St = Result.convertFromAPInt(Value, Value.isSigned(),
2652-
APFloat::rmNearestTiesToEven);
2653-
if (!Info.InConstantContext && St != llvm::APFloatBase::opOK &&
2654-
FPO.isFPConstrained()) {
2655-
Info.FFDiag(E, diag::note_constexpr_float_arithmetic_strict);
2656-
return false;
2657-
}
2658-
return true;
2651+
llvm::RoundingMode RM = getActiveRoundingMode(Info, E);
2652+
APFloat::opStatus St = Result.convertFromAPInt(Value, Value.isSigned(), RM);
2653+
return checkFloatingPointResult(Info, E, St);
26592654
}
26602655

26612656
static bool truncateBitfieldValue(EvalInfo &Info, const Expr *E,

clang/test/AST/const-fpfeatures.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -fexperimental-strict-floating-point -S -emit-llvm -triple i386-linux -Wno-unknown-pragmas %s -o - | FileCheck %s
1+
// RUN: %clang_cc1 -S -emit-llvm -triple i386-linux -Wno-unknown-pragmas %s -o - | FileCheck %s
22

33
// nextUp(1.F) == 0x1.000002p0F
44

@@ -13,6 +13,9 @@ float F3u = 0x1.000001p0;
1313
// CHECK: @F2u = {{.*}} float 0x3FF0000020000000
1414
// CHECK: @F3u = {{.*}} float 0x3FF0000020000000
1515

16+
float FI1u = 0xFFFFFFFFU;
17+
// CHECK: @FI1u = {{.*}} float 0x41F0000000000000
18+
1619
float _Complex C1u = C0;
1720
// CHECK: @C1u = {{.*}} { float, float } { float 0x3FF0000020000000, float 0x3FF0000020000000 }
1821

@@ -27,5 +30,8 @@ float F3d = 0x1.000001p0;
2730
// CHECK: @F2d = {{.*}} float 1.000000e+00
2831
// CHECK: @F3d = {{.*}} float 1.000000e+00
2932

33+
float FI1d = 0xFFFFFFFFU;
34+
// CHECK: @FI1d = {{.*}} float 0x41EFFFFFE0000000
35+
3036
float _Complex C1d = C0;
3137
// CHECK: @C1d = {{.*}} { float, float } { float 1.000000e+00, float 1.000000e+00 }

0 commit comments

Comments
 (0)