Merge pull request #5664 from lateralusX/lateralusX/mkbundle-windows-toolchains
[mono.git] / mono / mini / mini-llvm-cpp.cpp
index 6f05177546c51ec82f249feb33075c1549e9e816..253cd42ff81b93f61cfa49d1a40eac51737e1a82 100644 (file)
@@ -249,6 +249,7 @@ mono_llvm_set_call_notail (LLVMValueRef func)
 #endif
 }
 
+#if LLVM_API_VERSION > 500
 static Attribute::AttrKind
 convert_attr (AttrKind kind)
 {
@@ -274,6 +275,33 @@ convert_attr (AttrKind kind)
                return Attribute::NoUnwind;
        }
 }
+#else
+static LLVMAttribute
+convert_attr (AttrKind kind)
+{
+       switch (kind) {
+       case LLVM_ATTR_NO_UNWIND:
+               return LLVMNoUnwindAttribute;
+       case LLVM_ATTR_NO_INLINE:
+               return LLVMNoInlineAttribute;
+       case LLVM_ATTR_OPTIMIZE_FOR_SIZE:
+               return LLVMOptimizeForSizeAttribute;
+       case LLVM_ATTR_IN_REG:
+               return LLVMInRegAttribute;
+       case LLVM_ATTR_STRUCT_RET:
+               return LLVMStructRetAttribute;
+       case LLVM_ATTR_NO_ALIAS:
+               return LLVMNoAliasAttribute;
+       case LLVM_ATTR_BY_VAL:
+               return LLVMByValAttribute;
+       case LLVM_ATTR_UW_TABLE:
+               return LLVMUWTable;
+       default:
+               assert (0);
+               return LLVMNoUnwindAttribute;
+       }
+}
+#endif
 
 void
 mono_llvm_add_func_attr (LLVMValueRef func, AttrKind kind)
@@ -281,7 +309,14 @@ mono_llvm_add_func_attr (LLVMValueRef func, AttrKind kind)
 #if LLVM_API_VERSION > 100
        unwrap<Function> (func)->addAttribute (AttributeList::FunctionIndex, convert_attr (kind));
 #else
-       unwrap<Function> (func)->addFnAttr (convert_attr (kind));
+       Function *Func = unwrap<Function>(func);
+       const AttributeSet PAL = Func->getAttributes();
+       AttrBuilder B(convert_attr (kind));
+       const AttributeSet PALnew =
+               PAL.addAttributes(Func->getContext(), AttributeSet::FunctionIndex,
+                                                 AttributeSet::get(Func->getContext(),
+                                                                                       AttributeSet::FunctionIndex, B));
+       Func->setAttributes(PALnew);
 #endif
 }