Skip to content

Commit 0f6cbca

Browse files
committed
Move uses of enum to bitflags!.
There are still others, but this is the first batch.
1 parent af3889f commit 0f6cbca

File tree

3 files changed

+36
-43
lines changed

3 files changed

+36
-43
lines changed

src/librustc/middle/trans/base.rs

+2-10
Original file line numberDiff line numberDiff line change
@@ -191,21 +191,13 @@ pub fn decl_fn(ccx: &CrateContext, name: &str, cc: llvm::CallConv,
191191
match ty::get(output).sty {
192192
// functions returning bottom may unwind, but can never return normally
193193
ty::ty_bot => {
194-
unsafe {
195-
llvm::LLVMAddFunctionAttribute(llfn,
196-
llvm::FunctionIndex as c_uint,
197-
llvm::NoReturnAttribute as uint64_t)
198-
}
194+
llvm::SetFunctionAttribute(llfn, llvm::NoReturnAttribute)
199195
}
200196
_ => {}
201197
}
202198

203199
if ccx.tcx().sess.opts.cg.no_redzone {
204-
unsafe {
205-
llvm::LLVMAddFunctionAttribute(llfn,
206-
llvm::FunctionIndex as c_uint,
207-
llvm::NoRedZoneAttribute as uint64_t)
208-
}
200+
llvm::SetFunctionAttribute(llfn, llvm::NoRedZoneAttribute)
209201
}
210202

211203
llvm::SetFunctionCallConv(llfn, cc);

src/librustc/middle/trans/foreign.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,7 @@ fn add_argument_attributes(tys: &ForeignTypes,
998998

999999
match tys.fn_ty.ret_ty.attr {
10001000
Some(attr) => unsafe {
1001-
llvm::LLVMAddFunctionAttribute(llfn, i as c_uint, attr as u64);
1001+
llvm::LLVMAddFunctionAttribute(llfn, i as c_uint, attr.bits() as u64);
10021002
},
10031003
None => {}
10041004
}
@@ -1014,7 +1014,7 @@ fn add_argument_attributes(tys: &ForeignTypes,
10141014

10151015
match arg_ty.attr {
10161016
Some(attr) => unsafe {
1017-
llvm::LLVMAddFunctionAttribute(llfn, i as c_uint, attr as u64);
1017+
llvm::LLVMAddFunctionAttribute(llfn, i as c_uint, attr.bits() as u64);
10181018
},
10191019
None => ()
10201020
}

src/librustc_llvm/lib.rs

+32-31
Original file line numberDiff line numberDiff line change
@@ -91,34 +91,35 @@ pub enum DiagnosticSeverity {
9191
Note,
9292
}
9393

94-
#[deriving(Clone)]
95-
pub enum Attribute {
96-
ZExtAttribute = 1 << 0,
97-
SExtAttribute = 1 << 1,
98-
NoReturnAttribute = 1 << 2,
99-
InRegAttribute = 1 << 3,
100-
StructRetAttribute = 1 << 4,
101-
NoUnwindAttribute = 1 << 5,
102-
NoAliasAttribute = 1 << 6,
103-
ByValAttribute = 1 << 7,
104-
NestAttribute = 1 << 8,
105-
ReadNoneAttribute = 1 << 9,
106-
ReadOnlyAttribute = 1 << 10,
107-
NoInlineAttribute = 1 << 11,
108-
AlwaysInlineAttribute = 1 << 12,
109-
OptimizeForSizeAttribute = 1 << 13,
110-
StackProtectAttribute = 1 << 14,
111-
StackProtectReqAttribute = 1 << 15,
112-
AlignmentAttribute = 31 << 16,
113-
NoCaptureAttribute = 1 << 21,
114-
NoRedZoneAttribute = 1 << 22,
115-
NoImplicitFloatAttribute = 1 << 23,
116-
NakedAttribute = 1 << 24,
117-
InlineHintAttribute = 1 << 25,
118-
StackAttribute = 7 << 26,
119-
ReturnsTwiceAttribute = 1 << 29,
120-
UWTableAttribute = 1 << 30,
121-
NonLazyBindAttribute = 1 << 31,
94+
bitflags! {
95+
flags Attribute : u32 {
96+
static ZExtAttribute = 1 << 0,
97+
static SExtAttribute = 1 << 1,
98+
static NoReturnAttribute = 1 << 2,
99+
static InRegAttribute = 1 << 3,
100+
static StructRetAttribute = 1 << 4,
101+
static NoUnwindAttribute = 1 << 5,
102+
static NoAliasAttribute = 1 << 6,
103+
static ByValAttribute = 1 << 7,
104+
static NestAttribute = 1 << 8,
105+
static ReadNoneAttribute = 1 << 9,
106+
static ReadOnlyAttribute = 1 << 10,
107+
static NoInlineAttribute = 1 << 11,
108+
static AlwaysInlineAttribute = 1 << 12,
109+
static OptimizeForSizeAttribute = 1 << 13,
110+
static StackProtectAttribute = 1 << 14,
111+
static StackProtectReqAttribute = 1 << 15,
112+
static AlignmentAttribute = 31 << 16,
113+
static NoCaptureAttribute = 1 << 21,
114+
static NoRedZoneAttribute = 1 << 22,
115+
static NoImplicitFloatAttribute = 1 << 23,
116+
static NakedAttribute = 1 << 24,
117+
static InlineHintAttribute = 1 << 25,
118+
static StackAttribute = 7 << 26,
119+
static ReturnsTwiceAttribute = 1 << 29,
120+
static UWTableAttribute = 1 << 30,
121+
static NonLazyBindAttribute = 1 << 31,
122+
}
122123
}
123124

124125
#[repr(u64)]
@@ -160,13 +161,13 @@ trait AttrHelper {
160161
impl AttrHelper for Attribute {
161162
fn apply_llfn(&self, idx: c_uint, llfn: ValueRef) {
162163
unsafe {
163-
LLVMAddFunctionAttribute(llfn, idx, *self as uint64_t);
164+
LLVMAddFunctionAttribute(llfn, idx, self.bits() as uint64_t);
164165
}
165166
}
166167

167168
fn apply_callsite(&self, idx: c_uint, callsite: ValueRef) {
168169
unsafe {
169-
LLVMAddCallSiteAttribute(callsite, idx, *self as uint64_t);
170+
LLVMAddCallSiteAttribute(callsite, idx, self.bits() as uint64_t);
170171
}
171172
}
172173
}
@@ -2009,7 +2010,7 @@ pub fn ConstFCmp(pred: RealPredicate, v1: ValueRef, v2: ValueRef) -> ValueRef {
20092010

20102011
pub fn SetFunctionAttribute(fn_: ValueRef, attr: Attribute) {
20112012
unsafe {
2012-
LLVMAddFunctionAttribute(fn_, FunctionIndex as c_uint, attr as uint64_t)
2013+
LLVMAddFunctionAttribute(fn_, FunctionIndex as c_uint, attr.bits() as uint64_t)
20132014
}
20142015
}
20152016

0 commit comments

Comments
 (0)