-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Add overload of DIBuilder::createArrayType #125229
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. |
@llvm/pr-subscribers-llvm-ir Author: Tom Tromey (tromey) ChangesDICompositeType has an attribute representing the name of a type, but currently it isn't possible to set this for array types via the DIBuilder method. This patch adds a new overload of DIBuilder::createArrayType that allows "full" construction of an array type. This is useful for Ada, where arrays are a bit more first-class than C. Full diff: https://github.com/llvm/llvm-project/pull/125229.diff 3 Files Affected:
diff --git a/llvm/include/llvm/IR/DIBuilder.h b/llvm/include/llvm/IR/DIBuilder.h
index 6c479415b9ed27..c587cc61d83ca3 100644
--- a/llvm/include/llvm/IR/DIBuilder.h
+++ b/llvm/include/llvm/IR/DIBuilder.h
@@ -606,6 +606,35 @@ namespace llvm {
PointerUnion<DIExpression *, DIVariable *> Allocated = nullptr,
PointerUnion<DIExpression *, DIVariable *> Rank = nullptr);
+ /// Create debugging information entry for an array.
+ /// \param Scope Scope in which this enumeration is defined.
+ /// \param Name Union name.
+ /// \param File File where this member is defined.
+ /// \param LineNumber Line number.
+ /// \param Size Array size.
+ /// \param AlignInBits Alignment.
+ /// \param Ty Element type.
+ /// \param Subscripts Subscripts.
+ /// \param DataLocation The location of the raw data of a descriptor-based
+ /// Fortran array, either a DIExpression* or
+ /// a DIVariable*.
+ /// \param Associated The associated attribute of a descriptor-based
+ /// Fortran array, either a DIExpression* or
+ /// a DIVariable*.
+ /// \param Allocated The allocated attribute of a descriptor-based
+ /// Fortran array, either a DIExpression* or
+ /// a DIVariable*.
+ /// \param Rank The rank attribute of a descriptor-based
+ /// Fortran array, either a DIExpression* or
+ /// a DIVariable*.
+ DICompositeType *createArrayType(
+ DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
+ uint64_t Size, uint32_t AlignInBits, DIType *Ty, DINodeArray Subscripts,
+ PointerUnion<DIExpression *, DIVariable *> DataLocation = nullptr,
+ PointerUnion<DIExpression *, DIVariable *> Associated = nullptr,
+ PointerUnion<DIExpression *, DIVariable *> Allocated = nullptr,
+ PointerUnion<DIExpression *, DIVariable *> Rank = nullptr);
+
/// Create debugging information entry for a vector type.
/// \param Size Array size.
/// \param AlignInBits Alignment.
diff --git a/llvm/lib/IR/DIBuilder.cpp b/llvm/lib/IR/DIBuilder.cpp
index 8f9462ab46d885..6b3e3c5c5eea9f 100644
--- a/llvm/lib/IR/DIBuilder.cpp
+++ b/llvm/lib/IR/DIBuilder.cpp
@@ -616,6 +616,29 @@ DIBuilder::createArrayType(uint64_t Size, uint32_t AlignInBits, DIType *Ty,
return R;
}
+DICompositeType *DIBuilder::createArrayType(
+ DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
+ uint64_t Size, uint32_t AlignInBits, DIType *Ty, DINodeArray Subscripts,
+ PointerUnion<DIExpression *, DIVariable *> DL,
+ PointerUnion<DIExpression *, DIVariable *> AS,
+ PointerUnion<DIExpression *, DIVariable *> AL,
+ PointerUnion<DIExpression *, DIVariable *> RK) {
+ auto *R = DICompositeType::get(
+ VMContext, dwarf::DW_TAG_array_type, Name, File, LineNumber,
+ getNonCompileUnitScope(Scope), Ty, Size, AlignInBits, 0, DINode::FlagZero,
+ Subscripts, 0, nullptr, nullptr, "", nullptr,
+ isa<DIExpression *>(DL) ? (Metadata *)cast<DIExpression *>(DL)
+ : (Metadata *)cast<DIVariable *>(DL),
+ isa<DIExpression *>(AS) ? (Metadata *)cast<DIExpression *>(AS)
+ : (Metadata *)cast<DIVariable *>(AS),
+ isa<DIExpression *>(AL) ? (Metadata *)cast<DIExpression *>(AL)
+ : (Metadata *)cast<DIVariable *>(AL),
+ isa<DIExpression *>(RK) ? (Metadata *)cast<DIExpression *>(RK)
+ : (Metadata *)cast<DIVariable *>(RK));
+ trackIfUnresolved(R);
+ return R;
+}
+
DICompositeType *DIBuilder::createVectorType(uint64_t Size,
uint32_t AlignInBits, DIType *Ty,
DINodeArray Subscripts) {
diff --git a/llvm/unittests/IR/DebugInfoTest.cpp b/llvm/unittests/IR/DebugInfoTest.cpp
index 4283ba7a8f8236..c632bd6d3cbb54 100644
--- a/llvm/unittests/IR/DebugInfoTest.cpp
+++ b/llvm/unittests/IR/DebugInfoTest.cpp
@@ -1270,6 +1270,12 @@ TEST(DIBuilder, CompositeTypes) {
DICompositeType *Array = DIB.createArrayType(8, 8, nullptr, {});
EXPECT_EQ(Array->getTag(), dwarf::DW_TAG_array_type);
+ StringRef ArrayNameExp = "AnArray";
+ DICompositeType *NamedArray =
+ DIB.createArrayType(nullptr, ArrayNameExp, nullptr, 0, 8, 8, nullptr, {});
+ EXPECT_EQ(NamedArray->getTag(), dwarf::DW_TAG_array_type);
+ EXPECT_EQ(NamedArray->getName(), ArrayNameExp);
+
DICompositeType *Vector = DIB.createVectorType(8, 8, nullptr, {});
EXPECT_EQ(Vector->getTag(), dwarf::DW_TAG_array_type);
|
I do not think those failures could possibly come from this patch...? |
I rebased this; it needed one minor change to still compile. |
@dwblaikie I looked in llvm/Maintainers.md and you were listed in the "Debug info and DWARF" with the note "especially type information", so I'm taking the liberty of CCing you. The bot didn't add the "debuginfo" tag to this patch for whatever reason. |
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.
(if necessary (perhaps it falls out naturally from the implementation already, but I wouldn't assume so) I guess you'll send a separate patch to actually emit this name in llvm/lib/CodeGen/AsmPrinter/Dwarf*?)
This already works because |
DICompositeType has an attribute representing the name of a type, but currently it isn't possible to set this for array types via the DIBuilder method. This patch adds a new overload of DIBuilder::createArrayType that allows "full" construction of an array type. This is useful for Ada, where arrays are a bit more first-class than C.
@tromey 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! |
DICompositeType has an attribute representing the name of a type, but currently it isn't possible to set this for array types via the DIBuilder method. This patch adds a new overload of DIBuilder::createArrayType that allows "full" construction of an array type. This is useful for Ada, where arrays are a bit more first-class than C.