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
This commit is contained in:
David
2025-06-24 07:42:06 -06:00
committed by GitHub
parent 68f09370f9
commit 8fec6d1177
3 changed files with 20 additions and 4 deletions

View File

@@ -1420,6 +1420,16 @@ void LLVMSetSubprogram(LLVMValueRef Func, LLVMMetadataRef SP);
*/
unsigned LLVMDISubprogramGetLine(LLVMMetadataRef Subprogram);
/**
* Replace the subprogram subroutine type.
* \param Subprogram The subprogram object.
* \param SubroutineType The new subroutine type.
*
* @see DISubprogram::replaceType()
*/
void LLVMDISubprogramReplaceType(LLVMMetadataRef Subprogram,
LLVMMetadataRef SubroutineType);
/**
* Get the debug location for the given instruction.
*

View File

@@ -1813,6 +1813,12 @@ unsigned LLVMDISubprogramGetLine(LLVMMetadataRef Subprogram) {
return unwrapDI<DISubprogram>(Subprogram)->getLine();
}
void LLVMDISubprogramReplaceType(LLVMMetadataRef Subprogram,
LLVMMetadataRef SubroutineType) {
unwrapDI<DISubprogram>(Subprogram)
->replaceType(unwrapDI<DISubroutineType>(SubroutineType));
}
LLVMMetadataRef LLVMInstructionGetDebugLoc(LLVMValueRef Inst) {
return wrap(unwrap<Instruction>(Inst)->getDebugLoc().getAsMDNode());
}

View File

@@ -130,12 +130,12 @@ int llvm_test_dibuilder(void) {
LLVMMetadataRef FooParamLocation =
LLVMDIBuilderCreateDebugLocation(LLVMGetGlobalContext(), 42, 0,
ReplaceableFunctionMetadata, NULL);
LLVMMetadataRef FunctionMetadata =
LLVMDIBuilderCreateFunction(DIB, File, "foo", 3, "foo", 3,
File, 42, FunctionTy, true, true,
42, 0, false);
LLVMMetadataRef FunctionMetadata = LLVMDIBuilderCreateFunction(
DIB, File, "foo", 3, "foo", 3, File, 42, NULL, true, true, 42, 0, false);
LLVMMetadataReplaceAllUsesWith(ReplaceableFunctionMetadata, FunctionMetadata);
LLVMDISubprogramReplaceType(FunctionMetadata, FunctionTy);
LLVMMetadataRef FooParamExpression =
LLVMDIBuilderCreateExpression(DIB, NULL, 0);
LLVMMetadataRef FooParamVar1 =