rollup merge of #17250 : ahmedcharles/bitflags

This commit is contained in:
Alex Crichton 2014-09-19 10:00:10 -07:00
commit 0e5cb75766
3 changed files with 36 additions and 43 deletions

View File

@ -191,21 +191,13 @@ pub fn decl_fn(ccx: &CrateContext, name: &str, cc: llvm::CallConv,
match ty::get(output).sty { match ty::get(output).sty {
// functions returning bottom may unwind, but can never return normally // functions returning bottom may unwind, but can never return normally
ty::ty_bot => { ty::ty_bot => {
unsafe { llvm::SetFunctionAttribute(llfn, llvm::NoReturnAttribute)
llvm::LLVMAddFunctionAttribute(llfn,
llvm::FunctionIndex as c_uint,
llvm::NoReturnAttribute as uint64_t)
}
} }
_ => {} _ => {}
} }
if ccx.tcx().sess.opts.cg.no_redzone { if ccx.tcx().sess.opts.cg.no_redzone {
unsafe { llvm::SetFunctionAttribute(llfn, llvm::NoRedZoneAttribute)
llvm::LLVMAddFunctionAttribute(llfn,
llvm::FunctionIndex as c_uint,
llvm::NoRedZoneAttribute as uint64_t)
}
} }
llvm::SetFunctionCallConv(llfn, cc); llvm::SetFunctionCallConv(llfn, cc);

View File

@ -998,7 +998,7 @@ fn add_argument_attributes(tys: &ForeignTypes,
match tys.fn_ty.ret_ty.attr { match tys.fn_ty.ret_ty.attr {
Some(attr) => unsafe { Some(attr) => unsafe {
llvm::LLVMAddFunctionAttribute(llfn, i as c_uint, attr as u64); llvm::LLVMAddFunctionAttribute(llfn, i as c_uint, attr.bits() as u64);
}, },
None => {} None => {}
} }
@ -1014,7 +1014,7 @@ fn add_argument_attributes(tys: &ForeignTypes,
match arg_ty.attr { match arg_ty.attr {
Some(attr) => unsafe { Some(attr) => unsafe {
llvm::LLVMAddFunctionAttribute(llfn, i as c_uint, attr as u64); llvm::LLVMAddFunctionAttribute(llfn, i as c_uint, attr.bits() as u64);
}, },
None => () None => ()
} }

View File

@ -91,34 +91,35 @@ pub enum DiagnosticSeverity {
Note, Note,
} }
#[deriving(Clone)] bitflags! {
pub enum Attribute { flags Attribute : u32 {
ZExtAttribute = 1 << 0, static ZExtAttribute = 1 << 0,
SExtAttribute = 1 << 1, static SExtAttribute = 1 << 1,
NoReturnAttribute = 1 << 2, static NoReturnAttribute = 1 << 2,
InRegAttribute = 1 << 3, static InRegAttribute = 1 << 3,
StructRetAttribute = 1 << 4, static StructRetAttribute = 1 << 4,
NoUnwindAttribute = 1 << 5, static NoUnwindAttribute = 1 << 5,
NoAliasAttribute = 1 << 6, static NoAliasAttribute = 1 << 6,
ByValAttribute = 1 << 7, static ByValAttribute = 1 << 7,
NestAttribute = 1 << 8, static NestAttribute = 1 << 8,
ReadNoneAttribute = 1 << 9, static ReadNoneAttribute = 1 << 9,
ReadOnlyAttribute = 1 << 10, static ReadOnlyAttribute = 1 << 10,
NoInlineAttribute = 1 << 11, static NoInlineAttribute = 1 << 11,
AlwaysInlineAttribute = 1 << 12, static AlwaysInlineAttribute = 1 << 12,
OptimizeForSizeAttribute = 1 << 13, static OptimizeForSizeAttribute = 1 << 13,
StackProtectAttribute = 1 << 14, static StackProtectAttribute = 1 << 14,
StackProtectReqAttribute = 1 << 15, static StackProtectReqAttribute = 1 << 15,
AlignmentAttribute = 31 << 16, static AlignmentAttribute = 31 << 16,
NoCaptureAttribute = 1 << 21, static NoCaptureAttribute = 1 << 21,
NoRedZoneAttribute = 1 << 22, static NoRedZoneAttribute = 1 << 22,
NoImplicitFloatAttribute = 1 << 23, static NoImplicitFloatAttribute = 1 << 23,
NakedAttribute = 1 << 24, static NakedAttribute = 1 << 24,
InlineHintAttribute = 1 << 25, static InlineHintAttribute = 1 << 25,
StackAttribute = 7 << 26, static StackAttribute = 7 << 26,
ReturnsTwiceAttribute = 1 << 29, static ReturnsTwiceAttribute = 1 << 29,
UWTableAttribute = 1 << 30, static UWTableAttribute = 1 << 30,
NonLazyBindAttribute = 1 << 31, static NonLazyBindAttribute = 1 << 31,
}
} }
#[repr(u64)] #[repr(u64)]
@ -160,13 +161,13 @@ trait AttrHelper {
impl AttrHelper for Attribute { impl AttrHelper for Attribute {
fn apply_llfn(&self, idx: c_uint, llfn: ValueRef) { fn apply_llfn(&self, idx: c_uint, llfn: ValueRef) {
unsafe { unsafe {
LLVMAddFunctionAttribute(llfn, idx, *self as uint64_t); LLVMAddFunctionAttribute(llfn, idx, self.bits() as uint64_t);
} }
} }
fn apply_callsite(&self, idx: c_uint, callsite: ValueRef) { fn apply_callsite(&self, idx: c_uint, callsite: ValueRef) {
unsafe { unsafe {
LLVMAddCallSiteAttribute(callsite, idx, *self as uint64_t); LLVMAddCallSiteAttribute(callsite, idx, self.bits() as uint64_t);
} }
} }
} }
@ -2009,7 +2010,7 @@ pub fn ConstFCmp(pred: RealPredicate, v1: ValueRef, v2: ValueRef) -> ValueRef {
pub fn SetFunctionAttribute(fn_: ValueRef, attr: Attribute) { pub fn SetFunctionAttribute(fn_: ValueRef, attr: Attribute) {
unsafe { unsafe {
LLVMAddFunctionAttribute(fn_, FunctionIndex as c_uint, attr as uint64_t) LLVMAddFunctionAttribute(fn_, FunctionIndex as c_uint, attr.bits() as uint64_t)
} }
} }