Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support LLVM 10 #14

Merged
merged 2 commits into from Apr 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion Makefile
Expand Up @@ -48,7 +48,11 @@ config:
@echo "// Automatically generated by \`make config BUILDDIR=$(BUILDDIR)\`, do not edit." >> llvm_config_$(GOOS).go
@echo "" >> llvm_config_$(GOOS).go
@echo "// #cgo CPPFLAGS: $(shell $(CONFIG) --cppflags)" >> llvm_config_$(GOOS).go
@echo "// #cgo CXXFLAGS: -std=c++11" >> llvm_config_$(GOOS).go
@if [ $(VERSION_MAJOR) -gt 9 ]; then \
echo "// #cgo CXXFLAGS: -std=c++14" >> llvm_config_$(GOOS).go; \
else \
echo "// #cgo CXXFLAGS: -std=c++11" >> llvm_config_$(GOOS).go; \
fi
Comment on lines +51 to +55
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested with -std=c++14 for LLVM 9 and it seems to work just fine, so this condition should not be necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, I doubt that it would break LLVM 9, but I left it there in case old systems didn't support it (but could still build LLVM with c++11).

@echo "// #cgo LDFLAGS: $(LDFLAGS)" >> llvm_config_$(GOOS).go
@echo "import \"C\"" >> llvm_config_$(GOOS).go
@echo "" >> llvm_config_$(GOOS).go
Expand Down
13 changes: 13 additions & 0 deletions backports.cpp
Expand Up @@ -3,6 +3,7 @@
#include "llvm/IR/Instructions.h"
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
#include "llvm/Transforms/Coroutines.h"
#include "llvm-c/DebugInfo.h"

namespace llvm {

Expand All @@ -26,3 +27,15 @@ void LLVMGlobalObjectAddMetadata(LLVMValueRef Global, unsigned KindID, LLVMMetad
llvm::GlobalObject *O = llvm::unwrap<llvm::GlobalObject>(Global);
O->addMetadata(KindID, *N);
}

LLVMMetadataRef
LLVMGoDIBuilderCreateTypedef(LLVMDIBuilderRef Builder, LLVMMetadataRef Type,
const char *Name, size_t NameLen,
LLVMMetadataRef File, unsigned LineNo,
LLVMMetadataRef Scope, uint32_t AlignInBits) {
#if LLVM_VERSION_MAJOR >= 10
return LLVMDIBuilderCreateTypedef(Builder, Type, Name, NameLen, File, LineNo, Scope, AlignInBits);
#else
return LLVMDIBuilderCreateTypedef(Builder, Type, Name, NameLen, File, LineNo, Scope);
#endif
}
5 changes: 5 additions & 0 deletions backports.h
Expand Up @@ -10,6 +10,11 @@ void LLVMPassManagerBuilderAddCoroutinePassesToExtensionPoints_backport(LLVMPass

void LLVMGlobalObjectAddMetadata(LLVMValueRef objValue, unsigned KindID, LLVMMetadataRef md);

LLVMMetadataRef
LLVMGoDIBuilderCreateTypedef(LLVMDIBuilderRef Builder, LLVMMetadataRef Type,
const char *Name, size_t NameLen,
LLVMMetadataRef File, unsigned LineNo,
LLVMMetadataRef Scope, uint32_t AlignInBits);
#ifdef __cplusplus
}
#endif /* defined(__cplusplus) */
16 changes: 9 additions & 7 deletions dibuilder.go
Expand Up @@ -45,7 +45,7 @@ const (
FlagProtected
FlagFwdDecl
FlagAppleBlock
FlagBlockByrefStruct
FlagReserved
FlagVirtual
FlagArtificial
FlagExplicit
Expand Down Expand Up @@ -537,25 +537,27 @@ func (d *DIBuilder) CreateArrayType(t DIArrayType) Metadata {

// DITypedef holds the values for creating typedef type debug metadata.
type DITypedef struct {
Type Metadata
Name string
File Metadata
Line int
Context Metadata
Type Metadata
Name string
File Metadata
Line int
Context Metadata
AlignInBits uint32
}

// CreateTypedef creates typedef type debug metadata.
func (d *DIBuilder) CreateTypedef(t DITypedef) Metadata {
name := C.CString(t.Name)
defer C.free(unsafe.Pointer(name))
result := C.LLVMDIBuilderCreateTypedef(
result := C.LLVMGoDIBuilderCreateTypedef(
d.ref,
t.Type.C,
name,
C.size_t(len(t.Name)),
t.File.C,
C.unsigned(t.Line),
t.Context.C,
C.uint32_t(t.AlignInBits),
)
return Metadata{C: result}
}
Expand Down