Skip to content

Commit 21c8d5c

Browse files
committed
Added strict fp mode checking
1 parent 4df1e69 commit 21c8d5c

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3554,6 +3554,9 @@ static bool interp__builtin_ia32_vcvtps2ph(InterpState &S, CodePtr OpPC,
35543554
// In that case, we can only evaluate if the conversion is exact.
35553555
int ImmVal = Imm.getZExtValue();
35563556
bool UseMXCSR = (ImmVal & 4) != 0;
3557+
bool IsFPConstrained =
3558+
Call->getFPFeaturesInEffect(S.getASTContext().getLangOpts())
3559+
.isFPConstrained();
35573560

35583561
llvm::RoundingMode RM;
35593562
if (!UseMXCSR) {
@@ -3589,7 +3592,7 @@ static bool interp__builtin_ia32_vcvtps2ph(InterpState &S, CodePtr OpPC,
35893592
bool LostInfo;
35903593
APFloat::opStatus St = DstVal.convert(HalfSem, RM, &LostInfo);
35913594

3592-
if (UseMXCSR && St != APFloat::opOK) {
3595+
if (UseMXCSR && IsFPConstrained && St != APFloat::opOK) {
35933596
S.FFDiag(S.Current->getSource(OpPC),
35943597
diag::note_constexpr_dynamic_rounding);
35953598
return false;

clang/lib/AST/ExprConstant.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13892,6 +13892,8 @@ bool VectorExprEvaluator::VisitCallExpr(const CallExpr *E) {
1389213892

1389313893
int ImmVal = Imm.getZExtValue();
1389413894
bool UseMXCSR = (ImmVal & 4) != 0;
13895+
bool IsFPConstrained =
13896+
E->getFPFeaturesInEffect(Info.Ctx.getLangOpts()).isFPConstrained();
1389513897

1389613898
llvm::RoundingMode RM;
1389713899
if (!UseMXCSR) {
@@ -13924,7 +13926,7 @@ bool VectorExprEvaluator::VisitCallExpr(const CallExpr *E) {
1392413926
bool LostInfo;
1392513927
APFloat::opStatus St = SrcVal.convert(HalfSem, RM, &LostInfo);
1392613928

13927-
if (UseMXCSR && St != APFloat::opOK) {
13929+
if (UseMXCSR && IsFPConstrained && St != APFloat::opOK) {
1392813930
Info.FFDiag(E, diag::note_constexpr_dynamic_rounding);
1392913931
return false;
1393013932
}

0 commit comments

Comments
 (0)