Skip to content

Initial bitflags migration #14209

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 29 additions & 29 deletions src/librustc/lib/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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. */
Expand Down
18 changes: 9 additions & 9 deletions src/librustc/middle/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
_ => {}
Expand Down Expand Up @@ -257,30 +257,30 @@ 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
// reference to escape this function (returned or stored beyond the call by a closure).
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);
}
}
_ => {
// For non-immediate arguments the callee gets its own copy of
// 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);
}
}
}
Expand All @@ -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);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/trans/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/trans/foreign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {}
Expand All @@ -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 => ()
Expand Down