diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp --- a/clang/lib/Sema/SemaStmt.cpp +++ b/clang/lib/Sema/SemaStmt.cpp @@ -391,7 +391,14 @@ } void Sema::ActOnAfterCompoundStatementLeadingPragmas() { - if (getCurFPFeatures().isFPConstrained()) { + FPOptions &FPO = getCurFPFeatures(); + if (FPO.getConstRoundingMode() == llvm::RoundingMode::Dynamic && + !FPO.getAllowFEnvAccess()) { + // If dynamic rounding mode is specified in absence of FENV_ACCESS, treat it + // as setting default rounding mode. + FpPragmaStack.CurrentValue.clearConstRoundingModeOverride(); + } + if (FPO.isFPConstrained()) { FunctionScopeInfo *FSI = getCurFunction(); assert(FSI); FSI->setUsesFPIntrin(); diff --git a/clang/test/AST/ast-dump-fpfeatures.cpp b/clang/test/AST/ast-dump-fpfeatures.cpp --- a/clang/test/AST/ast-dump-fpfeatures.cpp +++ b/clang/test/AST/ast-dump-fpfeatures.cpp @@ -109,7 +109,18 @@ } // CHECK-LABEL: FunctionDecl {{.*}} func_12 'float (float, float)' +// CHECK: BinaryOperator {{.*}} 'float' '+' + +#pragma STDC FENV_ROUND FE_DYNAMIC +#pragma STDC FENV_ACCESS ON + +float func_12a(float x, float y) { + return x + y; +} + +// CHECK-LABEL: FunctionDecl {{.*}} func_12a 'float (float, float)' // CHECK: BinaryOperator {{.*}} 'float' '+' ConstRoundingMode=dynamic +#pragma STDC FENV_ACCESS OFF #pragma STDC FENV_ROUND FE_TONEAREST