[llvm] [LLVM-C][OCaml] Update OCaml bindings to match LLVMMetadataKind in C API (PR #132268)

via llvm-commits llvm-commits at lists.llvm.org
Sun Mar 23 17:32:39 PDT 2025


https://github.com/alan-j-hu updated https://github.com/llvm/llvm-project/pull/132268

>From ab80f9efaca0746c8cf49f8ed5247b9e5bdf04c1 Mon Sep 17 00:00:00 2001
From: Alan Hu <ahulambda at gmail.com>
Date: Thu, 20 Mar 2025 14:17:24 -0400
Subject: [PATCH 1/3] [LLVM-C] Move LLVMDISubrangeTypeMetadataKind to end of
 its 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.
---
 llvm/include/llvm-c/DebugInfo.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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;
 

>From 26a264b72410bcc4145d25fbaaa3ee3fd17babab Mon Sep 17 00:00:00 2001
From: Alan Hu <ahulambda at gmail.com>
Date: Thu, 20 Mar 2025 14:34:27 -0400
Subject: [PATCH 2/3] [OCaml] Bring OCaml bindings up to date with
 LLVMMetadataKind enum

---
 llvm/bindings/ocaml/debuginfo/llvm_debuginfo.ml  | 5 +++++
 llvm/bindings/ocaml/debuginfo/llvm_debuginfo.mli | 5 +++++
 2 files changed, 10 insertions(+)

diff --git a/llvm/bindings/ocaml/debuginfo/llvm_debuginfo.ml b/llvm/bindings/ocaml/debuginfo/llvm_debuginfo.ml
index 1b882d94a30b6..b5c8128c4c090 100644
--- a/llvm/bindings/ocaml/debuginfo/llvm_debuginfo.ml
+++ b/llvm/bindings/ocaml/debuginfo/llvm_debuginfo.ml
@@ -139,6 +139,11 @@ module MetadataKind = struct
     | DIMacroMetadataKind
     | DIMacroFileMetadataKind
     | DICommonBlockMetadataKind
+    | DIStringTypeMetadataKind
+    | DIGenericSubrangeMetadataKind
+    | DIArgListMetadataKind
+    | DIAssignIDMetadataKind
+    | DISubrangeTypeMetadataKind
 end
 
 (** The amount of debug information to emit. *)
diff --git a/llvm/bindings/ocaml/debuginfo/llvm_debuginfo.mli b/llvm/bindings/ocaml/debuginfo/llvm_debuginfo.mli
index 5c619a2646f5f..8a36a2b7d81b1 100644
--- a/llvm/bindings/ocaml/debuginfo/llvm_debuginfo.mli
+++ b/llvm/bindings/ocaml/debuginfo/llvm_debuginfo.mli
@@ -143,6 +143,11 @@ module MetadataKind : sig
     | DIMacroMetadataKind
     | DIMacroFileMetadataKind
     | DICommonBlockMetadataKind
+    | DIStringTypeMetadataKind
+    | DIGenericSubrangeMetadataKind
+    | DIArgListMetadataKind
+    | DIAssignIDMetadataKind
+    | DISubrangeTypeMetadataKind
 end
 
 (** The amount of debug information to emit. *)

>From 52ea0c6361d39590caae0b0a616fff18bb36184a Mon Sep 17 00:00:00 2001
From: Alan Hu <ahulambda at gmail.com>
Date: Sun, 23 Mar 2025 20:32:20 -0400
Subject: [PATCH 3/3] Add comment about appending entries

---
 llvm/include/llvm-c/DebugInfo.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/llvm/include/llvm-c/DebugInfo.h b/llvm/include/llvm-c/DebugInfo.h
index 63f0d4c7b367d..30bbaa4d34161 100644
--- a/llvm/include/llvm-c/DebugInfo.h
+++ b/llvm/include/llvm-c/DebugInfo.h
@@ -158,6 +158,8 @@ typedef enum {
 /**
  * The kind of metadata nodes.
  */
+// NOTE: New entries should always be appended instead of matching the order
+// in Metadata.def.
 enum {
   LLVMMDStringMetadataKind,
   LLVMConstantAsMetadataMetadataKind,



More information about the llvm-commits mailing list