[PATCH] D137719: [clang] Missed rounding mode use in constant evaluation

Serge Pavlov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 9 10:16:43 PST 2022


sepavloff updated this revision to Diff 474304.
sepavloff added a comment.

Remove accidentally added file


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137719/new/

https://reviews.llvm.org/D137719

Files:
  clang/lib/AST/ExprConstant.cpp
  clang/test/AST/const-fpfeatures.c


Index: clang/test/AST/const-fpfeatures.c
===================================================================
--- clang/test/AST/const-fpfeatures.c
+++ clang/test/AST/const-fpfeatures.c
@@ -13,6 +13,9 @@
 // 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 @@
 // 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 }
Index: clang/lib/AST/ExprConstant.cpp
===================================================================
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -2644,18 +2644,12 @@
 }
 
 static bool HandleIntToFloatCast(EvalInfo &Info, const Expr *E,
-                                 const FPOptions FPO,
-                                 QualType SrcType, const APSInt &Value,
-                                 QualType DestType, APFloat &Result) {
+                                 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,
@@ -4413,11 +4407,8 @@
       Value = HandleIntToIntCast(Info, E, SubobjType, PromotedLHSType, LHS);
       return true;
     } else if (RHS.isFloat()) {
-      const FPOptions FPO = E->getFPFeaturesInEffect(
-                                    Info.Ctx.getLangOpts());
       APFloat FValue(0.0);
-      return HandleIntToFloatCast(Info, E, FPO, SubobjType, Value,
-                                  PromotedLHSType, FValue) &&
+      return HandleIntToFloatCast(Info, E, Value, PromotedLHSType, FValue) &&
              handleFloatFloatBinOp(Info, E, FValue, Opcode, RHS.getFloat()) &&
              HandleFloatToIntCast(Info, E, PromotedLHSType, FValue, SubobjType,
                                   Value);
@@ -14169,11 +14160,8 @@
 
   case CK_IntegralToFloating: {
     APSInt IntResult;
-    const FPOptions FPO = E->getFPFeaturesInEffect(
-                                  Info.Ctx.getLangOpts());
     return EvaluateInteger(SubExpr, IntResult, Info) &&
-           HandleIntToFloatCast(Info, E, FPO, SubExpr->getType(),
-                                IntResult, E->getType(), Result);
+           HandleIntToFloatCast(Info, E, IntResult, E->getType(), Result);
   }
 
   case CK_FixedPointToFloating: {
@@ -14414,16 +14402,11 @@
     if (!Visit(E->getSubExpr()))
       return false;
 
-    const FPOptions FPO = E->getFPFeaturesInEffect(
-                                  Info.Ctx.getLangOpts());
     QualType To = E->getType()->castAs<ComplexType>()->getElementType();
-    QualType From
-      = E->getSubExpr()->getType()->castAs<ComplexType>()->getElementType();
     Result.makeComplexFloat();
-    return HandleIntToFloatCast(Info, E, FPO, From, Result.IntReal,
-                                To, Result.FloatReal) &&
-           HandleIntToFloatCast(Info, E, FPO, From, Result.IntImag,
-                                To, Result.FloatImag);
+    return HandleIntToFloatCast(Info, E, Result.IntReal, To,
+                                Result.FloatReal) &&
+           HandleIntToFloatCast(Info, E, Result.IntImag, To, Result.FloatImag);
   }
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137719.474304.patch
Type: text/x-patch
Size: 4129 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221109/facde418/attachment.bin>


More information about the cfe-commits mailing list