diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -5087,6 +5087,10 @@ // PushDeclContext because we don't have a scope. Sema::ContextRAII savedContext(*this, Function); + FPFeaturesStateRAII SavedFPFeatures(*this); + CurFPFeatures = FPOptions(getLangOpts()); + FpPragmaStack.CurrentValue = FPOptionsOverride(); + if (addInstantiatedParametersToScope(Function, PatternDecl, Scope, TemplateArgs)) return; diff --git a/clang/test/CodeGen/fp-template.cpp b/clang/test/CodeGen/fp-template.cpp --- a/clang/test/CodeGen/fp-template.cpp +++ b/clang/test/CodeGen/fp-template.cpp @@ -15,4 +15,19 @@ // CHECK-SAME: (float noundef %{{.*}}, float noundef %{{.*}}) #[[ATTR01:[0-9]+]]{{.*}} { // CHECK: call float @llvm.experimental.constrained.fadd.f32 +namespace PR63542 { + template float stable_sort(float x, Compare) { + float result = x + x; + stable_sort(x, int()); + return result; + } + float linkage_wrap() { return stable_sort(0.0, 1); } +} + +// CHECK-LABEL: define {{.*}} float @_ZN7PR6354211stable_sortIiEEffT_( +// CHECK: fadd float + +// Must be at the end of translation unit. +#pragma STDC FENV_ACCESS ON + // CHECK: attributes #[[ATTR01]] = { {{.*}}strictfp