diff --git a/src/librustc/lib/llvm.rs b/src/librustc/lib/llvm.rs index 0c874bd776ed1..c7010a4f90286 100644 --- a/src/librustc/lib/llvm.rs +++ b/src/librustc/lib/llvm.rs @@ -63,34 +63,34 @@ pub enum Linkage { } #[deriving(Clone)] -pub enum Attribute { - ZExtAttribute = 1 << 0, - SExtAttribute = 1 << 1, - NoReturnAttribute = 1 << 2, - InRegAttribute = 1 << 3, - StructRetAttribute = 1 << 4, - NoUnwindAttribute = 1 << 5, - NoAliasAttribute = 1 << 6, - ByValAttribute = 1 << 7, - NestAttribute = 1 << 8, - ReadNoneAttribute = 1 << 9, - ReadOnlyAttribute = 1 << 10, - NoInlineAttribute = 1 << 11, - AlwaysInlineAttribute = 1 << 12, - OptimizeForSizeAttribute = 1 << 13, - StackProtectAttribute = 1 << 14, - StackProtectReqAttribute = 1 << 15, - AlignmentAttribute = 31 << 16, - NoCaptureAttribute = 1 << 21, - NoRedZoneAttribute = 1 << 22, - NoImplicitFloatAttribute = 1 << 23, - NakedAttribute = 1 << 24, - InlineHintAttribute = 1 << 25, - StackAttribute = 7 << 26, - ReturnsTwiceAttribute = 1 << 29, - UWTableAttribute = 1 << 30, - NonLazyBindAttribute = 1 << 31, -} +bitflags!(flags Attribute: u32 { + static ZExtAttribute = 1 << 0, + static SExtAttribute = 1 << 1, + static NoReturnAttribute = 1 << 2, + static InRegAttribute = 1 << 3, + static StructRetAttribute = 1 << 4, + static NoUnwindAttribute = 1 << 5, + static NoAliasAttribute = 1 << 6, + static ByValAttribute = 1 << 7, + static NestAttribute = 1 << 8, + static ReadNoneAttribute = 1 << 9, + static ReadOnlyAttribute = 1 << 10, + static NoInlineAttribute = 1 << 11, + static AlwaysInlineAttribute = 1 << 12, + static OptimizeForSizeAttribute = 1 << 13, + static StackProtectAttribute = 1 << 14, + static StackProtectReqAttribute = 1 << 15, + static AlignmentAttribute = 31 << 16, + static NoCaptureAttribute = 1 << 21, + static NoRedZoneAttribute = 1 << 22, + static NoImplicitFloatAttribute = 1 << 23, + static NakedAttribute = 1 << 24, + static InlineHintAttribute = 1 << 25, + static StackAttribute = 7 << 26, + static ReturnsTwiceAttribute = 1 << 29, + static UWTableAttribute = 1 << 30, + static NonLazyBindAttribute = 1 << 31 +}) // enum for the LLVM IntPredicate type pub enum IntPredicate { @@ -1833,7 +1833,7 @@ pub fn ConstFCmp(pred: RealPredicate, v1: ValueRef, v2: ValueRef) -> ValueRef { pub fn SetFunctionAttribute(fn_: ValueRef, attr: Attribute) { unsafe { - llvm::LLVMAddFunctionAttr(fn_, attr as c_uint) + llvm::LLVMAddFunctionAttr(fn_, attr.bits as c_uint) } } /* Memory-managed object interface to type handles. */ diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index 17aa0664d4794..0d6d87ca68c67 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -176,14 +176,14 @@ fn decl_fn(llmod: ModuleRef, name: &str, cc: lib::llvm::CallConv, // functions returning bottom may unwind, but can never return normally ty::ty_bot => { unsafe { - llvm::LLVMAddFunctionAttr(llfn, lib::llvm::NoReturnAttribute as c_uint) + llvm::LLVMAddFunctionAttr(llfn, lib::llvm::NoReturnAttribute.bits() as c_uint) } } // `~` pointer return values never alias because ownership is transferred ty::ty_uniq(..) // | ty::ty_trait(_, _, ty::UniqTraitStore, _, _) => { unsafe { - llvm::LLVMAddReturnAttribute(llfn, lib::llvm::NoAliasAttribute as c_uint); + llvm::LLVMAddReturnAttribute(llfn, lib::llvm::NoAliasAttribute.bits() as c_uint); } } _ => {} @@ -257,13 +257,13 @@ pub fn decl_rust_fn(ccx: &CrateContext, has_env: bool, // `~` pointer parameters never alias because ownership is transferred ty::ty_uniq(..) => { unsafe { - llvm::LLVMAddAttribute(llarg, lib::llvm::NoAliasAttribute as c_uint); + llvm::LLVMAddAttribute(llarg, lib::llvm::NoAliasAttribute.bits() as c_uint); } } // `&mut` pointer parameters never alias other parameters, or mutable global data ty::ty_rptr(_, mt) if mt.mutbl == ast::MutMutable => { unsafe { - llvm::LLVMAddAttribute(llarg, lib::llvm::NoAliasAttribute as c_uint); + llvm::LLVMAddAttribute(llarg, lib::llvm::NoAliasAttribute.bits() as c_uint); } } // When a reference in an argument has no named lifetime, it's impossible for that @@ -271,7 +271,7 @@ pub fn decl_rust_fn(ccx: &CrateContext, has_env: bool, ty::ty_rptr(ReLateBound(_, BrAnon(_)), _) => { debug!("marking argument of {} as nocapture because of anonymous lifetime", name); unsafe { - llvm::LLVMAddAttribute(llarg, lib::llvm::NoCaptureAttribute as c_uint); + llvm::LLVMAddAttribute(llarg, lib::llvm::NoCaptureAttribute.bits() as c_uint); } } _ => { @@ -279,8 +279,8 @@ pub fn decl_rust_fn(ccx: &CrateContext, has_env: bool, // the value on the stack, so there are no aliases if !type_is_immediate(ccx, arg_ty) { unsafe { - llvm::LLVMAddAttribute(llarg, lib::llvm::NoAliasAttribute as c_uint); - llvm::LLVMAddAttribute(llarg, lib::llvm::NoCaptureAttribute as c_uint); + llvm::LLVMAddAttribute(llarg, lib::llvm::NoAliasAttribute.bits() as c_uint); + llvm::LLVMAddAttribute(llarg, lib::llvm::NoCaptureAttribute.bits() as c_uint); } } } @@ -293,8 +293,8 @@ pub fn decl_rust_fn(ccx: &CrateContext, has_env: bool, if uses_outptr { unsafe { let outptr = llvm::LLVMGetParam(llfn, 0); - llvm::LLVMAddAttribute(outptr, lib::llvm::StructRetAttribute as c_uint); - llvm::LLVMAddAttribute(outptr, lib::llvm::NoAliasAttribute as c_uint); + llvm::LLVMAddAttribute(outptr, lib::llvm::StructRetAttribute.bits() as c_uint); + llvm::LLVMAddAttribute(outptr, lib::llvm::NoAliasAttribute.bits() as c_uint); } } diff --git a/src/librustc/middle/trans/builder.rs b/src/librustc/middle/trans/builder.rs index 17667003506b1..a27a8aa9736a8 100644 --- a/src/librustc/middle/trans/builder.rs +++ b/src/librustc/middle/trans/builder.rs @@ -168,7 +168,7 @@ impl<'a> Builder<'a> { catch, noname()); for &(idx, attr) in attributes.iter() { - llvm::LLVMAddInstrAttribute(v, idx as c_uint, attr as c_uint); + llvm::LLVMAddInstrAttribute(v, idx as c_uint, attr.bits() as c_uint); } v } @@ -811,7 +811,7 @@ impl<'a> Builder<'a> { let v = llvm::LLVMBuildCall(self.llbuilder, llfn, args.as_ptr(), args.len() as c_uint, noname()); for &(idx, attr) in attributes.iter() { - llvm::LLVMAddInstrAttribute(v, idx as c_uint, attr as c_uint); + llvm::LLVMAddInstrAttribute(v, idx as c_uint, attr.bits() as c_uint); } v } diff --git a/src/librustc/middle/trans/foreign.rs b/src/librustc/middle/trans/foreign.rs index 2c4043a62f5fc..7c322e1b6542d 100644 --- a/src/librustc/middle/trans/foreign.rs +++ b/src/librustc/middle/trans/foreign.rs @@ -934,7 +934,7 @@ fn add_argument_attributes(tys: &ForeignTypes, Some(attr) => { let llarg = get_param(llfn, i); unsafe { - llvm::LLVMAddAttribute(llarg, attr as c_uint); + llvm::LLVMAddAttribute(llarg, attr.bits() as c_uint); } } None => {} @@ -954,7 +954,7 @@ fn add_argument_attributes(tys: &ForeignTypes, Some(attr) => { let llarg = get_param(llfn, i); unsafe { - llvm::LLVMAddAttribute(llarg, attr as c_uint); + llvm::LLVMAddAttribute(llarg, attr.bits() as c_uint); } } None => ()