-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[LLVM-C][OCaml] Update OCaml bindings to match LLVMMetadataKind in C API #132268
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
@llvm/pr-subscribers-debuginfo Author: Alan (alan-j-hu) ChangesInserting a new enum constant in the middle of the enum breaks the ABI for that enum. Commit e298fc2 introduced this issue, which was revealed because the OCaml binding tests failed. Full diff: https://github.com/llvm/llvm-project/pull/132268.diff 1 Files Affected:
diff --git a/llvm/include/llvm-c/DebugInfo.h b/llvm/include/llvm-c/DebugInfo.h
index 9d0875a4ed8d8..63f0d4c7b367d 100644
--- a/llvm/include/llvm-c/DebugInfo.h
+++ b/llvm/include/llvm-c/DebugInfo.h
@@ -172,7 +172,6 @@ enum {
LLVMDIEnumeratorMetadataKind,
LLVMDIBasicTypeMetadataKind,
LLVMDIDerivedTypeMetadataKind,
- LLVMDISubrangeTypeMetadataKind,
LLVMDICompositeTypeMetadataKind,
LLVMDISubroutineTypeMetadataKind,
LLVMDIFileMetadataKind,
@@ -196,6 +195,7 @@ enum {
LLVMDIGenericSubrangeMetadataKind,
LLVMDIArgListMetadataKind,
LLVMDIAssignIDMetadataKind,
+ LLVMDISubrangeTypeMetadataKind,
};
typedef unsigned LLVMMetadataKind;
|
2905d5d
to
ab80f9e
Compare
Also brought OCaml bindings up to date with the LLVMMetadataKind enum (there were some constants in the C enum that were missing corresponding cases in the OCaml type) |
I'm not sure what LLVM's practices are; is it always recommended to add new enum variants to the end to avoid ABI breakage; or is it fine to add new enum constants in the middle, and I should just update the OCaml bindings to properly reflect the C API? |
Uff, this is super broken. It looks like people are not aware of the fact that this enum must list entries in the same order as https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/IR/Metadata.def and that it is an append-only list. It looks like stuff like DIAssignID got inserted into the middle of the list :( I think we should either have Metadata.def explicitly list the ID (like FixedMetadataKinds.def) or else create an explicit mapping operation between the C API enum and the C++ one. |
Could we move DebugInfo.h to use the .def file (I seem to recall another recent review where someone was proposing removing .def usage from a C API header because it made it easier for some tooling to process it - but keeping a single source of truth seems more important?)? That doesn't address the "append only" nature - but I guess put big scary comments about that as best we can. |
Ah, |
Actually, I'm just wrong here, sorry. Looking closer, there actually is a mapping between the C enum and C++ enum: llvm-project/llvm/lib/IR/DebugInfo.cpp Lines 1857 to 1866 in 387f3e8
|
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.
With that in mind, this LGTM.
@@ -196,6 +195,7 @@ enum { | |||
LLVMDIGenericSubrangeMetadataKind, | |||
LLVMDIArgListMetadataKind, | |||
LLVMDIAssignIDMetadataKind, | |||
LLVMDISubrangeTypeMetadataKind, |
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.
Maybe add a comment above this enum that new entries should always be appended instead of matching the order in Metadata.def?
…ings - Move LLVMDISubrangeTypeMetadataKind to end of LLVMMetadataKind enum. Inserting a new enum constant in the middle of the enum breaks the ABI for that enum. Commit e298fc2 introduced this issue, which was revealed because the OCaml binding tests failed. - Bring OCaml bindings up to date with LLVMMetadataKind enum.
52ea0c6
to
d4c9d9b
Compare
Inserting a new enum constant in the middle of the enum breaks the ABI for that enum. Commit e298fc2 introduced this issue, which was revealed because the OCaml binding tests failed.