Index: lib/CodeGen/CGDeclCXX.cpp =================================================================== --- lib/CodeGen/CGDeclCXX.cpp +++ lib/CodeGen/CGDeclCXX.cpp @@ -272,6 +272,10 @@ if (getLangOpts().Sanitize.has(SanitizerKind::Memory)) Fn->addFnAttr(llvm::Attribute::SanitizeMemory); } + + if (getCodeGenOpts().DisableFPElim && + getCodeGenOpts().OmitLeafFramePointer) + Fn->addFnAttr("no-frame-pointer-elim-non-leaf"); return Fn; } Index: test/CodeGenCXX/global-init.cpp =================================================================== --- test/CodeGenCXX/global-init.cpp +++ test/CodeGenCXX/global-init.cpp @@ -1,6 +1,10 @@ // RUN: %clang_cc1 -triple=x86_64-apple-darwin10 -emit-llvm -fexceptions %s -o - |FileCheck %s // RUN: %clang_cc1 -triple=x86_64-apple-darwin10 -emit-llvm %s -o - |FileCheck -check-prefix CHECK-NOEXC %s +// RUN: %clang_cc1 -triple=x86_64-apple-darwin10 -emit-llvm \ +// RUN: -momit-leaf-frame-pointer -mdisable-fp-elim %s -o - \ +// RUN: | FileCheck -check-prefix CHECK-FP %s + struct A { A(); ~A(); @@ -203,3 +207,7 @@ // CHECK-NOEXC: define internal void @_GLOBAL__sub_I_global_init.cpp() [[NUW:#[0-9]+]] section "__TEXT,__StaticInit,regular,pure_instructions" { // CHECK-NOEXC: attributes [[NUW]] = { nounwind } + +// PR21811: attach the appropriate attribute to the global init function +// CHECK-FP: define internal void @_GLOBAL__sub_I_global_init.cpp() [[NUX:#[0-9]+]] section "__TEXT,__StaticInit,regular,pure_instructions" { +// CHECK-FP: attributes [[NUX]] = { nounwind "no-frame-pointer-elim-non-leaf" }