Skip to content

diffs to compile for clang 9 #96

Description

@dokipen3d

Here are some changes required to get coriander compiling with clang 9. I've tested this on my macbook pro M1 and just using the clang 9 release download. I'll now check 10 and 11.

+++ b/src/mutations.cpp
@@ -44,12 +44,14 @@ void appendGlobalConstructorCall(Module *M, std::string functionName) {
     for(int i = 0; i < oldNumConstructors; i++) {
         initializers[i] = initializer->getAggregateElement((unsigned int)i);
     }
-    Constant *structValues[] = {
-        ConstantInt::get(IntegerType::get(M->getContext(), 32), 1000000),
-        M->getOrInsertFunction(
+       auto callee = M->getOrInsertFunction(
             functionName,
             Type::getVoidTy(M->getContext()),
-            NULL),
+            static_cast<size_t>(NULL));
+       auto kernelGo = dyn_cast<Constant>(callee.getCallee());
+    Constant *structValues[] = {
+        ConstantInt::get(IntegerType::get(M->getContext(), 32), 1000000),
+        kernelGo,
         ConstantPointerNull::get(PointerType::get(IntegerType::get(M->getContext(), 8), 0))
     };
     initializers[oldNumConstructors] = ConstantStruct::getAnon(ArrayRef<Constant *>(&structValues[0], &structValues[3]));
diff --git a/src/patch_hostside.cpp b/src/patch_hostside.cpp
index 51d251c..a0ceefc 100644
--- a/src/patch_hostside.cpp
+++ b/src/patch_hostside.cpp
@@ -64,8 +64,12 @@ std::unique_ptr<GenericCallInst> GenericCallInst::create(llvm::CallInst *inst) {
 
 template<typename... ArgsTy>
 Constant *getOrInsertFunction(Module* m, StringRef Name, Type *RetTy, ArgsTy... Args) {
-#if LLVM_VERSION_MAJOR > 4
+#if LLVM_VERSION_MAJOR > 4 && LLVM_VERSION_MAJOR < 9
     return m->getOrInsertFunction(Name, RetTy, Args...);
+#elif LLVM_VERSION_MAJOR > 8
@@ -64,8 +64,12 @@ std::unique_ptr<GenericCallInst> GenericCallInst::create(llvm::CallInst *inst) {
 
 template<typename... ArgsTy>
 Constant *getOrInsertFunction(Module* m, StringRef Name, Type *RetTy, ArgsTy... Args) {
-#if LLVM_VERSION_MAJOR > 4
+#if LLVM_VERSION_MAJOR > 4 && LLVM_VERSION_MAJOR < 9
     return m->getOrInsertFunction(Name, RetTy, Args...);
+#elif LLVM_VERSION_MAJOR > 8
+       auto callee = m->getOrInsertFunction(Name, RetTy, Args...);
+       auto kernelGo = dyn_cast<Constant>(callee.getCallee());
+       return kernelGo;
 #else
     return m->getOrInsertFunction(Name, RetTy, Args..., NULL);
 #endif
@@ -559,10 +563,11 @@ void PatchHostside::patchCudaLaunch(
         i++;
     }
     // trigger the kernel...
-    Function *kernelGo = cast<Function>(F->getParent()->getOrInsertFunction(
+    auto callee = F->getParent()->getOrInsertFunction(
         "kernelGo",
         Type::getVoidTy(context),
-        NULL));
+        static_cast<size_t>(NULL));
+       auto kernelGo = dyn_cast<Constant>(callee.getCallee());
     CallInst *kernelGoInst = CallInst::Create(kernelGo);
     kernelGoInst->insertAfter(lastInst);
     lastInst = kernelGoInst;

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions