Skip to content

Commit 6d3b779

Browse files
committed
Set 'rounding_mode' to 'tonearest' with '#pragma STDC FENV_ACCESS OFF'.
In strict mode the 'roundin_mode' is set to 'dynamic'. Using this pragma to get out of strict mode doesn't have any effect on the 'rounding_mode'. See https://godbolt.org/z/zoGTf4j1G This patch fixes that. Differential Revision: https://reviews.llvm.org/D147733
1 parent a11523a commit 6d3b779

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

clang/lib/Sema/SemaAttr.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,6 +1336,7 @@ void Sema::ActOnPragmaFEnvAccess(SourceLocation Loc, bool IsEnabled) {
13361336
Diag(Loc, diag::err_pragma_fenv_requires_precise);
13371337
}
13381338
NewFPFeatures.setAllowFEnvAccessOverride(IsEnabled);
1339+
NewFPFeatures.setRoundingMathOverride(IsEnabled);
13391340
FpPragmaStack.Act(Loc, PSK_Set, StringRef(), NewFPFeatures);
13401341
CurFPFeatures = NewFPFeatures.applyOverrides(getLangOpts());
13411342
}

clang/test/CodeGen/pragma-fenv_access.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
// RUN: %clang_cc1 -fexperimental-strict-floating-point -ffp-exception-behavior=strict -triple %itanium_abi_triple -emit-llvm %s -o - | FileCheck --check-prefixes=CHECK,STRICT %s
2+
// RUN: %clang_cc1 -fexperimental-strict-floating-point -frounding-math -ffp-exception-behavior=strict -triple %itanium_abi_triple -emit-llvm %s -o - | FileCheck --check-prefixes=CHECK,STRICT-RND %s
23
// RUN: %clang_cc1 -fexperimental-strict-floating-point -ffp-exception-behavior=strict -triple %itanium_abi_triple -emit-llvm %s -o - -fms-extensions -DMS | FileCheck --check-prefixes=CHECK,STRICT %s
4+
// RUN: %clang_cc1 -fexperimental-strict-floating-point -frounding-math -ffp-exception-behavior=strict -triple %itanium_abi_triple -emit-llvm %s -o - -fms-extensions -DMS | FileCheck --check-prefixes=CHECK,STRICT-RND %s
35
// RUN: %clang_cc1 -fexperimental-strict-floating-point -triple %itanium_abi_triple -emit-llvm %s -o - | FileCheck --check-prefixes=CHECK,DEFAULT %s
4-
6+
// RUN: %clang_cc1 -fexperimental-strict-floating-point -frounding-math -triple %itanium_abi_triple -emit-llvm %s -o - | FileCheck --check-prefixes=CHECK,DEFAULT-RND %s
57

68
float func_00(float x, float y) {
79
return x + y;
810
}
911
// CHECK-LABEL: @func_00
1012
// STRICT: call float @llvm.experimental.constrained.fadd.f32(float {{.*}}, float {{.*}}, metadata !"round.tonearest", metadata !"fpexcept.strict")
13+
// STRICT-RND: call float @llvm.experimental.constrained.fadd.f32(float {{.*}}, float {{.*}}, metadata !"round.dynamic", metadata !"fpexcept.strict")
14+
// DEFAULT-RND: call float @llvm.experimental.constrained.fadd.f32(float {{.*}}, float {{.*}}, metadata !"round.dynamic", metadata !"fpexcept.ignore")
1115
// DEFAULT: fadd float
1216

1317

@@ -224,3 +228,17 @@ float func_18(float x, float y) {
224228
// STRICT: call float @llvm.experimental.constrained.fadd.f32(float {{.*}}, float {{.*}}, metadata !"round.tonearest", metadata !"fpexcept.strict")
225229
// DEFAULT: fadd float
226230

231+
#pragma STDC FENV_ACCESS ON
232+
float func_19(float x, float y) {
233+
return x + y;
234+
}
235+
// CHECK-LABEL: @func_19
236+
// STRICT: call float @llvm.experimental.constrained.fadd.f32(float {{.*}}, float {{.*}}, metadata !"round.dynamic", metadata !"fpexcept.strict")
237+
238+
#pragma STDC FENV_ACCESS OFF
239+
float func_20(float x, float y) {
240+
return x + y;
241+
}
242+
// CHECK-LABEL: @func_20
243+
// STRICT: call float @llvm.experimental.constrained.fadd.f32(float {{.*}}, float {{.*}}, metadata !"round.tonearest", metadata !"fpexcept.strict")
244+
// DEFAULT: fadd float

0 commit comments

Comments
 (0)