Skip to content

Commit 4ace3b7

Browse files
committed
Fix setting the fixed stack segment attribute on LLVM functions
At the same time create a more robust wrapper to try to prevent this type of issue from cropping up in the future.
1 parent 8d29367 commit 4ace3b7

File tree

2 files changed

+45
-63
lines changed

2 files changed

+45
-63
lines changed

src/librustc/lib/llvm.rs

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -59,35 +59,35 @@ pub enum Linkage {
5959

6060
#[deriving(Clone)]
6161
pub enum Attribute {
62-
ZExtAttribute = 1,
63-
SExtAttribute = 2,
64-
NoReturnAttribute = 4,
65-
InRegAttribute = 8,
66-
StructRetAttribute = 16,
67-
NoUnwindAttribute = 32,
68-
NoAliasAttribute = 64,
69-
ByValAttribute = 128,
70-
NestAttribute = 256,
71-
ReadNoneAttribute = 512,
72-
ReadOnlyAttribute = 1024,
73-
NoInlineAttribute = 2048,
74-
AlwaysInlineAttribute = 4096,
75-
OptimizeForSizeAttribute = 8192,
76-
StackProtectAttribute = 16384,
77-
StackProtectReqAttribute = 32768,
78-
// 31 << 16
79-
AlignmentAttribute = 2031616,
80-
NoCaptureAttribute = 2097152,
81-
NoRedZoneAttribute = 4194304,
82-
NoImplicitFloatAttribute = 8388608,
83-
NakedAttribute = 16777216,
84-
InlineHintAttribute = 33554432,
85-
// 7 << 26
86-
StackAttribute = 469762048,
87-
ReturnsTwiceAttribute = 536870912,
88-
// 1 << 30
89-
UWTableAttribute = 1073741824,
90-
NonLazyBindAttribute = 2147483648,
62+
ZExtAttribute = 1 << 0,
63+
SExtAttribute = 1 << 1,
64+
NoReturnAttribute = 1 << 2,
65+
InRegAttribute = 1 << 3,
66+
StructRetAttribute = 1 << 4,
67+
NoUnwindAttribute = 1 << 5,
68+
NoAliasAttribute = 1 << 6,
69+
ByValAttribute = 1 << 7,
70+
NestAttribute = 1 << 8,
71+
ReadNoneAttribute = 1 << 9,
72+
ReadOnlyAttribute = 1 << 10,
73+
NoInlineAttribute = 1 << 11,
74+
AlwaysInlineAttribute = 1 << 12,
75+
OptimizeForSizeAttribute = 1 << 13,
76+
StackProtectAttribute = 1 << 14,
77+
StackProtectReqAttribute = 1 << 15,
78+
AlignmentAttribute = 31 << 16,
79+
NoCaptureAttribute = 1 << 21,
80+
NoRedZoneAttribute = 1 << 22,
81+
NoImplicitFloatAttribute = 1 << 23,
82+
NakedAttribute = 1 << 24,
83+
InlineHintAttribute = 1 << 25,
84+
StackAttribute = 7 << 26,
85+
ReturnsTwiceAttribute = 1 << 29,
86+
UWTableAttribute = 1 << 30,
87+
NonLazyBindAttribute = 1 << 31,
88+
89+
// Not added to LLVM yet, so may need to stay updated if LLVM changes.
90+
FixedStackSegment = 1 << 41,
9191
}
9292

9393
// enum for the LLVM IntPredicate type
@@ -2107,6 +2107,15 @@ pub fn ConstFCmp(Pred: RealPredicate, V1: ValueRef, V2: ValueRef) -> ValueRef {
21072107
llvm::LLVMConstFCmp(Pred as c_ushort, V1, V2)
21082108
}
21092109
}
2110+
2111+
pub fn SetFunctionAttribute(Fn: ValueRef, attr: Attribute) {
2112+
unsafe {
2113+
let attr = attr as u64;
2114+
let lower = attr & 0xffffffff;
2115+
let upper = (attr >> 32) & 0xffffffff;
2116+
llvm::LLVMAddFunctionAttr(Fn, lower as c_uint, upper as c_uint);
2117+
}
2118+
}
21102119
/* Memory-managed object interface to type handles. */
21112120

21122121
pub struct TypeNames {

src/librustc/middle/trans/base.rs

Lines changed: 7 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -419,46 +419,25 @@ pub fn get_tydesc(ccx: &mut CrateContext, t: ty::t) -> @mut tydesc_info {
419419
}
420420

421421
pub fn set_optimize_for_size(f: ValueRef) {
422-
unsafe {
423-
llvm::LLVMAddFunctionAttr(f,
424-
lib::llvm::OptimizeForSizeAttribute
425-
as c_uint,
426-
0);
427-
}
422+
lib::llvm::SetFunctionAttribute(f, lib::llvm::OptimizeForSizeAttribute)
428423
}
429424

430425
pub fn set_no_inline(f: ValueRef) {
431-
unsafe {
432-
llvm::LLVMAddFunctionAttr(f,
433-
lib::llvm::NoInlineAttribute as c_uint,
434-
0);
435-
}
426+
lib::llvm::SetFunctionAttribute(f, lib::llvm::NoInlineAttribute)
436427
}
437428

438429
pub fn set_no_unwind(f: ValueRef) {
439-
unsafe {
440-
llvm::LLVMAddFunctionAttr(f,
441-
lib::llvm::NoUnwindAttribute as c_uint,
442-
0);
443-
}
430+
lib::llvm::SetFunctionAttribute(f, lib::llvm::NoUnwindAttribute)
444431
}
445432

446433
// Tell LLVM to emit the information necessary to unwind the stack for the
447434
// function f.
448435
pub fn set_uwtable(f: ValueRef) {
449-
unsafe {
450-
llvm::LLVMAddFunctionAttr(f,
451-
lib::llvm::UWTableAttribute as c_uint,
452-
0);
453-
}
436+
lib::llvm::SetFunctionAttribute(f, lib::llvm::UWTableAttribute)
454437
}
455438

456439
pub fn set_inline_hint(f: ValueRef) {
457-
unsafe {
458-
llvm::LLVMAddFunctionAttr(f,
459-
lib::llvm::InlineHintAttribute as c_uint,
460-
0);
461-
}
440+
lib::llvm::SetFunctionAttribute(f, lib::llvm::InlineHintAttribute)
462441
}
463442

464443
pub fn set_inline_hint_if_appr(attrs: &[ast::Attribute],
@@ -473,17 +452,11 @@ pub fn set_inline_hint_if_appr(attrs: &[ast::Attribute],
473452
}
474453

475454
pub fn set_always_inline(f: ValueRef) {
476-
unsafe {
477-
llvm::LLVMAddFunctionAttr(f,
478-
lib::llvm::AlwaysInlineAttribute as c_uint,
479-
0);
480-
}
455+
lib::llvm::SetFunctionAttribute(f, lib::llvm::AlwaysInlineAttribute)
481456
}
482457

483458
pub fn set_fixed_stack_segment(f: ValueRef) {
484-
unsafe {
485-
llvm::LLVMAddFunctionAttr(f, 0, 1 << (39 - 32));
486-
}
459+
lib::llvm::SetFunctionAttribute(f, lib::llvm::FixedStackSegment)
487460
}
488461

489462
pub fn set_glue_inlining(f: ValueRef, t: ty::t) {

0 commit comments

Comments
 (0)