Skip to content

Commit 8fec6d1

Browse files
authored
llvm-c: Introduce 'LLVMDISubprogramReplaceType' (#143461)
The C API does not provide a way to replace the subroutine type after creating a subprogram. This functionality is useful for creating a subroutine type composed of types which have the subprogram as scope
1 parent 68f0937 commit 8fec6d1

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

llvm/include/llvm-c/DebugInfo.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,6 +1420,16 @@ void LLVMSetSubprogram(LLVMValueRef Func, LLVMMetadataRef SP);
14201420
*/
14211421
unsigned LLVMDISubprogramGetLine(LLVMMetadataRef Subprogram);
14221422

1423+
/**
1424+
* Replace the subprogram subroutine type.
1425+
* \param Subprogram The subprogram object.
1426+
* \param SubroutineType The new subroutine type.
1427+
*
1428+
* @see DISubprogram::replaceType()
1429+
*/
1430+
void LLVMDISubprogramReplaceType(LLVMMetadataRef Subprogram,
1431+
LLVMMetadataRef SubroutineType);
1432+
14231433
/**
14241434
* Get the debug location for the given instruction.
14251435
*

llvm/lib/IR/DebugInfo.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1813,6 +1813,12 @@ unsigned LLVMDISubprogramGetLine(LLVMMetadataRef Subprogram) {
18131813
return unwrapDI<DISubprogram>(Subprogram)->getLine();
18141814
}
18151815

1816+
void LLVMDISubprogramReplaceType(LLVMMetadataRef Subprogram,
1817+
LLVMMetadataRef SubroutineType) {
1818+
unwrapDI<DISubprogram>(Subprogram)
1819+
->replaceType(unwrapDI<DISubroutineType>(SubroutineType));
1820+
}
1821+
18161822
LLVMMetadataRef LLVMInstructionGetDebugLoc(LLVMValueRef Inst) {
18171823
return wrap(unwrap<Instruction>(Inst)->getDebugLoc().getAsMDNode());
18181824
}

llvm/tools/llvm-c-test/debuginfo.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,12 @@ int llvm_test_dibuilder(void) {
130130
LLVMMetadataRef FooParamLocation =
131131
LLVMDIBuilderCreateDebugLocation(LLVMGetGlobalContext(), 42, 0,
132132
ReplaceableFunctionMetadata, NULL);
133-
LLVMMetadataRef FunctionMetadata =
134-
LLVMDIBuilderCreateFunction(DIB, File, "foo", 3, "foo", 3,
135-
File, 42, FunctionTy, true, true,
136-
42, 0, false);
133+
LLVMMetadataRef FunctionMetadata = LLVMDIBuilderCreateFunction(
134+
DIB, File, "foo", 3, "foo", 3, File, 42, NULL, true, true, 42, 0, false);
137135
LLVMMetadataReplaceAllUsesWith(ReplaceableFunctionMetadata, FunctionMetadata);
138136

137+
LLVMDISubprogramReplaceType(FunctionMetadata, FunctionTy);
138+
139139
LLVMMetadataRef FooParamExpression =
140140
LLVMDIBuilderCreateExpression(DIB, NULL, 0);
141141
LLVMMetadataRef FooParamVar1 =

0 commit comments

Comments
 (0)