Skip to content

llvm-c: Introduce 'LLVMDISubprogramReplaceType' #143461

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 24, 2025

Conversation

davidgmbb
Copy link
Contributor

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

@llvmbot
Copy link
Member

llvmbot commented Jun 10, 2025

@llvm/pr-subscribers-llvm-ir

@llvm/pr-subscribers-debuginfo

Author: David (davidgmbb)

Changes

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


Full diff: https://github.com/llvm/llvm-project/pull/143461.diff

2 Files Affected:

  • (modified) llvm/include/llvm-c/DebugInfo.h (+9)
  • (modified) llvm/lib/IR/DebugInfo.cpp (+4)
diff --git a/llvm/include/llvm-c/DebugInfo.h b/llvm/include/llvm-c/DebugInfo.h
index 991def64028da..bffed4bebbda6 100644
--- a/llvm/include/llvm-c/DebugInfo.h
+++ b/llvm/include/llvm-c/DebugInfo.h
@@ -1420,6 +1420,15 @@ 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 7db9891fdbd75..c26dfcde87edf 100644
--- a/llvm/lib/IR/DebugInfo.cpp
+++ b/llvm/lib/IR/DebugInfo.cpp
@@ -1818,6 +1818,10 @@ 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());
 }

Copy link

github-actions bot commented Jun 10, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@davidgmbb davidgmbb force-pushed the subprogram-replace-type branch from 9150b7e to f423d89 Compare June 10, 2025 00:19
@davidgmbb
Copy link
Contributor Author

ping

@dwblaikie
Copy link
Collaborator

Do we have unit test coverage for other parts of the debug info C API? If so, could you add some for this function too?

@davidgmbb davidgmbb force-pushed the subprogram-replace-type branch from f423d89 to 0c47a11 Compare June 17, 2025 23:59
@davidgmbb
Copy link
Contributor Author

Do we have unit test coverage for other parts of the debug info C API? If so, could you add some for this function too?

Hi. Thanks for taking some time to review the PR. I found some tests and added a call to the new function there, but I don't know if they are automatically triggered in CI runs.

@davidgmbb davidgmbb force-pushed the subprogram-replace-type branch from 0c47a11 to e993a25 Compare June 18, 2025 02:06
@OCHyams
Copy link
Contributor

OCHyams commented Jun 18, 2025

Do we have unit test coverage for other parts of the debug info C API? If so, could you add some for this function too?

Hi. Thanks for taking some time to review the PR. I found some tests and added a call to the new function there, but I don't know if they are automatically triggered in CI runs.

If you build llvm-c-test (e.g. build-dir> ninja llvm-c-test) you can run that specific test with lit llvm-dir> llvm-lit llvm/test/Bindings/llvm-c/debug_info_new_format.ll. I believe it runs as part of ninja check-llvm and therefor IIUC should be run in the pre-merge checks.

@davidgmbb
Copy link
Contributor Author

davidgmbb commented Jun 18, 2025

Do we have unit test coverage for other parts of the debug info C API? If so, could you add some for this function too?

Hi. Thanks for taking some time to review the PR. I found some tests and added a call to the new function there, but I don't know if they are automatically triggered in CI runs.

If you build llvm-c-test (e.g. build-dir> ninja llvm-c-test) you can run that specific test with lit llvm-dir> llvm-lit llvm/test/Bindings/llvm-c/debug_info_new_format.ll. I believe it runs as part of ninja check-llvm and therefor IIUC should be run in the pre-merge checks.

Thanks for the explanation. I checked the logs and that test passed. I am running all the tests locally but I have an old cheap CPU and it's taking forever. If I run just that test it passes.

Copy link
Contributor

@OCHyams OCHyams left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test update LGTM. If @dwblaikie has no further comments, I can merge this for you if you don't have commit access?

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
@davidgmbb davidgmbb force-pushed the subprogram-replace-type branch from e993a25 to 2d2e50c Compare June 24, 2025 12:18
@OCHyams OCHyams merged commit 8fec6d1 into llvm:main Jun 24, 2025
7 checks passed
@davidgmbb davidgmbb deleted the subprogram-replace-type branch June 24, 2025 15:10
DrSergei pushed a commit to DrSergei/llvm-project that referenced this pull request Jun 24, 2025
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
anthonyhatran pushed a commit to anthonyhatran/llvm-project that referenced this pull request Jun 26, 2025
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
rlavaee pushed a commit to rlavaee/llvm-project that referenced this pull request Jul 1, 2025
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants