-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[bindings] Add OCaml binding to LLVMGlobalSetMetadata
#131583
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
Conversation
|
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
You can test this locally with the following command:git-clang-format --diff 6b47bba44087caa7d4805bdb3229153a3bfba7a5 0bf3e74a492894f7fb10227797d5d7df73001b08 --extensions c -- llvm/bindings/ocaml/llvm/llvm_ocaml.cView the diff from clang-format here.diff --git a/llvm/bindings/ocaml/llvm/llvm_ocaml.c b/llvm/bindings/ocaml/llvm/llvm_ocaml.c
index 7d32b8b2f6..e3960bac31 100644
--- a/llvm/bindings/ocaml/llvm/llvm_ocaml.c
+++ b/llvm/bindings/ocaml/llvm/llvm_ocaml.c
@@ -1547,7 +1547,8 @@ value llvm_set_global_constant(value Flag, value GlobalVar) {
}
/* llvalue -> llmdkind -> llmetadata -> unit */
-value llvm_global_set_metadata(value Value, value MetadataKind, value Metadata) {
+value llvm_global_set_metadata(value Value, value MetadataKind,
+ value Metadata) {
LLVMGlobalSetMetadata(Value_val(Value), (unsigned int)Int_val(MetadataKind),
Metadata_val(Metadata));
return Val_unit;
|
Format code according to formatter requirements
|
BTW, what is the default OCamlFormat parameters for the binding files? I have OCamlFormat installed locally, but it seems like it's formatting using a different config than the current one. I'm currently maintaining format of OCaml files by hand. |
|
Taking a look at this. Right now I'm getting some test failures involving debuginfo.ml, but I'm still trying to figure out if thy were caused by this PR or some other issue on my end, etc. |
|
When you run the unit tests, is the OCaml debuginfo test failing for you, or is this only on my end? |
|
I'm getting the I'm not sure what's happening here -- I also get failures on the The one I get in this branch is: And the one I get on main branch is this, which is even weirder. But maybe because I have a different version of LLVM opam package installed: |
|
I frequently get this error as well: IIRC it's a bug in some CMakeLists.txt file. You need to explicitly run |
|
Reran. Seems like the same debuginfo test failure is in main branch too, so it's not caused by this PR. |
|
Looks like commit 6b47bba, the last commit on main, has the debuginfo test failure. Commit d8b2e43, the last commit to directly touch the OCaml bindings, does not have the debuginfo test failure. Commit a5fb2bb, the last commit to directly touch the OCaml debuginfo bindings, does not have the debuginfo test failure. So, it looks like the debuginfo test failure was introduced somewhere in-between commit d8b2e43 and commit 6b47bba, in code that did not touch the OCaml bindings. |
|
I used git bisect, which determined that the breaking commit was 8dbc393. This commit seems to be unrelated, so I need to figure out why it breaks the debuginfo test. EDIT: I ran the test again and it seems to be fine, so now I need to do more investigation. Did I mess up the git bisect somewhere? |
|
Looks like the bad commit was the one right after; e298fc2. |
|
Okay, I verified that the failing test doesn't have to do with this PR.
I don't believe the bindings use an ocamlformat file. There is some kind of consistent style that you should try to adhere to, but they're not being enforced by any formatting rules. |
Thanks!
I was asking this because I saw the two IMHO, although unrelated to this PR, that if we have the |
Fix typo and formats Co-authored-by: Alan <[email protected]>
alan-j-hu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed that you made the metadata tests "looser" by checking for a numeric regex instead of the precise metadata ID. As far as I can tell, the tests are still deterministic. Would it be better to continue checking for the exact metadata ID, as the file currently does?
llvm/test/Bindings/OCaml/core.ml
Outdated
| * CHECK: !llvm.module.flags = !{!{{[0-9]+}}} | ||
| * CHECK: !{{[0-9]+}} = !{i32 0, !"global test metadata"} | ||
| * CHECK: !{{[0-9]+}} = !{i32 1, !"Debug Info Version", i32 3} | ||
| * CHECK: !{{[0-9]+}} = !{i32 1, !"metadata test"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| * CHECK: !llvm.module.flags = !{!{{[0-9]+}}} | |
| * CHECK: !{{[0-9]+}} = !{i32 0, !"global test metadata"} | |
| * CHECK: !{{[0-9]+}} = !{i32 1, !"Debug Info Version", i32 3} | |
| * CHECK: !{{[0-9]+}} = !{i32 1, !"metadata test"} | |
| * CHECK: !llvm.module.flags = !{!{{[0-9]+}}} | |
| * CHECK: !0 = !{i32 0, !"global test metadata"} | |
| * CHECK: !1 = !{i32 1, !"Debug Info Version", i32 3} | |
| * CHECK: !2 = !{i32 1, !"metadata test"} |
llvm/test/Bindings/OCaml/core.ml
Outdated
| (* CHECK: %metadata = add i32 %P1, %P2, !test !{{[0-9]+}} | ||
| * Number of metadata nodes is not predictable, so we just check for | ||
| * the presence of metadata here |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even if you were to prefer to check for a numeric regex instead of a precise ID, I don't like the wording of "predictable" in the comment. The tests are still deterministic, i.e. predictable.
| (* CHECK: %metadata = add i32 %P1, %P2, !test !{{[0-9]+}} | |
| * Number of metadata nodes is not predictable, so we just check for | |
| * the presence of metadata here | |
| (* CHECK: %metadata = add i32 %P1, %P2, !test !2 |
|
I see what you mean here. I will change it back to absolute numbers. |
Change test metadata IDs back to numbers
Forgot one place to revert
The module flags is wrong
|
I approve these changes, and will squash and merge them. For the commit message, I will just use the message for the first commit - |
|
Yes, thank you!
…________________________________
From: Alan ***@***.***>
Sent: Saturday, March 22, 2025 12:35:30 AM
To: llvm/llvm-project ***@***.***>
Cc: Rynco Maekawa ***@***.***>; Author ***@***.***>
Subject: Re: [llvm/llvm-project] [bindings] Add OCaml binding to `LLVMGlobalSetMetadata` (PR #131583)
I approve these changes, and will squash and merge them. For the commit message, I will just use the message for the first commit - [bindings] Add `global_set_metadata` for function debuginfo. Is this fine?
—
Reply to this email directly, view it on GitHub<#131583 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/ACOIVL6H2ENGWKQFOOKSX6D2VQ5VFAVCNFSM6AAAAABZE5ZN5CVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDONBTHA4TEMRSHA>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
[alan-j-hu]alan-j-hu left a comment (llvm/llvm-project#131583)<#131583 (comment)>
I approve these changes, and will squash and merge them. For the commit message, I will just use the message for the first commit - [bindings] Add `global_set_metadata` for function debuginfo. Is this fine?
—
Reply to this email directly, view it on GitHub<#131583 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/ACOIVL6H2ENGWKQFOOKSX6D2VQ5VFAVCNFSM6AAAAABZE5ZN5CVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDONBTHA4TEMRSHA>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
|
@lynzrand Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR. Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues. How to do this, and the rest of the post-merge process, is covered in detail here. If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! |
This PR adds the OCaml binding to
LLVMGlobalSetMetadata, so that OCaml users can set metadata on global values like functions. This is useful for e.g. adding debug information to functions.(Note that the existing
set_metadatafunction operates on instructions, and cannot be used to set metadata on global values.)This is my first PR to LLVM, so please tell me if I have done anything wrong.
Although the contribution guide said that contributions should include a unit test, I can't find any unit test in the OCaml bindings, so I guess I can skip that? My fault, I didn't see the test directory. I will add tests soon.Tests are added now.This binding has been tested in our internal projects and worked.
The code within this PR came from a branch of version 18.x. As far as I know, related C bindings haven't changed during the times, so this patch should still be relevant.