[llvm] Add debuginfo C support for a SetType, Subrangetype, dynamic array type and replace arrays (PR #135607)

Orlando Cazalet-Hyams via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 4 07:37:50 PDT 2025


================
@@ -1321,6 +1321,53 @@ return wrap(unwrap(Builder)->createEnumerationType(
     LineNumber, SizeInBits, AlignInBits, Elts, unwrapDI<DIType>(ClassTy)));
 }
 
+LLVMMetadataRef LLVMDIBuilderCreateSetType(
+    LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
+    size_t NameLen, LLVMMetadataRef File, unsigned LineNumber,
+    uint64_t SizeInBits, uint32_t AlignInBits, LLVMMetadataRef BaseTy) {
+  return wrap(unwrap(Builder)->createSetType(
+      unwrapDI<DIScope>(Scope), {Name, NameLen}, unwrapDI<DIFile>(File),
+      LineNumber, SizeInBits, AlignInBits, unwrapDI<DIType>(BaseTy)));
+}
+
+LLVMMetadataRef LLVMDIBuilderCreateSubrangeType(
+    LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
+    size_t NameLen, unsigned LineNo, LLVMMetadataRef File, uint64_t SizeInBits,
+    uint32_t AlignInBits, LLVMDIFlags Flags, LLVMMetadataRef BaseTy,
+    LLVMMetadataRef LowerBound, LLVMMetadataRef UpperBound,
+    LLVMMetadataRef Stride, LLVMMetadataRef Bias) {
+  return wrap(unwrap(Builder)->createSubrangeType(
+      {Name, NameLen}, unwrapDI<DIFile>(File), LineNo, unwrapDI<DIScope>(Scope),
+      SizeInBits, AlignInBits, map_from_llvmDIFlags(Flags),
+      unwrapDI<DIType>(BaseTy), unwrap(LowerBound), unwrap(UpperBound),
+      unwrap(Stride), unwrap(Bias)));
+}
+
+LLVMMetadataRef LLVMDIBuilderCreateDynamicArrayType(
+    LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
+    size_t NameLen, unsigned LineNo, LLVMMetadataRef File, uint64_t Size,
+    uint32_t AlignInBits, LLVMMetadataRef Ty, LLVMMetadataRef *Subscripts,
+    unsigned NumSubscripts, LLVMMetadataRef DataLocation,
+    LLVMMetadataRef Associated, LLVMMetadataRef Allocated, LLVMMetadataRef Rank,
+    LLVMMetadataRef BitStride) {
+  auto Subs =
+      unwrap(Builder)->getOrCreateArray({unwrap(Subscripts), NumSubscripts});
+  return wrap(unwrap(Builder)->createArrayType(
+      unwrapDI<DIScope>(Scope), {Name, NameLen}, unwrapDI<DIFile>(File), LineNo,
+      Size, AlignInBits, unwrapDI<DIType>(Ty), Subs,
+      unwrapDI<DIExpression>(DataLocation), unwrapDI<DIExpression>(Associated),
+      unwrapDI<DIExpression>(Allocated), unwrapDI<DIExpression>(Rank),
+      unwrap(BitStride)));
+}
----------------
OCHyams wrote:

Is `unwrapDI<DIExpression>` is the right move for these parameters? `createArrayType` takes `PointerUnion<DIExpression *, DIVariable *>`, as it looks like it expects either 
 an expression or variable, but this implementation means only DIExpressions are accepted by the C interface.
 
Something like the code-suggestion above might be good to cover all inputs. Please can you update the function comment to reflect the accepted types, and update the test to check variables, expressions and null.

```suggestion
/// MD may be nullptr, a DIExpression or DIVariable.
PointerUnion<DIExpression *, DIVariable *> unwrapExprVar(LLVMMetadataRef MD) {
  if (!MD)
    return nullptr;
  MDNode *MDN = unwrapDI<MDNode>(MD);
  if (auto *E = dyn_cast<DIExpression>(MDN))
    return E;
  assert(isa<DIVariable>(MDN) && "Expected DIExpression or DIVariable");
  return cast<DIVariable>(MDN);
}

LLVMMetadataRef LLVMDIBuilderCreateDynamicArrayType(
    LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
    size_t NameLen, unsigned LineNo, LLVMMetadataRef File, uint64_t Size,
    uint32_t AlignInBits, LLVMMetadataRef Ty, LLVMMetadataRef *Subscripts,
    unsigned NumSubscripts, LLVMMetadataRef DataLocation,
    LLVMMetadataRef Associated, LLVMMetadataRef Allocated, LLVMMetadataRef Rank,
    LLVMMetadataRef BitStride) {
  auto Subs =
      unwrap(Builder)->getOrCreateArray({unwrap(Subscripts), NumSubscripts});
  return wrap(unwrap(Builder)->createArrayType(
      unwrapDI<DIScope>(Scope), {Name, NameLen}, unwrapDI<DIFile>(File), LineNo,
      Size, AlignInBits, unwrapDI<DIType>(Ty), Subs,
      unwrapExprVar(DataLocation), unwrapExprVar(Associated),
      unwrapExprVar(Allocated), unwrapExprVar(Rank), unwrap(BitStride)));
}
```

https://github.com/llvm/llvm-project/pull/135607


More information about the llvm-commits mailing list