diff --git a/clang/lib/CodeGen/CGDeclCXX.cpp b/clang/lib/CodeGen/CGDeclCXX.cpp --- a/clang/lib/CodeGen/CGDeclCXX.cpp +++ b/clang/lib/CodeGen/CGDeclCXX.cpp @@ -594,7 +594,12 @@ llvm::Function *Fn = CreateGlobalInitOrDestructFunction( FTy, llvm::Twine("_GLOBAL__sub_I_", FileName), FI); - CodeGenFunction(*this).GenerateCXXGlobalInitFunc(Fn, CXXGlobalInits); + CodeGenFunction CGFn(*this); + CGFn.GenerateCXXGlobalInitFunc(Fn, CXXGlobalInits); + if (CGFn.isStrictFP()) + if (!Fn->hasFnAttribute(llvm::Attribute::StrictFP)) + Fn->addFnAttr(llvm::Attribute::StrictFP); + AddGlobalCtor(Fn); // In OpenCL global init functions must be converted to kernels in order to diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h --- a/clang/lib/CodeGen/CodeGenFunction.h +++ b/clang/lib/CodeGen/CodeGenFunction.h @@ -4344,6 +4344,9 @@ /// Set the codegen fast-math flags. void SetFastMathFlags(FPOptions FPFeatures); + /// Query for the use of constrained floating point math + bool isStrictFP() { return Builder.getIsFPConstrained(); } + private: llvm::MDNode *getRangeForLoadFromType(QualType Ty); void EmitReturnOfRValue(RValue RV, QualType Ty); diff --git a/clang/test/CodeGen/fp-floatcontrol-stack.cpp b/clang/test/CodeGen/fp-floatcontrol-stack.cpp --- a/clang/test/CodeGen/fp-floatcontrol-stack.cpp +++ b/clang/test/CodeGen/fp-floatcontrol-stack.cpp @@ -251,3 +251,8 @@ #endif }; OFF off; + +//CHECK-DEBSTRICT: define internal void @_GLOBAL__sub_I_fp_floatcontrol_stack.cpp() [[STRICTDEF:#[0-9]+]] +//CHECK-DEBSTRICT: call void @__cxx_global_var_init() [[STRICTFPONLY:#[0-9]+]] +//CHECK-DEBSTRICT: attributes [[STRICTDEF]] = { noinline{{.*}}strictfp{{.*}} } +//CHECK-DEBSTRICT: attributes [[STRICTFPONLY]] = { strictfp }