Hi,
This patch attempts to fix bug#21811 by attaching the 
no-frame-pointer-elim-non-leaf
attribute to the compiler-created global init function. It would be helpful if
someone can review this,
- Gao

http://reviews.llvm.org/D9203

Files:
  lib/CodeGen/CGDeclCXX.cpp
  test/CodeGenCXX/global-init.cpp

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" }

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
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" }
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to