diff options
| author | bors <bors@rust-lang.org> | 2017-07-23 01:57:37 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-07-23 01:57:37 +0000 |
| commit | ef19bd1a339212f77160f12af6d5d85d8bb36ea4 (patch) | |
| tree | c512dc5b3d68aa97934766c72e4e7caaa735873e /src/rustllvm/RustWrapper.cpp | |
| parent | c35a0c1d053040381959a9d84b150f64764e53e4 (diff) | |
| parent | 38e40ce50653b8164915b8142e883c5a57b33e7b (diff) | |
| download | rust-ef19bd1a339212f77160f12af6d5d85d8bb36ea4.tar.gz rust-ef19bd1a339212f77160f12af6d5d85d8bb36ea4.zip | |
Auto merge of #43387 - TimNN:rustllvm50, r=alexcrichton
Update Rust LLVM bindings for LLVM 5.0 This is the initial set of changes to update the rust llvm bindings for 5.0. The llvm commits necessitating these changes are linked from the tracking issue, #43370.
Diffstat (limited to 'src/rustllvm/RustWrapper.cpp')
| -rw-r--r-- | src/rustllvm/RustWrapper.cpp | 227 |
1 files changed, 148 insertions, 79 deletions
diff --git a/src/rustllvm/RustWrapper.cpp b/src/rustllvm/RustWrapper.cpp index c11c5f4186e..15a04ba00e2 100644 --- a/src/rustllvm/RustWrapper.cpp +++ b/src/rustllvm/RustWrapper.cpp @@ -18,6 +18,10 @@ #include "llvm/IR/CallSite.h" +#if LLVM_VERSION_GE(5, 0) +#include "llvm/ADT/Optional.h" +#endif + //===----------------------------------------------------------------------=== // // This file defines alternate interfaces to core functions that are more @@ -163,10 +167,14 @@ extern "C" void LLVMRustAddCallSiteAttribute(LLVMValueRef Instr, unsigned Index, LLVMRustAttribute RustAttr) { CallSite Call = CallSite(unwrap<Instruction>(Instr)); Attribute Attr = Attribute::get(Call->getContext(), fromRust(RustAttr)); +#if LLVM_VERSION_GE(5, 0) + Call.addAttribute(Index, Attr); +#else AttrBuilder B(Attr); Call.setAttributes(Call.getAttributes().addAttributes( Call->getContext(), Index, AttributeSet::get(Call->getContext(), Index, B))); +#endif } extern "C" void LLVMRustAddDereferenceableCallSiteAttr(LLVMValueRef Instr, @@ -175,9 +183,14 @@ extern "C" void LLVMRustAddDereferenceableCallSiteAttr(LLVMValueRef Instr, CallSite Call = CallSite(unwrap<Instruction>(Instr)); AttrBuilder B; B.addDereferenceableAttr(Bytes); +#if LLVM_VERSION_GE(5, 0) + Call.setAttributes(Call.getAttributes().addAttributes( + Call->getContext(), Index, B)); +#else Call.setAttributes(Call.getAttributes().addAttributes( Call->getContext(), Index, AttributeSet::get(Call->getContext(), Index, B))); +#endif } extern "C" void LLVMRustAddFunctionAttribute(LLVMValueRef Fn, unsigned Index, @@ -185,7 +198,11 @@ extern "C" void LLVMRustAddFunctionAttribute(LLVMValueRef Fn, unsigned Index, Function *A = unwrap<Function>(Fn); Attribute Attr = Attribute::get(A->getContext(), fromRust(RustAttr)); AttrBuilder B(Attr); +#if LLVM_VERSION_GE(5, 0) + A->addAttributes(Index, B); +#else A->addAttributes(Index, AttributeSet::get(A->getContext(), Index, B)); +#endif } extern "C" void LLVMRustAddDereferenceableAttr(LLVMValueRef Fn, unsigned Index, @@ -193,7 +210,11 @@ extern "C" void LLVMRustAddDereferenceableAttr(LLVMValueRef Fn, unsigned Index, Function *A = unwrap<Function>(Fn); AttrBuilder B; B.addDereferenceableAttr(Bytes); +#if LLVM_VERSION_GE(5, 0) + A->addAttributes(Index, B); +#else A->addAttributes(Index, AttributeSet::get(A->getContext(), Index, B)); +#endif } extern "C" void LLVMRustAddFunctionAttrStringValue(LLVMValueRef Fn, @@ -203,18 +224,26 @@ extern "C" void LLVMRustAddFunctionAttrStringValue(LLVMValueRef Fn, Function *F = unwrap<Function>(Fn); AttrBuilder B; B.addAttribute(Name, Value); +#if LLVM_VERSION_GE(5, 0) + F->addAttributes(Index, B); +#else F->addAttributes(Index, AttributeSet::get(F->getContext(), Index, B)); +#endif } extern "C" void LLVMRustRemoveFunctionAttributes(LLVMValueRef Fn, unsigned Index, LLVMRustAttribute RustAttr) { Function *F = unwrap<Function>(Fn); - const AttributeSet PAL = F->getAttributes(); Attribute Attr = Attribute::get(F->getContext(), fromRust(RustAttr)); AttrBuilder B(Attr); + auto PAL = F->getAttributes(); +#if LLVM_VERSION_GE(5, 0) + auto PALNew = PAL.removeAttributes(F->getContext(), Index, B); +#else const AttributeSet PALNew = PAL.removeAttributes( F->getContext(), Index, AttributeSet::get(F->getContext(), Index, B)); +#endif F->setAttributes(PALNew); } @@ -263,6 +292,18 @@ enum class LLVMRustSynchronizationScope { CrossThread, }; +#if LLVM_VERSION_GE(5, 0) +static SyncScope::ID fromRust(LLVMRustSynchronizationScope Scope) { + switch (Scope) { + case LLVMRustSynchronizationScope::SingleThread: + return SyncScope::SingleThread; + case LLVMRustSynchronizationScope::CrossThread: + return SyncScope::System; + default: + llvm_unreachable("bad SynchronizationScope."); + } +} +#else static SynchronizationScope fromRust(LLVMRustSynchronizationScope Scope) { switch (Scope) { case LLVMRustSynchronizationScope::SingleThread: @@ -273,6 +314,7 @@ static SynchronizationScope fromRust(LLVMRustSynchronizationScope Scope) { llvm_unreachable("bad SynchronizationScope."); } } +#endif extern "C" LLVMValueRef LLVMRustBuildAtomicFence(LLVMBuilderRef B, LLVMAtomicOrdering Order, @@ -318,17 +360,19 @@ extern "C" void LLVMRustAppendModuleInlineAsm(LLVMModuleRef M, const char *Asm) typedef DIBuilder *LLVMRustDIBuilderRef; -typedef struct LLVMOpaqueMetadata *LLVMRustMetadataRef; +#if LLVM_VERSION_LT(5, 0) +typedef struct LLVMOpaqueMetadata *LLVMMetadataRef; namespace llvm { -DEFINE_ISA_CONVERSION_FUNCTIONS(Metadata, LLVMRustMetadataRef) +DEFINE_ISA_CONVERSION_FUNCTIONS(Metadata, LLVMMetadataRef) -inline Metadata **unwrap(LLVMRustMetadataRef *Vals) { +inline Metadata **unwrap(LLVMMetadataRef *Vals) { return reinterpret_cast<Metadata **>(Vals); } } +#endif -template <typename DIT> DIT *unwrapDIPtr(LLVMRustMetadataRef Ref) { +template <typename DIT> DIT *unwrapDIPtr(LLVMMetadataRef Ref) { return (DIT *)(Ref ? unwrap<MDNode>(Ref) : nullptr); } @@ -466,7 +510,7 @@ extern "C" void LLVMRustAddModuleFlag(LLVMModuleRef M, const char *Name, unwrap(M)->addModuleFlag(Module::Warning, Name, Value); } -extern "C" void LLVMRustMetadataAsValue(LLVMContextRef C, LLVMRustMetadataRef MD) { +extern "C" void LLVMRustMetadataAsValue(LLVMContextRef C, LLVMMetadataRef MD) { wrap(MetadataAsValue::get(*unwrap(C), unwrap(MD))); } @@ -482,8 +526,8 @@ extern "C" void LLVMRustDIBuilderFinalize(LLVMRustDIBuilderRef Builder) { Builder->finalize(); } -extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateCompileUnit( - LLVMRustDIBuilderRef Builder, unsigned Lang, LLVMRustMetadataRef FileRef, +extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateCompileUnit( + LLVMRustDIBuilderRef Builder, unsigned Lang, LLVMMetadataRef FileRef, const char *Producer, bool isOptimized, const char *Flags, unsigned RuntimeVer, const char *SplitName) { auto *File = unwrapDI<DIFile>(FileRef); @@ -498,16 +542,16 @@ extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateCompileUnit( #endif } -extern "C" LLVMRustMetadataRef +extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateFile(LLVMRustDIBuilderRef Builder, const char *Filename, const char *Directory) { return wrap(Builder->createFile(Filename, Directory)); } -extern "C" LLVMRustMetadataRef +extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateSubroutineType(LLVMRustDIBuilderRef Builder, - LLVMRustMetadataRef File, - LLVMRustMetadataRef ParameterTypes) { + LLVMMetadataRef File, + LLVMMetadataRef ParameterTypes) { return wrap(Builder->createSubroutineType( #if LLVM_VERSION_EQ(3, 7) unwrapDI<DIFile>(File), @@ -515,12 +559,12 @@ LLVMRustDIBuilderCreateSubroutineType(LLVMRustDIBuilderRef Builder, DITypeRefArray(unwrap<MDTuple>(ParameterTypes)))); } -extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateFunction( - LLVMRustDIBuilderRef Builder, LLVMRustMetadataRef Scope, const char *Name, - const char *LinkageName, LLVMRustMetadataRef File, unsigned LineNo, - LLVMRustMetadataRef Ty, bool IsLocalToUnit, bool IsDefinition, +extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateFunction( + LLVMRustDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, + const char *LinkageName, LLVMMetadataRef File, unsigned LineNo, + LLVMMetadataRef Ty, bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine, LLVMRustDIFlags Flags, bool IsOptimized, - LLVMValueRef Fn, LLVMRustMetadataRef TParam, LLVMRustMetadataRef Decl) { + LLVMValueRef Fn, LLVMMetadataRef TParam, LLVMMetadataRef Decl) { #if LLVM_VERSION_GE(3, 8) DITemplateParameterArray TParams = DITemplateParameterArray(unwrap<MDTuple>(TParam)); @@ -540,7 +584,7 @@ extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateFunction( #endif } -extern "C" LLVMRustMetadataRef +extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateBasicType(LLVMRustDIBuilderRef Builder, const char *Name, uint64_t SizeInBits, uint32_t AlignInBits, unsigned Encoding) { @@ -551,19 +595,23 @@ LLVMRustDIBuilderCreateBasicType(LLVMRustDIBuilderRef Builder, const char *Name, Encoding)); } -extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreatePointerType( - LLVMRustDIBuilderRef Builder, LLVMRustMetadataRef PointeeTy, +extern "C" LLVMMetadataRef LLVMRustDIBuilderCreatePointerType( + LLVMRustDIBuilderRef Builder, LLVMMetadataRef PointeeTy, uint64_t SizeInBits, uint32_t AlignInBits, const char *Name) { return wrap(Builder->createPointerType(unwrapDI<DIType>(PointeeTy), - SizeInBits, AlignInBits, Name)); + SizeInBits, AlignInBits, +#if LLVM_VERSION_GE(5, 0) + /* DWARFAddressSpace */ None, +#endif + Name)); } -extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateStructType( - LLVMRustDIBuilderRef Builder, LLVMRustMetadataRef Scope, const char *Name, - LLVMRustMetadataRef File, unsigned LineNumber, uint64_t SizeInBits, +extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateStructType( + LLVMRustDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, + LLVMMetadataRef File, unsigned LineNumber, uint64_t SizeInBits, uint32_t AlignInBits, LLVMRustDIFlags Flags, - LLVMRustMetadataRef DerivedFrom, LLVMRustMetadataRef Elements, - unsigned RunTimeLang, LLVMRustMetadataRef VTableHolder, + LLVMMetadataRef DerivedFrom, LLVMMetadataRef Elements, + unsigned RunTimeLang, LLVMMetadataRef VTableHolder, const char *UniqueId) { return wrap(Builder->createStructType( unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), LineNumber, @@ -572,37 +620,37 @@ extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateStructType( unwrapDI<DIType>(VTableHolder), UniqueId)); } -extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateMemberType( - LLVMRustDIBuilderRef Builder, LLVMRustMetadataRef Scope, const char *Name, - LLVMRustMetadataRef File, unsigned LineNo, uint64_t SizeInBits, +extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateMemberType( + LLVMRustDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, + LLVMMetadataRef File, unsigned LineNo, uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits, LLVMRustDIFlags Flags, - LLVMRustMetadataRef Ty) { + LLVMMetadataRef Ty) { return wrap(Builder->createMemberType(unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), LineNo, SizeInBits, AlignInBits, OffsetInBits, fromRust(Flags), unwrapDI<DIType>(Ty))); } -extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateLexicalBlock( - LLVMRustDIBuilderRef Builder, LLVMRustMetadataRef Scope, - LLVMRustMetadataRef File, unsigned Line, unsigned Col) { +extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateLexicalBlock( + LLVMRustDIBuilderRef Builder, LLVMMetadataRef Scope, + LLVMMetadataRef File, unsigned Line, unsigned Col) { return wrap(Builder->createLexicalBlock(unwrapDI<DIDescriptor>(Scope), unwrapDI<DIFile>(File), Line, Col)); } -extern "C" LLVMRustMetadataRef +extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateLexicalBlockFile(LLVMRustDIBuilderRef Builder, - LLVMRustMetadataRef Scope, - LLVMRustMetadataRef File) { + LLVMMetadataRef Scope, + LLVMMetadataRef File) { return wrap(Builder->createLexicalBlockFile(unwrapDI<DIDescriptor>(Scope), unwrapDI<DIFile>(File))); } -extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateStaticVariable( - LLVMRustDIBuilderRef Builder, LLVMRustMetadataRef Context, const char *Name, - const char *LinkageName, LLVMRustMetadataRef File, unsigned LineNo, - LLVMRustMetadataRef Ty, bool IsLocalToUnit, LLVMValueRef V, - LLVMRustMetadataRef Decl = nullptr, uint32_t AlignInBits = 0) { +extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateStaticVariable( + LLVMRustDIBuilderRef Builder, LLVMMetadataRef Context, const char *Name, + const char *LinkageName, LLVMMetadataRef File, unsigned LineNo, + LLVMMetadataRef Ty, bool IsLocalToUnit, LLVMValueRef V, + LLVMMetadataRef Decl = nullptr, uint32_t AlignInBits = 0) { llvm::GlobalVariable *InitVal = cast<llvm::GlobalVariable>(unwrap(V)); #if LLVM_VERSION_GE(4, 0) @@ -632,10 +680,10 @@ extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateStaticVariable( #endif } -extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateVariable( - LLVMRustDIBuilderRef Builder, unsigned Tag, LLVMRustMetadataRef Scope, - const char *Name, LLVMRustMetadataRef File, unsigned LineNo, - LLVMRustMetadataRef Ty, bool AlwaysPreserve, LLVMRustDIFlags Flags, +extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateVariable( + LLVMRustDIBuilderRef Builder, unsigned Tag, LLVMMetadataRef Scope, + const char *Name, LLVMMetadataRef File, unsigned LineNo, + LLVMMetadataRef Ty, bool AlwaysPreserve, LLVMRustDIFlags Flags, unsigned ArgNo, uint32_t AlignInBits) { #if LLVM_VERSION_GE(3, 8) if (Tag == 0x100) { // DW_TAG_auto_variable @@ -659,40 +707,40 @@ extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateVariable( #endif } -extern "C" LLVMRustMetadataRef +extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateArrayType(LLVMRustDIBuilderRef Builder, uint64_t Size, - uint32_t AlignInBits, LLVMRustMetadataRef Ty, - LLVMRustMetadataRef Subscripts) { + uint32_t AlignInBits, LLVMMetadataRef Ty, + LLVMMetadataRef Subscripts) { return wrap( Builder->createArrayType(Size, AlignInBits, unwrapDI<DIType>(Ty), DINodeArray(unwrapDI<MDTuple>(Subscripts)))); } -extern "C" LLVMRustMetadataRef +extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateVectorType(LLVMRustDIBuilderRef Builder, uint64_t Size, - uint32_t AlignInBits, LLVMRustMetadataRef Ty, - LLVMRustMetadataRef Subscripts) { + uint32_t AlignInBits, LLVMMetadataRef Ty, + LLVMMetadataRef Subscripts) { return wrap( Builder->createVectorType(Size, AlignInBits, unwrapDI<DIType>(Ty), DINodeArray(unwrapDI<MDTuple>(Subscripts)))); } -extern "C" LLVMRustMetadataRef +extern "C" LLVMMetadataRef LLVMRustDIBuilderGetOrCreateSubrange(LLVMRustDIBuilderRef Builder, int64_t Lo, int64_t Count) { return wrap(Builder->getOrCreateSubrange(Lo, Count)); } -extern "C" LLVMRustMetadataRef +extern "C" LLVMMetadataRef LLVMRustDIBuilderGetOrCreateArray(LLVMRustDIBuilderRef Builder, - LLVMRustMetadataRef *Ptr, unsigned Count) { + LLVMMetadataRef *Ptr, unsigned Count) { Metadata **DataValue = unwrap(Ptr); return wrap( Builder->getOrCreateArray(ArrayRef<Metadata *>(DataValue, Count)).get()); } extern "C" LLVMValueRef LLVMRustDIBuilderInsertDeclareAtEnd( - LLVMRustDIBuilderRef Builder, LLVMValueRef V, LLVMRustMetadataRef VarInfo, + LLVMRustDIBuilderRef Builder, LLVMValueRef V, LLVMMetadataRef VarInfo, int64_t *AddrOps, unsigned AddrOpsCount, LLVMValueRef DL, LLVMBasicBlockRef InsertAtEnd) { return wrap(Builder->insertDeclare( @@ -702,27 +750,27 @@ extern "C" LLVMValueRef LLVMRustDIBuilderInsertDeclareAtEnd( unwrap(InsertAtEnd))); } -extern "C" LLVMRustMetadataRef +extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateEnumerator(LLVMRustDIBuilderRef Builder, const char *Name, uint64_t Val) { return wrap(Builder->createEnumerator(Name, Val)); } -extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateEnumerationType( - LLVMRustDIBuilderRef Builder, LLVMRustMetadataRef Scope, const char *Name, - LLVMRustMetadataRef File, unsigned LineNumber, uint64_t SizeInBits, - uint32_t AlignInBits, LLVMRustMetadataRef Elements, - LLVMRustMetadataRef ClassTy) { +extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateEnumerationType( + LLVMRustDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, + LLVMMetadataRef File, unsigned LineNumber, uint64_t SizeInBits, + uint32_t AlignInBits, LLVMMetadataRef Elements, + LLVMMetadataRef ClassTy) { return wrap(Builder->createEnumerationType( unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), LineNumber, SizeInBits, AlignInBits, DINodeArray(unwrapDI<MDTuple>(Elements)), unwrapDI<DIType>(ClassTy))); } -extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateUnionType( - LLVMRustDIBuilderRef Builder, LLVMRustMetadataRef Scope, const char *Name, - LLVMRustMetadataRef File, unsigned LineNumber, uint64_t SizeInBits, - uint32_t AlignInBits, LLVMRustDIFlags Flags, LLVMRustMetadataRef Elements, +extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateUnionType( + LLVMRustDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, + LLVMMetadataRef File, unsigned LineNumber, uint64_t SizeInBits, + uint32_t AlignInBits, LLVMRustDIFlags Flags, LLVMMetadataRef Elements, unsigned RunTimeLang, const char *UniqueId) { return wrap(Builder->createUnionType( unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), LineNumber, @@ -730,20 +778,24 @@ extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateUnionType( DINodeArray(unwrapDI<MDTuple>(Elements)), RunTimeLang, UniqueId)); } -extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateTemplateTypeParameter( - LLVMRustDIBuilderRef Builder, LLVMRustMetadataRef Scope, const char *Name, - LLVMRustMetadataRef Ty, LLVMRustMetadataRef File, unsigned LineNo, +extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateTemplateTypeParameter( + LLVMRustDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, + LLVMMetadataRef Ty, LLVMMetadataRef File, unsigned LineNo, unsigned ColumnNo) { return wrap(Builder->createTemplateTypeParameter( unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIType>(Ty))); } -extern "C" LLVMRustMetadataRef +extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateNameSpace(LLVMRustDIBuilderRef Builder, - LLVMRustMetadataRef Scope, const char *Name, - LLVMRustMetadataRef File, unsigned LineNo) { + LLVMMetadataRef Scope, const char *Name, + LLVMMetadataRef File, unsigned LineNo) { return wrap(Builder->createNameSpace( - unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), LineNo + unwrapDI<DIDescriptor>(Scope), Name +#if LLVM_VERSION_LT(5, 0) + , + unwrapDI<DIFile>(File), LineNo +#endif #if LLVM_VERSION_GE(4, 0) , false // ExportSymbols (only relevant for C++ anonymous namespaces) @@ -753,16 +805,16 @@ LLVMRustDIBuilderCreateNameSpace(LLVMRustDIBuilderRef Builder, extern "C" void LLVMRustDICompositeTypeSetTypeArray(LLVMRustDIBuilderRef Builder, - LLVMRustMetadataRef CompositeTy, - LLVMRustMetadataRef TyArray) { + LLVMMetadataRef CompositeTy, + LLVMMetadataRef TyArray) { DICompositeType *Tmp = unwrapDI<DICompositeType>(CompositeTy); Builder->replaceArrays(Tmp, DINodeArray(unwrap<MDTuple>(TyArray))); } extern "C" LLVMValueRef LLVMRustDIBuilderCreateDebugLocation(LLVMContextRef ContextRef, unsigned Line, - unsigned Column, LLVMRustMetadataRef Scope, - LLVMRustMetadataRef InlinedAt) { + unsigned Column, LLVMMetadataRef Scope, + LLVMMetadataRef InlinedAt) { LLVMContext &Context = *unwrap(ContextRef); DebugLoc debug_loc = DebugLoc::get(Line, Column, unwrapDIPtr<MDNode>(Scope), @@ -879,8 +931,8 @@ extern "C" void LLVMRustWriteTwineToString(LLVMTwineRef T, RustStringRef Str) { extern "C" void LLVMRustUnpackOptimizationDiagnostic( LLVMDiagnosticInfoRef DI, RustStringRef PassNameOut, - LLVMValueRef *FunctionOut, LLVMDebugLocRef *DebugLocOut, - RustStringRef MessageOut) { + LLVMValueRef *FunctionOut, unsigned* Line, unsigned* Column, + RustStringRef FilenameOut, RustStringRef MessageOut) { // Undefined to call this not on an optimization diagnostic! llvm::DiagnosticInfoOptimizationBase *Opt = static_cast<llvm::DiagnosticInfoOptimizationBase *>(unwrap(DI)); @@ -888,7 +940,24 @@ extern "C" void LLVMRustUnpackOptimizationDiagnostic( RawRustStringOstream PassNameOS(PassNameOut); PassNameOS << Opt->getPassName(); *FunctionOut = wrap(&Opt->getFunction()); - *DebugLocOut = wrap(&Opt->getDebugLoc()); + + RawRustStringOstream FilenameOS(FilenameOut); +#if LLVM_VERSION_GE(5,0) + DiagnosticLocation loc = Opt->getLocation(); + if (loc.isValid()) { + *Line = loc.getLine(); + *Column = loc.getColumn(); + FilenameOS << loc.getFilename(); + } +#else + const DebugLoc &loc = Opt->getDebugLoc(); + if (loc) { + *Line = loc.getLine(); + *Column = loc.getCol(); + FilenameOS << cast<DIScope>(loc.getScope())->getFilename(); + } +#endif + RawRustStringOstream MessageOS(MessageOut); MessageOS << Opt->getMsg(); } |
