Skip to content

Commit 3cae434

Browse files
committed
librustc: Consolidate the attribute handling for tagging function arguments and returns.
1 parent 90eeb92 commit 3cae434

File tree

11 files changed

+276
-314
lines changed

11 files changed

+276
-314
lines changed

src/librustc/lib/llvm.rs

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use std::c_str::ToCStr;
1616
use std::cell::RefCell;
1717
use collections::HashMap;
18-
use libc::{c_uint, c_ushort, c_void, free};
18+
use libc::{c_uint, c_ushort, c_void, free, uint64_t};
1919
use std::str::raw::from_c_str;
2020

2121
use middle::trans::type_::Type;
@@ -92,6 +92,33 @@ pub enum Attribute {
9292
NonLazyBindAttribute = 1 << 31,
9393
}
9494

95+
#[repr(u64)]
96+
pub enum OtherAttribute {
97+
// The following are not really exposed in
98+
// the LLVM c api so instead to add these
99+
// we call a wrapper function in RustWrapper
100+
// that uses the C++ api.
101+
SanitizeAddressAttribute = 1 << 32,
102+
MinSizeAttribute = 1 << 33,
103+
NoDuplicateAttribute = 1 << 34,
104+
StackProtectStrongAttribute = 1 << 35,
105+
SanitizeThreadAttribute = 1 << 36,
106+
SanitizeMemoryAttribute = 1 << 37,
107+
NoBuiltinAttribute = 1 << 38,
108+
ReturnedAttribute = 1 << 39,
109+
ColdAttribute = 1 << 40,
110+
BuiltinAttribute = 1 << 41,
111+
OptimizeNoneAttribute = 1 << 42,
112+
InAllocaAttribute = 1 << 43,
113+
NonNullAttribute = 1 << 44,
114+
}
115+
116+
#[repr(C)]
117+
pub enum AttributeSet {
118+
ReturnIndex = 0,
119+
FunctionIndex = !0
120+
}
121+
95122
// enum for the LLVM IntPredicate type
96123
pub enum IntPredicate {
97124
IntEQ = 32,
@@ -308,7 +335,7 @@ pub mod llvm {
308335
use super::{CodeGenModel, RelocMode, CodeGenOptLevel};
309336
use super::debuginfo::*;
310337
use libc::{c_char, c_int, c_longlong, c_ushort, c_uint, c_ulonglong,
311-
size_t};
338+
size_t, uint64_t};
312339

313340
// Link to our native llvm bindings (things that we need to use the C++ api
314341
// for) and because llvm is written in C++ we need to link against libstdc++
@@ -706,23 +733,11 @@ pub mod llvm {
706733
pub fn LLVMSetFunctionCallConv(Fn: ValueRef, CC: c_uint);
707734
pub fn LLVMGetGC(Fn: ValueRef) -> *c_char;
708735
pub fn LLVMSetGC(Fn: ValueRef, Name: *c_char);
709-
pub fn LLVMAddFunctionAttr(Fn: ValueRef, PA: c_uint);
710-
pub fn LLVMAddFunctionAttrString(Fn: ValueRef, Name: *c_char);
711-
pub fn LLVMRemoveFunctionAttrString(Fn: ValueRef, Name: *c_char);
736+
pub fn LLVMAddFunctionAttribute(Fn: ValueRef, index: c_uint, PA: uint64_t);
737+
pub fn LLVMAddFunctionAttrString(Fn: ValueRef, index: c_uint, Name: *c_char);
738+
pub fn LLVMRemoveFunctionAttrString(Fn: ValueRef, index: c_uint, Name: *c_char);
712739
pub fn LLVMGetFunctionAttr(Fn: ValueRef) -> c_ulonglong;
713740

714-
pub fn LLVMAddReturnAttribute(Fn: ValueRef, PA: c_uint);
715-
pub fn LLVMRemoveReturnAttribute(Fn: ValueRef, PA: c_uint);
716-
717-
pub fn LLVMAddColdAttribute(Fn: ValueRef);
718-
719-
pub fn LLVMAddNonNullAttribute(Arg: ValueRef);
720-
pub fn LLVMAddNonNullReturnAttribute(Fn: ValueRef);
721-
722-
pub fn LLVMRemoveFunctionAttr(Fn: ValueRef,
723-
PA: c_ulonglong,
724-
HighPA: c_ulonglong);
725-
726741
/* Operations on parameters */
727742
pub fn LLVMCountParams(Fn: ValueRef) -> c_uint;
728743
pub fn LLVMGetParams(Fn: ValueRef, Params: *ValueRef);
@@ -786,6 +801,9 @@ pub mod llvm {
786801
pub fn LLVMSetInstrParamAlignment(Instr: ValueRef,
787802
index: c_uint,
788803
align: c_uint);
804+
pub fn LLVMAddCallSiteAttribute(Instr: ValueRef,
805+
index: c_uint,
806+
Val: uint64_t);
789807

790808
/* Operations on call instructions (only) */
791809
pub fn LLVMIsTailCall(CallInst: ValueRef) -> Bool;
@@ -1838,7 +1856,7 @@ pub fn ConstFCmp(pred: RealPredicate, v1: ValueRef, v2: ValueRef) -> ValueRef {
18381856

18391857
pub fn SetFunctionAttribute(fn_: ValueRef, attr: Attribute) {
18401858
unsafe {
1841-
llvm::LLVMAddFunctionAttr(fn_, attr as c_uint)
1859+
llvm::LLVMAddFunctionAttribute(fn_, FunctionIndex as c_uint, attr as uint64_t)
18421860
}
18431861
}
18441862
/* Memory-managed object interface to type handles. */

0 commit comments

Comments
 (0)