]> git.lizzy.rs Git - rust.git/commitdiff
rustc: Ensure closures are "split-stack"
authorAlex Crichton <alex@alexcrichton.com>
Sat, 19 Apr 2014 17:33:46 +0000 (10:33 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Sat, 19 Apr 2014 17:33:46 +0000 (10:33 -0700)
In upgrading LLVM, only rust functions had the "split-stack" attribute added.
This commit changes the addition of LLVM's "split-stack" attribute to *always*
occur and then we remove it sometimes if the "no_split_stack" rust attribute is
present.

Closes #13625

src/librustc/lib/llvm.rs
src/librustc/middle/trans/base.rs
src/rustllvm/RustWrapper.cpp

index 10e717e550d1fc8c1105f5268af4ff1344026a78..9e652536f6d21907680181c96fc0cf1baae7a06d 100644 (file)
@@ -709,6 +709,7 @@ pub fn LLVMGetOrInsertFunction(M: ModuleRef,
         pub fn LLVMSetGC(Fn: ValueRef, Name: *c_char);
         pub fn LLVMAddFunctionAttr(Fn: ValueRef, PA: c_uint);
         pub fn LLVMAddFunctionAttrString(Fn: ValueRef, Name: *c_char);
+        pub fn LLVMRemoveFunctionAttrString(Fn: ValueRef, Name: *c_char);
         pub fn LLVMGetFunctionAttr(Fn: ValueRef) -> c_ulonglong;
 
         pub fn LLVMAddReturnAttribute(Fn: ValueRef, PA: c_uint);
index 95ba619e401039d1773fecee102bc40e23d788cb..735b60622ed62572f3e4c4eb18556469c535dafa 100644 (file)
@@ -199,6 +199,7 @@ fn decl_fn(llmod: ModuleRef, name: &str, cc: lib::llvm::CallConv,
     lib::llvm::SetFunctionCallConv(llfn, cc);
     // Function addresses in Rust are never significant, allowing functions to be merged.
     lib::llvm::SetUnnamedAddr(llfn, true);
+    set_split_stack(llfn);
 
     llfn
 }
@@ -445,8 +446,8 @@ pub fn set_llvm_fn_attrs(attrs: &[ast::Attribute], llfn: ValueRef) {
     }
 
     // Add the no-split-stack attribute if requested
-    if !contains_name(attrs, "no_split_stack") {
-        set_split_stack(llfn);
+    if contains_name(attrs, "no_split_stack") {
+        unset_split_stack(llfn);
     }
 
     if contains_name(attrs, "cold") {
@@ -464,6 +465,12 @@ pub fn set_split_stack(f: ValueRef) {
     })
 }
 
+pub fn unset_split_stack(f: ValueRef) {
+    "split-stack".with_c_str(|buf| {
+        unsafe { llvm::LLVMRemoveFunctionAttrString(f, buf); }
+    })
+}
+
 // Double-check that we never ask LLVM to declare the same symbol twice. It
 // silently mangles such symbols, breaking our linkage model.
 pub fn note_unique_llvm_symbol(ccx: &CrateContext, sym: ~str) {
index 035a39669de8d4323b52b2f4cb95cbdc6458205c..3fe1b1380da01498eedcbeda9fbf8db3628d82b4 100644 (file)
@@ -77,6 +77,18 @@ extern "C" void LLVMAddFunctionAttrString(LLVMValueRef fn, const char *Name) {
   unwrap<Function>(fn)->addFnAttr(Name);
 }
 
+extern "C" void LLVMRemoveFunctionAttrString(LLVMValueRef fn, const char *Name) {
+  Function *f = unwrap<Function>(fn);
+  LLVMContext &C = f->getContext();
+  AttrBuilder B;
+  B.addAttribute(Name);
+  AttributeSet to_remove = AttributeSet::get(C, AttributeSet::FunctionIndex, B);
+
+  AttributeSet attrs = f->getAttributes();
+  f->setAttributes(attrs.removeAttributes(f->getContext(),
+                                          AttributeSet::FunctionIndex,
+                                          to_remove));
+}
 
 extern "C" void LLVMAddReturnAttribute(LLVMValueRef Fn, LLVMAttribute PA) {
   Function *A = unwrap<Function>(Fn);