Skip to content

Commit cce4741

Browse files
committed
[LLVM-C] Correct The Current Debug Location Accessors (Again)
Summary: Resubmitting D60484 with the conflicting Go bindings renamed to avoid collisions. Reviewers: whitequark, deadalnix Subscribers: hiraditya, llvm-commits, sammccall Tags: #llvm Differential Revision: https://reviews.llvm.org/D60511 llvm-svn: 358086
1 parent aae424a commit cce4741

File tree

7 files changed

+64
-8
lines changed

7 files changed

+64
-8
lines changed

llvm/bindings/go/llvm/IRBindings.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ void LLVMSetMetadata2(LLVMValueRef Inst, unsigned KindID, LLVMMetadataRef MD) {
5050
unwrap<Instruction>(Inst)->setMetadata(KindID, N);
5151
}
5252

53-
void LLVMSetCurrentDebugLocation2(LLVMBuilderRef Bref, unsigned Line,
53+
void LLVMGoSetCurrentDebugLocation(LLVMBuilderRef Bref, unsigned Line,
5454
unsigned Col, LLVMMetadataRef Scope,
5555
LLVMMetadataRef InlinedAt) {
5656
unwrap(Bref)->SetCurrentDebugLocation(
5757
DebugLoc::get(Line, Col, Scope ? unwrap<MDNode>(Scope) : nullptr,
5858
InlinedAt ? unwrap<MDNode>(InlinedAt) : nullptr));
5959
}
6060

61-
LLVMDebugLocMetadata LLVMGetCurrentDebugLocation2(LLVMBuilderRef Bref) {
61+
LLVMDebugLocMetadata LLVMGoGetCurrentDebugLocation(LLVMBuilderRef Bref) {
6262
const auto& Loc = unwrap(Bref)->getCurrentDebugLocation();
6363
const auto* InlinedAt = Loc.getInlinedAt();
6464
const LLVMDebugLocMetadata md{

llvm/bindings/go/llvm/IRBindings.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ void LLVMAddNamedMetadataOperand2(LLVMModuleRef M, const char *name,
4343
LLVMMetadataRef Val);
4444
void LLVMSetMetadata2(LLVMValueRef Inst, unsigned KindID, LLVMMetadataRef MD);
4545

46-
void LLVMSetCurrentDebugLocation2(LLVMBuilderRef Bref, unsigned Line,
46+
void LLVMGoSetCurrentDebugLocation(LLVMBuilderRef Bref, unsigned Line,
4747
unsigned Col, LLVMMetadataRef Scope,
4848
LLVMMetadataRef InlinedAt);
4949

50-
struct LLVMDebugLocMetadata LLVMGetCurrentDebugLocation2(LLVMBuilderRef Bref);
50+
struct LLVMDebugLocMetadata LLVMGoGetCurrentDebugLocation(LLVMBuilderRef Bref);
5151

5252
#ifdef __cplusplus
5353
}

llvm/bindings/go/llvm/ir.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1301,11 +1301,11 @@ type DebugLoc struct {
13011301
InlinedAt Metadata
13021302
}
13031303
func (b Builder) SetCurrentDebugLocation(line, col uint, scope, inlinedAt Metadata) {
1304-
C.LLVMSetCurrentDebugLocation2(b.C, C.unsigned(line), C.unsigned(col), scope.C, inlinedAt.C)
1304+
C.LLVMGoSetCurrentDebugLocation(b.C, C.unsigned(line), C.unsigned(col), scope.C, inlinedAt.C)
13051305
}
13061306
// Get current debug location. Please do not call this function until setting debug location with SetCurrentDebugLocation()
13071307
func (b Builder) GetCurrentDebugLocation() (loc DebugLoc) {
1308-
md := C.LLVMGetCurrentDebugLocation2(b.C)
1308+
md := C.LLVMGoGetCurrentDebugLocation(b.C)
13091309
loc.Line = uint(md.Line)
13101310
loc.Col = uint(md.Col)
13111311
loc.Scope = Metadata{C: md.Scope}

llvm/include/llvm-c/Core.h

+34-1
Original file line numberDiff line numberDiff line change
@@ -3510,9 +3510,42 @@ void LLVMInsertIntoBuilderWithName(LLVMBuilderRef Builder, LLVMValueRef Instr,
35103510
void LLVMDisposeBuilder(LLVMBuilderRef Builder);
35113511

35123512
/* Metadata */
3513+
3514+
/**
3515+
* Get location information used by debugging information.
3516+
*
3517+
* @see llvm::IRBuilder::getCurrentDebugLocation()
3518+
*/
3519+
LLVMMetadataRef LLVMGetCurrentDebugLocation2(LLVMBuilderRef Builder);
3520+
3521+
/**
3522+
* Set location information used by debugging information.
3523+
*
3524+
* To clear the location metadata of the given instruction, pass NULL to \p Loc.
3525+
*
3526+
* @see llvm::IRBuilder::SetCurrentDebugLocation()
3527+
*/
3528+
void LLVMSetCurrentDebugLocation2(LLVMBuilderRef Builder, LLVMMetadataRef Loc);
3529+
3530+
/**
3531+
* Attempts to set the debug location for the given instruction using the
3532+
* current debug location for the given builder. If the builder has no current
3533+
* debug location, this function is a no-op.
3534+
*
3535+
* @see llvm::IRBuilder::SetInstDebugLocation()
3536+
*/
3537+
void LLVMSetInstDebugLocation(LLVMBuilderRef Builder, LLVMValueRef Inst);
3538+
3539+
/**
3540+
* Deprecated: Passing the NULL location will crash.
3541+
* Use LLVMGetCurrentDebugLocation2 instead.
3542+
*/
35133543
void LLVMSetCurrentDebugLocation(LLVMBuilderRef Builder, LLVMValueRef L);
3544+
/**
3545+
* Deprecated: Returning the NULL location will crash.
3546+
* Use LLVMGetCurrentDebugLocation2 instead.
3547+
*/
35143548
LLVMValueRef LLVMGetCurrentDebugLocation(LLVMBuilderRef Builder);
3515-
void LLVMSetInstDebugLocation(LLVMBuilderRef Builder, LLVMValueRef Inst);
35163549

35173550
/* Terminators */
35183551
LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef);

llvm/include/llvm-c/DebugInfo.h

+9
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,15 @@ unsigned LLVMDILocationGetColumn(LLVMMetadataRef Location);
451451
*/
452452
LLVMMetadataRef LLVMDILocationGetScope(LLVMMetadataRef Location);
453453

454+
/**
455+
* Get the "inline at" location associated with this debug location.
456+
* \param Location The debug location.
457+
*
458+
* @see DILocation::getInlinedAt()
459+
*/
460+
LLVMMetadataRef LLVMDILocationGetInlinedAt(LLVMMetadataRef Location);
461+
462+
454463
/**
455464
* Create a type array.
456465
* \param Builder The DIBuilder.

llvm/lib/IR/Core.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -3006,6 +3006,17 @@ void LLVMDisposeBuilder(LLVMBuilderRef Builder) {
30063006

30073007
/*--.. Metadata builders ...................................................--*/
30083008

3009+
LLVMMetadataRef LLVMGetCurrentDebugLocation2(LLVMBuilderRef Builder) {
3010+
return wrap(unwrap(Builder)->getCurrentDebugLocation().getAsMDNode());
3011+
}
3012+
3013+
void LLVMSetCurrentDebugLocation2(LLVMBuilderRef Builder, LLVMMetadataRef Loc) {
3014+
if (Loc)
3015+
unwrap(Builder)->SetCurrentDebugLocation(DebugLoc(unwrap<MDNode>(Loc)));
3016+
else
3017+
unwrap(Builder)->SetCurrentDebugLocation(DebugLoc());
3018+
}
3019+
30093020
void LLVMSetCurrentDebugLocation(LLVMBuilderRef Builder, LLVMValueRef L) {
30103021
MDNode *Loc =
30113022
L ? cast<MDNode>(unwrap<MetadataAsValue>(L)->getMetadata()) : nullptr;
@@ -3022,7 +3033,6 @@ void LLVMSetInstDebugLocation(LLVMBuilderRef Builder, LLVMValueRef Inst) {
30223033
unwrap(Builder)->SetInstDebugLocation(unwrap<Instruction>(Inst));
30233034
}
30243035

3025-
30263036
/*--.. Instruction builders ................................................--*/
30273037

30283038
LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef B) {

llvm/lib/IR/DebugInfo.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -899,6 +899,10 @@ LLVMMetadataRef LLVMDILocationGetScope(LLVMMetadataRef Location) {
899899
return wrap(unwrapDI<DILocation>(Location)->getScope());
900900
}
901901

902+
LLVMMetadataRef LLVMDILocationGetInlinedAt(LLVMMetadataRef Location) {
903+
return wrap(unwrapDI<DILocation>(Location)->getInlinedAt());
904+
}
905+
902906
LLVMMetadataRef LLVMDIBuilderCreateEnumerator(LLVMDIBuilderRef Builder,
903907
const char *Name, size_t NameLen,
904908
int64_t Value,

0 commit comments

Comments
 (0)