Skip to content

Commit 76d6171

Browse files
authored
Merge pull request #22 from cpunion/add-missing-funcs
Add removed DIBuilder.InsertDeclareAtEnd
2 parents 439e2e4 + 59116c4 commit 76d6171

3 files changed

Lines changed: 26 additions & 0 deletions

File tree

backports.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,17 @@ void LLVMGoDIBuilderInsertDbgValueRecordAtEnd(
6262
LLVMDIBuilderInsertDbgValueAtEnd(Builder, Val, VarInfo, Expr, DebugLoc, Block);
6363
#endif
6464
}
65+
66+
void LLVMGoDIBuilderInsertDbgDeclareRecordAtEnd(
67+
LLVMDIBuilderRef Builder, LLVMValueRef Val, LLVMMetadataRef VarInfo,
68+
LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMBasicBlockRef Block) {
69+
#if LLVM_VERSION_MAJOR >= 19
70+
// Note: this returns a LLVMDbgRecordRef. Previously, InsertDeclareAtEnd would
71+
// return a Declare. But since the type changed, and I'd like to keep the API
72+
// consistent across LLVM versions, I decided to drop the return value.
73+
LLVMDIBuilderInsertDeclareRecordAtEnd(Builder, Val, VarInfo, Expr, DebugLoc, Block);
74+
#else
75+
// Old llvm.dbg.* API.
76+
LLVMDIBuilderInsertDeclareAtEnd(Builder, Val, VarInfo, Expr, DebugLoc, Block);
77+
#endif
78+
}

backports.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ void LLVMGoDIBuilderInsertDbgValueRecordAtEnd(
1414
LLVMDIBuilderRef Builder, LLVMValueRef Val, LLVMMetadataRef VarInfo,
1515
LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMBasicBlockRef Block);
1616

17+
void LLVMGoDIBuilderInsertDbgDeclareRecordAtEnd(
18+
LLVMDIBuilderRef Builder, LLVMValueRef Val, LLVMMetadataRef VarInfo,
19+
LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMBasicBlockRef Block);
20+
1721
#ifdef __cplusplus
1822
}
1923
#endif /* defined(__cplusplus) */

dibuilder.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,14 @@ func (d *DIBuilder) CreateExpression(addr []uint64) Metadata {
610610
return Metadata{C: result}
611611
}
612612

613+
// InsertDeclareAtEnd inserts a call to llvm.dbg.declare at the end of the
614+
// specified basic block for the given value and associated debug metadata.
615+
func (d *DIBuilder) InsertDeclareAtEnd(v Value, diVarInfo, expr Metadata, l DebugLoc, bb BasicBlock) {
616+
loc := C.LLVMDIBuilderCreateDebugLocation(
617+
d.m.Context().C, C.uint(l.Line), C.uint(l.Col), l.Scope.C, l.InlinedAt.C)
618+
C.LLVMGoDIBuilderInsertDbgDeclareRecordAtEnd(d.ref, v.C, diVarInfo.C, expr.C, loc, bb.C)
619+
}
620+
613621
// InsertValueAtEnd inserts a call to llvm.dbg.value at the end of the
614622
// specified basic block for the given value and associated debug metadata.
615623
func (d *DIBuilder) InsertValueAtEnd(v Value, diVarInfo, expr Metadata, l DebugLoc, bb BasicBlock) {

0 commit comments

Comments
 (0)