Skip to content

Move uses of enum to bitflags!. #17250

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

Merged
merged 1 commit into from
Sep 20, 2014
Merged
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
12 changes: 2 additions & 10 deletions src/librustc/middle/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,21 +191,13 @@ pub fn decl_fn(ccx: &CrateContext, name: &str, cc: llvm::CallConv,
match ty::get(output).sty {
// functions returning bottom may unwind, but can never return normally
ty::ty_bot => {
unsafe {
llvm::LLVMAddFunctionAttribute(llfn,
llvm::FunctionIndex as c_uint,
llvm::NoReturnAttribute as uint64_t)
}
llvm::SetFunctionAttribute(llfn, llvm::NoReturnAttribute)
}
_ => {}
}

if ccx.tcx().sess.opts.cg.no_redzone {
unsafe {
llvm::LLVMAddFunctionAttribute(llfn,
llvm::FunctionIndex as c_uint,
llvm::NoRedZoneAttribute as uint64_t)
}
llvm::SetFunctionAttribute(llfn, llvm::NoRedZoneAttribute)
}

llvm::SetFunctionCallConv(llfn, cc);
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 @@ -998,7 +998,7 @@ fn add_argument_attributes(tys: &ForeignTypes,

match tys.fn_ty.ret_ty.attr {
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 => {}
}
Expand All @@ -1014,7 +1014,7 @@ fn add_argument_attributes(tys: &ForeignTypes,

match arg_ty.attr {
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 => ()
}
Expand Down
63 changes: 32 additions & 31 deletions src/librustc_llvm/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,34 +91,35 @@ pub enum DiagnosticSeverity {
Note,
}

#[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,
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This appears to be the only use of actual bit flags in LLVM apis, why make the other apis also move to the rust bitflags api?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was going off of this https://gist.github.com/aturon/c20615b26fb31c337afd list and replaced them all on 'autopilot' without really considering what bitflags is meant to do. Anyways, makes complete sense now.


#[repr(u64)]
Expand Down Expand Up @@ -160,13 +161,13 @@ trait AttrHelper {
impl AttrHelper for Attribute {
fn apply_llfn(&self, idx: c_uint, llfn: ValueRef) {
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) {
unsafe {
LLVMAddCallSiteAttribute(callsite, idx, *self as uint64_t);
LLVMAddCallSiteAttribute(callsite, idx, self.bits() as uint64_t);
}
}
}
Expand Down Expand Up @@ -2009,7 +2010,7 @@ pub fn ConstFCmp(pred: RealPredicate, v1: ValueRef, v2: ValueRef) -> ValueRef {

pub fn SetFunctionAttribute(fn_: ValueRef, attr: Attribute) {
unsafe {
LLVMAddFunctionAttribute(fn_, FunctionIndex as c_uint, attr as uint64_t)
LLVMAddFunctionAttribute(fn_, FunctionIndex as c_uint, attr.bits() as uint64_t)
}
}

Expand Down