From 9081102f24f546277126b25819fe447b8696402b Mon Sep 17 00:00:00 2001 From: kai Date: Sat, 2 Feb 2013 14:57:01 +0100 Subject: [PATCH] Use AttrBuilder for LLVM >= 3.2. Due to a misunderstanding of the new semantics of the Attribute(s) class, this class was used in places where class AttrBuilder should be used. --- gen/functions.cpp | 37 ++++++++++++++++++++++--------------- gen/tollvm.cpp | 16 +++++++++------- gen/tollvm.h | 4 +++- 3 files changed, 34 insertions(+), 23 deletions(-) diff --git a/gen/functions.cpp b/gen/functions.cpp index 7a206a30..eb558613 100644 --- a/gen/functions.cpp +++ b/gen/functions.cpp @@ -72,10 +72,8 @@ llvm::FunctionType* DtoFunctionType(Type* type, Type* thistype, Type* nesttype, else { Type* rt = f->next; -#if LDC_LLVM_VER >= 303 - llvm::Attribute a; -#elif LDC_LLVM_VER == 302 - llvm::Attributes a; +#if LDC_LLVM_VER >= 302 + llvm::AttrBuilder attrBuilder; #else llvm::Attributes a = None; #endif @@ -121,8 +119,17 @@ llvm::FunctionType* DtoFunctionType(Type* type, Type* thistype, Type* nesttype, if (f->isref) t = t->pointerTo(); #endif +#if LDC_LLVM_VER >= 302 + attrBuilder.addAttribute(DtoShouldExtend(t)); +#else a = DtoShouldExtend(t); +#endif } +#if LDC_LLVM_VER >= 303 + llvm::Attribute a = llvm::Attribute::get(gIR->context(), attrBuilder); +#elif LDC_LLVM_VER == 302 + llvm::Attributes a = llvm::Attributes::get(gIR->context(), attrBuilder); +#endif #if DMDV2 fty.ret = new IrFuncTyArg(rt, f->isref, a); #else @@ -202,10 +209,8 @@ llvm::FunctionType* DtoFunctionType(Type* type, Type* thistype, Type* nesttype, #endif Type* argtype = arg->type; -#if LDC_LLVM_VER >= 303 - llvm::Attribute a; -#elif LDC_LLVM_VER == 302 - llvm::Attributes a; +#if LDC_LLVM_VER >= 302 + llvm::AttrBuilder attrBuilder; #else llvm::Attributes a = None; #endif @@ -222,9 +227,9 @@ llvm::FunctionType* DtoFunctionType(Type* type, Type* thistype, Type* nesttype, else if (abi->passByVal(byref ? argtype->pointerTo() : argtype)) { #if LDC_LLVM_VER >= 303 - if (!byref) a = llvm::Attribute::get(gIR->context(), llvm::AttrBuilder(a).addAttribute(llvm::Attribute::ByVal)); + if (!byref) attrBuilder.addAttribute(llvm::Attribute::ByVal); #elif LDC_LLVM_VER == 302 - if (!byref) a = llvm::Attributes::get(gIR->context(), llvm::AttrBuilder(a).addAttribute(llvm::Attributes::ByVal)); + if (!byref) attrBuilder.addAttribute(llvm::Attributes::ByVal); #else if (!byref) a |= llvm::Attribute::ByVal; #endif @@ -234,15 +239,17 @@ llvm::FunctionType* DtoFunctionType(Type* type, Type* thistype, Type* nesttype, // sext/zext else if (!byref) { -#if LDC_LLVM_VER >= 303 - a = llvm::Attribute::get(gIR->context(), llvm::AttrBuilder(a).addAttributes(DtoShouldExtend(argtype))); -#elif LDC_LLVM_VER == 302 - a = llvm::Attributes::get(gIR->context(), llvm::AttrBuilder(a).addAttributes(DtoShouldExtend(argtype))); +#if LDC_LLVM_VER >= 302 + attrBuilder.addAttribute(DtoShouldExtend(argtype)); #else a |= DtoShouldExtend(argtype); #endif } - +#if LDC_LLVM_VER >= 303 + llvm::Attribute a = llvm::Attribute::get(gIR->context(), attrBuilder); +#elif LDC_LLVM_VER == 302 + llvm::Attributes a = llvm::Attributes::get(gIR->context(), attrBuilder); +#endif fty.args.push_back(new IrFuncTyArg(argtype, byref, a)); lidx++; } diff --git a/gen/tollvm.cpp b/gen/tollvm.cpp index 7834bcec..28ce5d96 100644 --- a/gen/tollvm.cpp +++ b/gen/tollvm.cpp @@ -43,7 +43,9 @@ bool DtoIsPassedByRef(Type* type) } #if LDC_LLVM_VER >= 303 -llvm::Attribute DtoShouldExtend(Type* type) +llvm::Attribute::AttrKind DtoShouldExtend(Type* type) +#elif LDC_LLVM_VER == 302 +llvm::Attributes::AttrVal DtoShouldExtend(Type* type) #else llvm::Attributes DtoShouldExtend(Type* type) #endif @@ -56,9 +58,9 @@ llvm::Attributes DtoShouldExtend(Type* type) case Tint8: case Tint16: #if LDC_LLVM_VER >= 303 - return llvm::Attribute::get(gIR->context(), llvm::AttrBuilder().addAttribute(llvm::Attribute::SExt)); + return llvm::Attribute::SExt; #elif LDC_LLVM_VER == 302 - return llvm::Attributes::get(gIR->context(), llvm::AttrBuilder().addAttribute(llvm::Attributes::SExt)); + return llvm::Attributes::SExt; #else return llvm::Attribute::SExt; #endif @@ -66,18 +68,18 @@ llvm::Attributes DtoShouldExtend(Type* type) case Tuns8: case Tuns16: #if LDC_LLVM_VER >= 303 - return llvm::Attribute::get(gIR->context(), llvm::AttrBuilder().addAttribute(llvm::Attribute::ZExt)); + return llvm::Attribute::ZExt; #elif LDC_LLVM_VER == 302 - return llvm::Attributes::get(gIR->context(), llvm::AttrBuilder().addAttribute(llvm::Attributes::ZExt)); + return llvm::Attributes::ZExt; #else return llvm::Attribute::ZExt; #endif } } #if LDC_LLVM_VER >= 303 - return llvm::Attribute(); + return llvm::Attribute::None; #elif LDC_LLVM_VER == 302 - return llvm::Attributes(); + return llvm::Attributes::None; #else return llvm::Attribute::None; #endif diff --git a/gen/tollvm.h b/gen/tollvm.h index 0cd00dab..1e553931 100644 --- a/gen/tollvm.h +++ b/gen/tollvm.h @@ -35,7 +35,9 @@ bool DtoIsPassedByRef(Type* type); // should argument be zero or sign extended #if LDC_LLVM_VER >= 303 -llvm::Attribute DtoShouldExtend(Type* type); +llvm::Attribute::AttrKind DtoShouldExtend(Type* type); +#elif LDC_LLVM_VER == 302 +llvm::Attributes::AttrVal DtoShouldExtend(Type* type); #else llvm::Attributes DtoShouldExtend(Type* type); #endif