From a792ecbaf21e5a4e4114c5740d70606a3a0340b8 Mon Sep 17 00:00:00 2001 From: David Nadlinger Date: Thu, 9 May 2013 22:55:38 +0200 Subject: [PATCH] Fix function attribute handling on LLVM 3.3+. The issue was that when merging in the old attributes, attrs wasn't assigned to, thus silently dropping all of them (leading e.g. to noinline being omitted on functions containing inline asm). The new code hopefully also makes the intent clearer. --- gen/functions.cpp | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/gen/functions.cpp b/gen/functions.cpp index 3d5f84c3..bee0c17f 100644 --- a/gen/functions.cpp +++ b/gen/functions.cpp @@ -552,7 +552,10 @@ void DtoResolveFunction(FuncDeclaration* fdecl) #if LDC_LLVM_VER >= 303 static void set_param_attrs(TypeFunction* f, llvm::Function* func, FuncDeclaration* fdecl) { - llvm::AttributeSet attrs; + llvm::AttributeSet old = func->getAttributes(); + llvm::AttributeSet existingAttrs[] = { old.getFnAttributes(), old.getRetAttributes() }; + llvm::AttributeSet newAttrs = llvm::AttributeSet::get(gIR->context(), existingAttrs); + int idx = 0; // handle implicit args @@ -560,7 +563,7 @@ static void set_param_attrs(TypeFunction* f, llvm::Function* func, FuncDeclarati if (f->fty.X) { \ if (f->fty.X->attrs.hasAttributes()) { \ llvm::AttributeSet a = llvm::AttributeSet::get(gIR->context(), idx, f->fty.X->attrs); \ - attrs = attrs.addAttributes(gIR->context(), idx, a); \ + newAttrs = newAttrs.addAttributes(gIR->context(), idx, a); \ } \ idx++; \ } @@ -586,20 +589,12 @@ static void set_param_attrs(TypeFunction* f, llvm::Function* func, FuncDeclarati { unsigned i = idx + (f->fty.reverseParams ? n-k-1 : k); llvm::AttributeSet as = llvm::AttributeSet::get(gIR->context(), i, a); - attrs = attrs.addAttributes(gIR->context(), i, as); + newAttrs = newAttrs.addAttributes(gIR->context(), i, as); } } - // Merge in any old attributes (attributes for the function itself are - // also stored in a list slot). - llvm::AttributeSet oldAttrs = func->getAttributes(); - for (size_t i = 0; i < oldAttrs.getNumSlots(); ++i) { - attrs.addAttributes(gIR->context(), oldAttrs.getSlotIndex(i), - oldAttrs.getSlotAttributes(i)); - } - // Store the final attribute set - func->setAttributes(attrs); + func->setAttributes(newAttrs); } #else static void set_param_attrs(TypeFunction* f, llvm::Function* func, FuncDeclaration* fdecl)