[pkg-d-commits] [ldc] 83/95: Fix LLVM 5.0 compilation.

Matthias Klumpp mak at moszumanska.debian.org
Thu Jul 13 20:54:03 UTC 2017


This is an automated email from the git hooks/post-receive script.

mak pushed a commit to annotated tag v1.3.0-beta1
in repository ldc.

commit 64df1687a84b4185f9e0ec0d54cf527520fdbc20
Author: Johan Engelen <jbc.engelen at gmail.com>
Date:   Thu Apr 13 22:00:00 2017 +0200

    Fix LLVM 5.0 compilation.
---
 gen/attributes.cpp                  | 13 ++++++++-----
 gen/functions.cpp                   |  8 ++++++--
 gen/inlineir.cpp                    |  8 ++++++++
 gen/llvmhelpers.cpp                 | 15 ++++++++++++---
 gen/passes/GarbageCollect2Stack.cpp | 12 ++++++++++--
 gen/runtime.cpp                     |  6 ++++--
 gen/tocall.cpp                      |  2 +-
 gen/trycatchfinally.cpp             |  3 +++
 8 files changed, 52 insertions(+), 15 deletions(-)

diff --git a/gen/attributes.cpp b/gen/attributes.cpp
index 1525d6e..3a8a9f8 100644
--- a/gen/attributes.cpp
+++ b/gen/attributes.cpp
@@ -67,11 +67,14 @@ AttrSet::AttrSet(const AttrSet &base, unsigned index, LLAttribute attribute)
 AttrSet
 AttrSet::extractFunctionAndReturnAttributes(const llvm::Function *function) {
   auto old = function->getAttributes();
-  LLAttributeSet existingAttrs[] = {old.getFnAttributes(),
-                                    old.getRetAttributes()};
-  AttrSet r(LLAttributeSet::get(gIR->context(), existingAttrs));
-
-  return r;
+#if LDC_LLVM_VER >= 500
+  return {LLAttributeSet::get(gIR->context(), old.getFnAttributes(),
+                              old.getRetAttributes(), {})};
+#else
+  llvm::AttributeSet existingAttrs[] = {old.getFnAttributes(),
+                                        old.getRetAttributes()};
+  return {LLAttributeSet::get(gIR->context(), existingAttrs)};
+#endif
 }
 
 AttrSet &AttrSet::add(unsigned index, const AttrBuilder &builder) {
diff --git a/gen/functions.cpp b/gen/functions.cpp
index f5431b9..498455a 100644
--- a/gen/functions.cpp
+++ b/gen/functions.cpp
@@ -978,8 +978,12 @@ void DtoDefineFunction(FuncDeclaration *fd, bool linkageAvailableExternally) {
   // create alloca point
   // this gets erased when the function is complete, so alignment etc does not
   // matter at all
-  llvm::Instruction *allocaPoint = new llvm::AllocaInst(
-      LLType::getInt32Ty(gIR->context()), "alloca point", beginbb);
+  llvm::Instruction *allocaPoint =
+      new llvm::AllocaInst(LLType::getInt32Ty(gIR->context()),
+#if LDC_LLVM_VER >= 500
+                           0, // Address space
+#endif
+                           "alloca point", beginbb);
   funcGen.allocapoint = allocaPoint;
 
   // debug info - after all allocas, but before any llvm.dbg.declare etc
diff --git a/gen/inlineir.cpp b/gen/inlineir.cpp
index 66fac9a..806c311 100644
--- a/gen/inlineir.cpp
+++ b/gen/inlineir.cpp
@@ -35,10 +35,18 @@ struct TempDisableDiscardValueNames {
 };
 
 /// Adds the idol's function attributes to the wannabe
+/// Note: don't add function _parameter_ attributes
 void copyFnAttributes(llvm::Function *wannabe, llvm::Function *idol) {
   auto attrSet = idol->getAttributes();
   auto fnAttrSet = attrSet.getFnAttributes();
+#if LDC_LLVM_VER >= 500
+  wannabe->addAttributes(LLAttributeSet::FunctionIndex,
+                         LLAttributeSet::get(gIR->context(),
+                                             LLAttributeSet::FunctionIndex,
+                                             fnAttrSet));
+#else
   wannabe->addAttributes(LLAttributeSet::FunctionIndex, fnAttrSet);
+#endif
 }
 } // anonymous namespace
 
diff --git a/gen/llvmhelpers.cpp b/gen/llvmhelpers.cpp
index d866857..a82b7af 100644
--- a/gen/llvmhelpers.cpp
+++ b/gen/llvmhelpers.cpp
@@ -180,15 +180,24 @@ llvm::AllocaInst *DtoAlloca(VarDeclaration *vd, const char *name) {
 llvm::AllocaInst *DtoArrayAlloca(Type *type, unsigned arraysize,
                                  const char *name) {
   LLType *lltype = DtoType(type);
-  auto ai = new llvm::AllocaInst(lltype, DtoConstUint(arraysize), name,
-                                 gIR->topallocapoint());
+  auto ai = new llvm::AllocaInst(
+      lltype,
+#if LDC_LLVM_VER >= 500
+      gIR->module.getDataLayout().getAllocaAddrSpace(),
+#endif
+      DtoConstUint(arraysize), name, gIR->topallocapoint());
   ai->setAlignment(DtoAlignment(type));
   return ai;
 }
 
 llvm::AllocaInst *DtoRawAlloca(LLType *lltype, size_t alignment,
                                const char *name) {
-  auto ai = new llvm::AllocaInst(lltype, name, gIR->topallocapoint());
+  auto ai =
+      new llvm::AllocaInst(lltype,
+#if LDC_LLVM_VER >= 500
+                           gIR->module.getDataLayout().getAllocaAddrSpace(),
+#endif
+                           name, gIR->topallocapoint());
   if (alignment) {
     ai->setAlignment(alignment);
   }
diff --git a/gen/passes/GarbageCollect2Stack.cpp b/gen/passes/GarbageCollect2Stack.cpp
index 1f8fd07..e6eeb24 100644
--- a/gen/passes/GarbageCollect2Stack.cpp
+++ b/gen/passes/GarbageCollect2Stack.cpp
@@ -115,8 +115,16 @@ public:
   virtual Value *promote(CallSite CS, IRBuilder<> &B, const Analysis &A) {
     NumGcToStack++;
 
-    Instruction *Begin = &(*CS.getCaller()->getEntryBlock().begin());
-    return new AllocaInst(Ty, ".nongc_mem", Begin); // FIXME: align?
+    auto &BB = CS.getCaller()->getEntryBlock();
+    Instruction *Begin = &(*BB.begin());
+
+    // FIXME: set alignment on alloca?
+    return new AllocaInst(
+        Ty,
+#if LDC_LLVM_VER >= 500
+        BB.getModule()->getDataLayout().getAllocaAddrSpace(),
+#endif
+        ".nongc_mem", Begin);
   }
 
   explicit FunctionInfo(ReturnType::Type returnType) : ReturnType(returnType) {}
diff --git a/gen/runtime.cpp b/gen/runtime.cpp
index 9f75b00..ec027d9 100644
--- a/gen/runtime.cpp
+++ b/gen/runtime.cpp
@@ -320,11 +320,13 @@ static void buildRuntimeModule() {
       Attr_ReadOnly_1_NoCapture(Attr_ReadOnly, 1, llvm::Attribute::NoCapture),
       Attr_ReadOnly_1_3_NoCapture(Attr_ReadOnly_1_NoCapture, 3,
                                   llvm::Attribute::NoCapture),
-      Attr_ReadOnly_NoUnwind_1_NoCapture(Attr_ReadOnly_1_NoCapture, ~0U,
+      Attr_ReadOnly_NoUnwind_1_NoCapture(Attr_ReadOnly_1_NoCapture,
+                                         LLAttributeSet::FunctionIndex,
                                          llvm::Attribute::NoUnwind),
       Attr_ReadOnly_NoUnwind_1_2_NoCapture(Attr_ReadOnly_NoUnwind_1_NoCapture,
                                            2, llvm::Attribute::NoCapture),
-      Attr_ReadNone(NoAttrs, ~0U, llvm::Attribute::ReadNone),
+      Attr_ReadNone(NoAttrs, LLAttributeSet::FunctionIndex,
+                    llvm::Attribute::ReadNone),
       Attr_1_NoCapture(NoAttrs, 1, llvm::Attribute::NoCapture),
       Attr_NoAlias_1_NoCapture(Attr_1_NoCapture, 0, llvm::Attribute::NoAlias),
       Attr_1_2_NoCapture(Attr_1_NoCapture, 2, llvm::Attribute::NoCapture),
diff --git a/gen/tocall.cpp b/gen/tocall.cpp
index c76eac0..80e8d11 100644
--- a/gen/tocall.cpp
+++ b/gen/tocall.cpp
@@ -826,7 +826,7 @@ DValue *DtoCallFunctionImpl(Loc &loc, Type *resulttype, DValue *fnval,
   AttrSet attrs;
 
   // return attrs
-  attrs.add(0, irFty.ret->attrs);
+  attrs.add(LLAttributeSet::ReturnIndex, irFty.ret->attrs);
 
   std::vector<LLValue *> args;
   args.reserve(irFty.args.size());
diff --git a/gen/trycatchfinally.cpp b/gen/trycatchfinally.cpp
index 6573bef..17a132c 100644
--- a/gen/trycatchfinally.cpp
+++ b/gen/trycatchfinally.cpp
@@ -306,6 +306,9 @@ llvm::BasicBlock *CleanupScope::run(IRState &irs, llvm::BasicBlock *sourceBlock,
   if (!branchSelector) {
     // ... and have not created one yet, so do so now.
     branchSelector = new llvm::AllocaInst(llvm::Type::getInt32Ty(irs.context()),
+#if LDC_LLVM_VER >= 500
+                                          irs.module.getDataLayout().getAllocaAddrSpace(),
+#endif
                                           llvm::Twine("branchsel.") +
                                               beginBlock()->getName(),
                                           irs.topallocapoint());

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-d/ldc.git



More information about the pkg-d-commits mailing list