Skip to content

Commit

Permalink
Add support for LLVM 14
Browse files Browse the repository at this point in the history
  • Loading branch information
aykevl committed Apr 20, 2022
1 parent ee4aad4 commit 512c94c
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 6 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,31 @@ jobs:
- name: Test default LLVM
run:
go test -v
test-macos-llvm-14:
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install LLVM
run: |
brew install llvm@14
- name: Test LLVM 14
run:
go test -v -tags=llvm14
test-linux-llvm-14:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install LLVM
run: |
echo 'deb http://apt.llvm.org/focal/ llvm-toolchain-focal-14 main' | sudo tee /etc/apt/sources.list.d/llvm.list
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo apt-get update
sudo apt-get install --no-install-recommends llvm-14-dev
- name: Test LLVM 14
run:
go test -v -tags=llvm14
test-linux-llvm-13:
runs-on: ubuntu-20.04
steps:
Expand Down
10 changes: 10 additions & 0 deletions backports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "llvm/IR/Instructions.h"
#include "llvm/IR/LegacyPassManager.h"
#include "llvm/IR/Module.h"
#include "llvm/Pass.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Transforms/IPO.h"
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
Expand Down Expand Up @@ -76,3 +77,12 @@ LLVMMemoryBufferRef LLVMGoWriteThinLTOBitcodeToMemoryBuffer(LLVMModuleRef M) {
PM.run(*llvm::unwrap(M));
return llvm::wrap(llvm::MemoryBuffer::getMemBufferCopy(OS.str()).release());
}

LLVMMetadataRef LLVMGoDIBuilderCreateExpression(LLVMDIBuilderRef Builder,
uint64_t *Addr, size_t Length) {
#if LLVM_VERSION_MAJOR >= 14
return LLVMDIBuilderCreateExpression(Builder, Addr, Length);
#else
return LLVMDIBuilderCreateExpression(Builder, (int64_t*)Addr, Length);
#endif
}
3 changes: 3 additions & 0 deletions backports.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ LLVMMetadataRef LLVMGoDIBuilderCreateCompileUnit(

LLVMMemoryBufferRef LLVMGoWriteThinLTOBitcodeToMemoryBuffer(LLVMModuleRef M);

LLVMMetadataRef LLVMGoDIBuilderCreateExpression(LLVMDIBuilderRef Builder,
uint64_t *Addr, size_t Length);

#ifdef __cplusplus
}
#endif /* defined(__cplusplus) */
8 changes: 4 additions & 4 deletions dibuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -601,12 +601,12 @@ func (d *DIBuilder) getOrCreateTypeArray(values []Metadata) Metadata {

// CreateExpression creates a new descriptor for the specified
// variable which has a complex address expression for its address.
func (d *DIBuilder) CreateExpression(addr []int64) Metadata {
var data *C.int64_t
func (d *DIBuilder) CreateExpression(addr []uint64) Metadata {
var data *C.uint64_t
if len(addr) > 0 {
data = (*C.int64_t)(unsafe.Pointer(&addr[0]))
data = (*C.uint64_t)(unsafe.Pointer(&addr[0]))
}
result := C.LLVMDIBuilderCreateExpression(d.ref, data, C.size_t(len(addr)))
result := C.LLVMGoDIBuilderCreateExpression(d.ref, data, C.size_t(len(addr)))
return Metadata{C: result}
}

Expand Down
4 changes: 2 additions & 2 deletions llvm_config_linux_llvm13.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build !byollvm && linux && !llvm11 && !llvm12
// +build !byollvm,linux,!llvm11,!llvm12
//go:build !byollvm && linux && !llvm11 && !llvm12 && !llvm14
// +build !byollvm,linux,!llvm11,!llvm12,!llvm14

package llvm

Expand Down
18 changes: 18 additions & 0 deletions llvm_config_linux_llvm14.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//go:build !byollvm && linux && llvm14
// +build !byollvm,linux,llvm14

package llvm

// // Note: disabling deprecated warnings as a transition to new function
// // signatures. We should fix this in LLVM 15 or so, when support for
// // LLVM 13 is dropped and the old function signatures aren't supported
// // anymore.
// // Examples are: LLVMConstGEP2, LLVMAddAlias2, ...
// #cgo CFLAGS: -Wno-deprecated-declarations
//
// #cgo CPPFLAGS: -I/usr/lib/llvm-14/include -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
// #cgo CXXFLAGS: -std=c++14
// #cgo LDFLAGS: -L/usr/lib/llvm-14/lib -lLLVM-14
import "C"

type run_build_sh int

0 comments on commit 512c94c

Please sign in to comment.