diff --git a/llvm/include/llvm-c/DebugInfo.h b/llvm/include/llvm-c/DebugInfo.h index 991def64028d..ef89a88617be 100644 --- a/llvm/include/llvm-c/DebugInfo.h +++ b/llvm/include/llvm-c/DebugInfo.h @@ -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. * diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp index 196fe294a274..5c645ffe3f3f 100644 --- a/llvm/lib/IR/DebugInfo.cpp +++ b/llvm/lib/IR/DebugInfo.cpp @@ -1813,6 +1813,12 @@ unsigned LLVMDISubprogramGetLine(LLVMMetadataRef Subprogram) { return unwrapDI(Subprogram)->getLine(); } +void LLVMDISubprogramReplaceType(LLVMMetadataRef Subprogram, + LLVMMetadataRef SubroutineType) { + unwrapDI(Subprogram) + ->replaceType(unwrapDI(SubroutineType)); +} + LLVMMetadataRef LLVMInstructionGetDebugLoc(LLVMValueRef Inst) { return wrap(unwrap(Inst)->getDebugLoc().getAsMDNode()); } diff --git a/llvm/tools/llvm-c-test/debuginfo.c b/llvm/tools/llvm-c-test/debuginfo.c index 3ac5a6bc2cf0..8c6f6436782e 100644 --- a/llvm/tools/llvm-c-test/debuginfo.c +++ b/llvm/tools/llvm-c-test/debuginfo.c @@ -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 =