From f2c394dc96b4a4e392ac059ace745a27e7953f13 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Mon, 23 Nov 2020 16:04:12 +0100 Subject: [PATCH] Compatibility with both LLVM 10 and 11 --- .github/workflows/main.yml | 5 +++-- src/compiler/llvm_codegen.c | 4 ++-- src/compiler/llvm_codegen_debug_info.c | 4 ++-- src/compiler/llvm_codegen_module.c | 6 +++++- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c2d9b4e22..b4de0555d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -12,9 +12,10 @@ jobs: steps: - uses: actions/checkout@v1 - name: (Linux) Download LLVM - run: sudo apt-get install llvm-9 llvm-9-dev + run: | + sudo apt-get install llvm-10 - name: Build run: | mkdir build && cd build - cmake -DLLVM_DIR=/usr/lib/llvm-9/cmake -DCMAKE_BUILD_TYPE=Debug .. + cmake -DLLVM_DIR=/usr/lib/llvm-10/cmake -DCMAKE_BUILD_TYPE=Debug .. cmake --build . diff --git a/src/compiler/llvm_codegen.c b/src/compiler/llvm_codegen.c index 9a1a36440..93735c078 100644 --- a/src/compiler/llvm_codegen.c +++ b/src/compiler/llvm_codegen.c @@ -276,7 +276,7 @@ void gencontext_emit_introspection_type(GenContext *context, Decl *decl) LLVMValueRef global_name = LLVMAddGlobal(context->module, llvm_get_type(context, type_byte), decl->name ? decl->name : "anon"); LLVMSetGlobalConstant(global_name, 1); LLVMSetInitializer(global_name, LLVMConstInt(llvm_get_type(context, type_byte), 1, false)); - decl->type->backend_typeid = LLVMBuildPtrToInt(context->builder, global_name, llvm_get_type(context, type_typeid), ""); + decl->type->backend_typeid = LLVMConstPointerCast(global_name, llvm_get_type(context, type_typeid)); switch (decl->visibility) { @@ -629,7 +629,7 @@ void llvm_store_self_aligned(GenContext *context, LLVMValueRef pointer, LLVMValu void llvm_store_aligned(GenContext *context, LLVMValueRef pointer, LLVMValueRef value, unsigned alignment) { LLVMValueRef ref = LLVMBuildStore(context->builder, value, pointer); - LLVMSetAlignment(ref, alignment); + if (alignment) LLVMSetAlignment(ref, alignment); } void llvm_store_aligned_decl(GenContext *context, Decl *decl, LLVMValueRef value) diff --git a/src/compiler/llvm_codegen_debug_info.c b/src/compiler/llvm_codegen_debug_info.c index 82c9e31bd..4e2362896 100644 --- a/src/compiler/llvm_codegen_debug_info.c +++ b/src/compiler/llvm_codegen_debug_info.c @@ -419,7 +419,7 @@ static LLVMMetadataRef llvm_debug_typedef_type(GenContext *c, Type *type) return LLVMDIBuilderCreateTypedef(c->debug.builder, llvm_get_debug_type(c, type->canonical), type->name, strlen(type->name), - NULL, 0, NULL); + NULL, 0, NULL, 0); } SourceLocation *location = TOKLOC(decl->span.loc); @@ -432,7 +432,7 @@ static LLVMMetadataRef llvm_debug_typedef_type(GenContext *c, Type *type) llvm_get_debug_type(c, decl->typedef_decl.type_info->type), decl->name, TOKLEN(decl->name_token), c->debug.file, location->line, - c->debug.file); + c->debug.file, type_abi_alignment(type)); if (type->backend_debug_type) { LLVMMetadataReplaceAllUsesWith(type->backend_debug_type, real); diff --git a/src/compiler/llvm_codegen_module.c b/src/compiler/llvm_codegen_module.c index b7cf112b6..69f4b1654 100644 --- a/src/compiler/llvm_codegen_module.c +++ b/src/compiler/llvm_codegen_module.c @@ -34,7 +34,11 @@ void gencontext_begin_module(GenContext *context) dwarf_flags, strlen(dwarf_flags), runtime_version, "" /* split name */, 0 /* len */, emission_kind, /* dwo */0, /* inlining */0, - /* debug for profiling */0); + /* debug for profiling */0 +#if LLVM_VERSION_MAJOR > 10 + , "", 0, "", 0 +#endif + ); } // Setup all types. Not thread-safe, but at this point in time we can assume a single context. // We need to remove the context from the cache after this.