diff --git a/llvm/bindings/go/llvm/IRBindings.h b/llvm/bindings/go/llvm/IRBindings.h --- a/llvm/bindings/go/llvm/IRBindings.h +++ b/llvm/bindings/go/llvm/IRBindings.h @@ -43,11 +43,11 @@ LLVMMetadataRef Val); void LLVMSetMetadata2(LLVMValueRef Inst, unsigned KindID, LLVMMetadataRef MD); -void LLVMSetCurrentDebugLocation2(LLVMBuilderRef Bref, unsigned Line, +void LLVMGoSetCurrentDebugLocation(LLVMBuilderRef Bref, unsigned Line, unsigned Col, LLVMMetadataRef Scope, LLVMMetadataRef InlinedAt); -struct LLVMDebugLocMetadata LLVMGetCurrentDebugLocation2(LLVMBuilderRef Bref); +struct LLVMDebugLocMetadata LLVMGoGetCurrentDebugLocation(LLVMBuilderRef Bref); #ifdef __cplusplus } diff --git a/llvm/bindings/go/llvm/IRBindings.cpp b/llvm/bindings/go/llvm/IRBindings.cpp --- a/llvm/bindings/go/llvm/IRBindings.cpp +++ b/llvm/bindings/go/llvm/IRBindings.cpp @@ -50,7 +50,7 @@ unwrap(Inst)->setMetadata(KindID, N); } -void LLVMSetCurrentDebugLocation2(LLVMBuilderRef Bref, unsigned Line, +void LLVMGoSetCurrentDebugLocation(LLVMBuilderRef Bref, unsigned Line, unsigned Col, LLVMMetadataRef Scope, LLVMMetadataRef InlinedAt) { unwrap(Bref)->SetCurrentDebugLocation( @@ -58,7 +58,7 @@ InlinedAt ? unwrap(InlinedAt) : nullptr)); } -LLVMDebugLocMetadata LLVMGetCurrentDebugLocation2(LLVMBuilderRef Bref) { +LLVMDebugLocMetadata LLVMGoGetCurrentDebugLocation(LLVMBuilderRef Bref) { const auto& Loc = unwrap(Bref)->getCurrentDebugLocation(); const auto* InlinedAt = Loc.getInlinedAt(); const LLVMDebugLocMetadata md{ diff --git a/llvm/bindings/go/llvm/ir.go b/llvm/bindings/go/llvm/ir.go --- a/llvm/bindings/go/llvm/ir.go +++ b/llvm/bindings/go/llvm/ir.go @@ -1301,11 +1301,11 @@ InlinedAt Metadata } func (b Builder) SetCurrentDebugLocation(line, col uint, scope, inlinedAt Metadata) { - C.LLVMSetCurrentDebugLocation2(b.C, C.unsigned(line), C.unsigned(col), scope.C, inlinedAt.C) + C.LLVMGoSetCurrentDebugLocation(b.C, C.unsigned(line), C.unsigned(col), scope.C, inlinedAt.C) } // Get current debug location. Please do not call this function until setting debug location with SetCurrentDebugLocation() func (b Builder) GetCurrentDebugLocation() (loc DebugLoc) { - md := C.LLVMGetCurrentDebugLocation2(b.C) + md := C.LLVMGoGetCurrentDebugLocation(b.C) loc.Line = uint(md.Line) loc.Col = uint(md.Col) loc.Scope = Metadata{C: md.Scope} diff --git a/llvm/include/llvm-c/Core.h b/llvm/include/llvm-c/Core.h --- a/llvm/include/llvm-c/Core.h +++ b/llvm/include/llvm-c/Core.h @@ -3510,9 +3510,42 @@ void LLVMDisposeBuilder(LLVMBuilderRef Builder); /* Metadata */ + +/** + * Get location information used by debugging information. + * + * @see llvm::IRBuilder::getCurrentDebugLocation() + */ +LLVMMetadataRef LLVMGetCurrentDebugLocation2(LLVMBuilderRef Builder); + +/** + * Set location information used by debugging information. + * + * To clear the location metadata of the given instruction, pass NULL to \p Loc. + * + * @see llvm::IRBuilder::SetCurrentDebugLocation() + */ +void LLVMSetCurrentDebugLocation2(LLVMBuilderRef Builder, LLVMMetadataRef Loc); + +/** + * Attempts to set the debug location for the given instruction using the + * current debug location for the given builder. If the builder has no current + * debug location, this function is a no-op. + * + * @see llvm::IRBuilder::SetInstDebugLocation() + */ +void LLVMSetInstDebugLocation(LLVMBuilderRef Builder, LLVMValueRef Inst); + +/** + * Deprecated: Passing the NULL location will crash. + * Use LLVMGetCurrentDebugLocation2 instead. + */ void LLVMSetCurrentDebugLocation(LLVMBuilderRef Builder, LLVMValueRef L); +/** + * Deprecated: Returning the NULL location will crash. + * Use LLVMGetCurrentDebugLocation2 instead. + */ LLVMValueRef LLVMGetCurrentDebugLocation(LLVMBuilderRef Builder); -void LLVMSetInstDebugLocation(LLVMBuilderRef Builder, LLVMValueRef Inst); /* Terminators */ LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef); diff --git a/llvm/lib/IR/Core.cpp b/llvm/lib/IR/Core.cpp --- a/llvm/lib/IR/Core.cpp +++ b/llvm/lib/IR/Core.cpp @@ -3006,6 +3006,17 @@ /*--.. Metadata builders ...................................................--*/ +LLVMMetadataRef LLVMGetCurrentDebugLocation2(LLVMBuilderRef Builder) { + return wrap(unwrap(Builder)->getCurrentDebugLocation().getAsMDNode()); +} + +void LLVMSetCurrentDebugLocation2(LLVMBuilderRef Builder, LLVMMetadataRef Loc) { + if (Loc) + unwrap(Builder)->SetCurrentDebugLocation(DebugLoc(unwrap(Loc))); + else + unwrap(Builder)->SetCurrentDebugLocation(DebugLoc()); +} + void LLVMSetCurrentDebugLocation(LLVMBuilderRef Builder, LLVMValueRef L) { MDNode *Loc = L ? cast(unwrap(L)->getMetadata()) : nullptr; @@ -3022,7 +3033,6 @@ unwrap(Builder)->SetInstDebugLocation(unwrap(Inst)); } - /*--.. Instruction builders ................................................--*/ LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef B) {