]> git.proxmox.com Git - rustc.git/blobdiff - src/librustc_trans/trans/attributes.rs
Imported Upstream version 1.1.0+dfsg1
[rustc.git] / src / librustc_trans / trans / attributes.rs
index 2615490a9fbc5a584b4b0b7f0fe525df9a0323fb..132947e34d795e052da61c5214e1960077ad4668 100644 (file)
@@ -39,13 +39,13 @@ pub fn split_stack(val: ValueRef, set: bool) {
 pub fn inline(val: ValueRef, inline: InlineAttr) {
     use self::InlineAttr::*;
     match inline {
-        Hint   => llvm::SetFunctionAttribute(val, llvm::InlineHintAttribute),
-        Always => llvm::SetFunctionAttribute(val, llvm::AlwaysInlineAttribute),
-        Never  => llvm::SetFunctionAttribute(val, llvm::NoInlineAttribute),
+        Hint   => llvm::SetFunctionAttribute(val, llvm::Attribute::InlineHint),
+        Always => llvm::SetFunctionAttribute(val, llvm::Attribute::AlwaysInline),
+        Never  => llvm::SetFunctionAttribute(val, llvm::Attribute::NoInline),
         None   => {
-            let attr = llvm::InlineHintAttribute |
-                       llvm::AlwaysInlineAttribute |
-                       llvm::NoInlineAttribute;
+            let attr = llvm::Attribute::InlineHint |
+                       llvm::Attribute::AlwaysInline |
+                       llvm::Attribute::NoInline;
             unsafe {
                 llvm::LLVMRemoveFunctionAttr(val, attr.bits() as c_ulonglong)
             }
@@ -57,10 +57,13 @@ pub fn inline(val: ValueRef, inline: InlineAttr) {
 #[inline]
 pub fn emit_uwtable(val: ValueRef, emit: bool) {
     if emit {
-        llvm::SetFunctionAttribute(val, llvm::UWTableAttribute);
+        llvm::SetFunctionAttribute(val, llvm::Attribute::UWTable);
     } else {
         unsafe {
-            llvm::LLVMRemoveFunctionAttr(val, llvm::UWTableAttribute.bits() as c_ulonglong);
+            llvm::LLVMRemoveFunctionAttr(
+                val,
+                llvm::Attribute::UWTable.bits() as c_ulonglong,
+            );
         }
     }
 }
@@ -71,10 +74,13 @@ pub fn emit_uwtable(val: ValueRef, emit: bool) {
 pub fn unwind(val: ValueRef, can_unwind: bool) {
     if can_unwind {
         unsafe {
-            llvm::LLVMRemoveFunctionAttr(val, llvm::NoUnwindAttribute.bits() as c_ulonglong);
+            llvm::LLVMRemoveFunctionAttr(
+                val,
+                llvm::Attribute::NoUnwind.bits() as c_ulonglong,
+            );
         }
     } else {
-        llvm::SetFunctionAttribute(val, llvm::NoUnwindAttribute);
+        llvm::SetFunctionAttribute(val, llvm::Attribute::NoUnwind);
     }
 }
 
@@ -83,10 +89,13 @@ pub fn unwind(val: ValueRef, can_unwind: bool) {
 #[allow(dead_code)] // possibly useful function
 pub fn set_optimize_for_size(val: ValueRef, optimize: bool) {
     if optimize {
-        llvm::SetFunctionAttribute(val, llvm::OptimizeForSizeAttribute);
+        llvm::SetFunctionAttribute(val, llvm::Attribute::OptimizeForSize);
     } else {
         unsafe {
-            llvm::LLVMRemoveFunctionAttr(val, llvm::OptimizeForSizeAttribute.bits() as c_ulonglong);
+            llvm::LLVMRemoveFunctionAttr(
+                val,
+                llvm::Attribute::OptimizeForSize.bits() as c_ulonglong,
+            );
         }
     }
 }
@@ -107,7 +116,7 @@ pub fn from_fn_attrs(ccx: &CrateContext, attrs: &[ast::Attribute], llfn: ValueRe
                                                llvm::ColdAttribute as u64)
             }
         } else if attr.check_name("allocator") {
-            llvm::NoAliasAttribute.apply_llfn(llvm::ReturnIndex as c_uint, llfn);
+            llvm::Attribute::NoAlias.apply_llfn(llvm::ReturnIndex as c_uint, llfn);
         }
     }
 }
@@ -176,9 +185,9 @@ pub fn from_fn_type<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fn_type: ty::Ty<'tcx
             // The outptr can be noalias and nocapture because it's entirely
             // invisible to the program. We also know it's nonnull as well
             // as how many bytes we can dereference
-            attrs.arg(1, llvm::StructRetAttribute)
-                 .arg(1, llvm::NoAliasAttribute)
-                 .arg(1, llvm::NoCaptureAttribute)
+            attrs.arg(1, llvm::Attribute::StructRet)
+                 .arg(1, llvm::Attribute::NoAlias)
+                 .arg(1, llvm::Attribute::NoCapture)
                  .arg(1, llvm::DereferenceableAttribute(llret_sz));
 
             // Add one more since there's an outptr
@@ -187,10 +196,10 @@ pub fn from_fn_type<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fn_type: ty::Ty<'tcx
             // The `noalias` attribute on the return value is useful to a
             // function ptr caller.
             match ret_ty.sty {
-                // `~` pointer return values never alias because ownership
+                // `Box` pointer return values never alias because ownership
                 // is transferred
                 ty::ty_uniq(it) if common::type_is_sized(ccx.tcx(), it) => {
-                    attrs.ret(llvm::NoAliasAttribute);
+                    attrs.ret(llvm::Attribute::NoAlias);
                 }
                 _ => {}
             }
@@ -207,7 +216,7 @@ pub fn from_fn_type<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fn_type: ty::Ty<'tcx
             }
 
             if let ty::ty_bool = ret_ty.sty {
-                attrs.ret(llvm::ZExtAttribute);
+                attrs.ret(llvm::Attribute::ZExt);
             }
         }
     }
@@ -221,20 +230,20 @@ pub fn from_fn_type<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fn_type: ty::Ty<'tcx
                 // For non-immediate arguments the callee gets its own copy of
                 // the value on the stack, so there are no aliases. It's also
                 // program-invisible so can't possibly capture
-                attrs.arg(idx, llvm::NoAliasAttribute)
-                     .arg(idx, llvm::NoCaptureAttribute)
+                attrs.arg(idx, llvm::Attribute::NoAlias)
+                     .arg(idx, llvm::Attribute::NoCapture)
                      .arg(idx, llvm::DereferenceableAttribute(llarg_sz));
             }
 
             ty::ty_bool => {
-                attrs.arg(idx, llvm::ZExtAttribute);
+                attrs.arg(idx, llvm::Attribute::ZExt);
             }
 
-            // `~` pointer parameters never alias because ownership is transferred
+            // `Box` pointer parameters never alias because ownership is transferred
             ty::ty_uniq(inner) => {
                 let llsz = machine::llsize_of_real(ccx, type_of::type_of(ccx, inner));
 
-                attrs.arg(idx, llvm::NoAliasAttribute)
+                attrs.arg(idx, llvm::Attribute::NoAlias)
                      .arg(idx, llvm::DereferenceableAttribute(llsz));
             }
 
@@ -247,15 +256,15 @@ pub fn from_fn_type<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fn_type: ty::Ty<'tcx
                                   !ty::type_contents(ccx.tcx(), mt.ty).interior_unsafe() => {
 
                 let llsz = machine::llsize_of_real(ccx, type_of::type_of(ccx, mt.ty));
-                attrs.arg(idx, llvm::NoAliasAttribute)
+                attrs.arg(idx, llvm::Attribute::NoAlias)
                      .arg(idx, llvm::DereferenceableAttribute(llsz));
 
                 if mt.mutbl == ast::MutImmutable {
-                    attrs.arg(idx, llvm::ReadOnlyAttribute);
+                    attrs.arg(idx, llvm::Attribute::ReadOnly);
                 }
 
                 if let ReLateBound(_, BrAnon(_)) = *b {
-                    attrs.arg(idx, llvm::NoCaptureAttribute);
+                    attrs.arg(idx, llvm::Attribute::NoCapture);
                 }
             }
 
@@ -263,7 +272,7 @@ pub fn from_fn_type<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fn_type: ty::Ty<'tcx
             // reference to escape this function (returned or stored beyond the call by a closure).
             ty::ty_rptr(&ReLateBound(_, BrAnon(_)), mt) => {
                 let llsz = machine::llsize_of_real(ccx, type_of::type_of(ccx, mt.ty));
-                attrs.arg(idx, llvm::NoCaptureAttribute)
+                attrs.arg(idx, llvm::Attribute::NoCapture)
                      .arg(idx, llvm::DereferenceableAttribute(llsz));
             }