-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Add RunTimeLang to Class and Enumeration DIBuilder functions #72011
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-clang-codegen @llvm/pr-subscribers-llvm-ir Author: Augusto Noronha (augusto2112) ChangesRunTimeLang is already supported by DICompositeType, and already used by structs and unions. Add a new parameter in the class and enumeration create methods, so they can use the RunTimeLang attribute as well. Full diff: https://github.com/llvm/llvm-project/pull/72011.diff 4 Files Affected:
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp
index 84a166d3ac3659c..fc8088da998ddbd 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -3385,9 +3385,9 @@ llvm::DIType *CGDebugInfo::CreateTypeDefinition(const EnumType *Ty) {
unsigned Line = getLineNumber(ED->getLocation());
llvm::DIScope *EnumContext = getDeclContextDescriptor(ED);
llvm::DIType *ClassTy = getOrCreateType(ED->getIntegerType(), DefUnit);
- return DBuilder.createEnumerationType(EnumContext, ED->getName(), DefUnit,
- Line, Size, Align, EltArray, ClassTy,
- Identifier, ED->isScoped());
+ return DBuilder.createEnumerationType(
+ EnumContext, ED->getName(), DefUnit, Line, Size, Align, EltArray, ClassTy,
+ /*RunTimeLang=*/0, Identifier, ED->isScoped());
}
llvm::DIMacro *CGDebugInfo::CreateMacro(llvm::DIMacroFile *Parent,
diff --git a/llvm/include/llvm/IR/DIBuilder.h b/llvm/include/llvm/IR/DIBuilder.h
index ecd6dd7b0a4f822..9c8646c8a544b74 100644
--- a/llvm/include/llvm/IR/DIBuilder.h
+++ b/llvm/include/llvm/IR/DIBuilder.h
@@ -424,6 +424,7 @@ namespace llvm {
/// \param OffsetInBits Member offset.
/// \param Flags Flags to encode member attribute, e.g. private
/// \param Elements class members.
+ /// \param RunTimeLang Optional parameter, Objective-C runtime version.
/// \param VTableHolder Debug info of the base class that contains vtable
/// for this type. This is used in
/// DW_AT_containing_type. See DWARF documentation
@@ -434,8 +435,8 @@ namespace llvm {
DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
DINode::DIFlags Flags, DIType *DerivedFrom, DINodeArray Elements,
- DIType *VTableHolder = nullptr, MDNode *TemplateParms = nullptr,
- StringRef UniqueIdentifier = "");
+ unsigned RunTimeLang = 0, DIType *VTableHolder = nullptr,
+ MDNode *TemplateParms = nullptr, StringRef UniqueIdentifier = "");
/// Create debugging information entry for a struct.
/// \param Scope Scope in which this struct is defined.
@@ -578,13 +579,14 @@ namespace llvm {
/// \param AlignInBits Member alignment.
/// \param Elements Enumeration elements.
/// \param UnderlyingType Underlying type of a C++11/ObjC fixed enum.
+ /// \param RunTimeLang Optional parameter, Objective-C runtime version.
/// \param UniqueIdentifier A unique identifier for the enum.
/// \param IsScoped Boolean flag indicate if this is C++11/ObjC 'enum class'.
DICompositeType *createEnumerationType(
DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
uint64_t SizeInBits, uint32_t AlignInBits, DINodeArray Elements,
- DIType *UnderlyingType, StringRef UniqueIdentifier = "", bool IsScoped = false);
-
+ DIType *UnderlyingType, unsigned RunTimeLang = 0,
+ StringRef UniqueIdentifier = "", bool IsScoped = false);
/// Create debugging information entry for a set.
/// \param Scope Scope in which this set is defined.
/// \param Name Set name.
diff --git a/llvm/lib/IR/DIBuilder.cpp b/llvm/lib/IR/DIBuilder.cpp
index 1ce8c17f8a880f6..b466018e9a7d998 100644
--- a/llvm/lib/IR/DIBuilder.cpp
+++ b/llvm/lib/IR/DIBuilder.cpp
@@ -477,14 +477,15 @@ DICompositeType *DIBuilder::createClassType(
DIScope *Context, StringRef Name, DIFile *File, unsigned LineNumber,
uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
DINode::DIFlags Flags, DIType *DerivedFrom, DINodeArray Elements,
- DIType *VTableHolder, MDNode *TemplateParams, StringRef UniqueIdentifier) {
+ unsigned RunTimeLang, DIType *VTableHolder, MDNode *TemplateParams,
+ StringRef UniqueIdentifier) {
assert((!Context || isa<DIScope>(Context)) &&
"createClassType should be called with a valid Context");
auto *R = DICompositeType::get(
VMContext, dwarf::DW_TAG_structure_type, Name, File, LineNumber,
getNonCompileUnitScope(Context), DerivedFrom, SizeInBits, AlignInBits,
- OffsetInBits, Flags, Elements, 0, VTableHolder,
+ OffsetInBits, Flags, Elements, RunTimeLang, VTableHolder,
cast_or_null<MDTuple>(TemplateParams), UniqueIdentifier);
trackIfUnresolved(R);
return R;
@@ -535,15 +536,17 @@ DISubroutineType *DIBuilder::createSubroutineType(DITypeRefArray ParameterTypes,
return DISubroutineType::get(VMContext, Flags, CC, ParameterTypes);
}
-DICompositeType *DIBuilder::createEnumerationType(
- DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
- uint64_t SizeInBits, uint32_t AlignInBits, DINodeArray Elements,
- DIType *UnderlyingType, StringRef UniqueIdentifier, bool IsScoped) {
+DICompositeType *
+DIBuilder::createEnumerationType(DIScope *Scope, StringRef Name, DIFile *File,
+ unsigned LineNumber, uint64_t SizeInBits,
+ uint32_t AlignInBits, DINodeArray Elements,
+ DIType *UnderlyingType, unsigned RunTimeLang,
+ StringRef UniqueIdentifier, bool IsScoped) {
auto *CTy = DICompositeType::get(
VMContext, dwarf::DW_TAG_enumeration_type, Name, File, LineNumber,
getNonCompileUnitScope(Scope), UnderlyingType, SizeInBits, AlignInBits, 0,
- IsScoped ? DINode::FlagEnumClass : DINode::FlagZero, Elements, 0, nullptr,
- nullptr, UniqueIdentifier);
+ IsScoped ? DINode::FlagEnumClass : DINode::FlagZero, Elements,
+ RunTimeLang, nullptr, nullptr, UniqueIdentifier);
AllEnumTypes.emplace_back(CTy);
trackIfUnresolved(CTy);
return CTy;
diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp
index 390a27c4bc0c4dd..501eec3dd99c1e5 100644
--- a/llvm/lib/IR/DebugInfo.cpp
+++ b/llvm/lib/IR/DebugInfo.cpp
@@ -1467,13 +1467,12 @@ LLVMMetadataRef LLVMDIBuilderCreateClassType(LLVMDIBuilderRef Builder,
auto Elts = unwrap(Builder)->getOrCreateArray({unwrap(Elements),
NumElements});
return wrap(unwrap(Builder)->createClassType(
- unwrapDI<DIScope>(Scope), {Name, NameLen},
- unwrapDI<DIFile>(File), LineNumber,
- SizeInBits, AlignInBits, OffsetInBits,
- map_from_llvmDIFlags(Flags), unwrapDI<DIType>(DerivedFrom),
- Elts, unwrapDI<DIType>(VTableHolder),
- unwrapDI<MDNode>(TemplateParamsNode),
- {UniqueIdentifier, UniqueIdentifierLen}));
+ unwrapDI<DIScope>(Scope), {Name, NameLen}, unwrapDI<DIFile>(File),
+ LineNumber, SizeInBits, AlignInBits, OffsetInBits,
+ map_from_llvmDIFlags(Flags), unwrapDI<DIType>(DerivedFrom), Elts,
+ /*RunTimeLang=*/0, unwrapDI<DIType>(VTableHolder),
+ unwrapDI<MDNode>(TemplateParamsNode),
+ {UniqueIdentifier, UniqueIdentifierLen}));
}
LLVMMetadataRef
|
You can test this locally with the following command:git-clang-format --diff c05ab7b8507a33d5e069ebbe10a5c607995c9c11 8cebb68070de258e6f581e83c3b0541087f53570 -- clang/lib/CodeGen/CGDebugInfo.cpp llvm/include/llvm/IR/DIBuilder.h llvm/lib/IR/DIBuilder.cpp llvm/lib/IR/DebugInfo.cpp View the diff from clang-format here.diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp
index 501eec3dd9..1d2f938090 100644
--- a/llvm/lib/IR/DebugInfo.cpp
+++ b/llvm/lib/IR/DebugInfo.cpp
@@ -1315,17 +1315,15 @@ LLVMDIBuilderCreateUnspecifiedType(LLVMDIBuilderRef Builder, const char *Name,
return wrap(unwrap(Builder)->createUnspecifiedType({Name, NameLen}));
}
-LLVMMetadataRef
-LLVMDIBuilderCreateStaticMemberType(
+LLVMMetadataRef LLVMDIBuilderCreateStaticMemberType(
LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
size_t NameLen, LLVMMetadataRef File, unsigned LineNumber,
LLVMMetadataRef Type, LLVMDIFlags Flags, LLVMValueRef ConstantVal,
uint32_t AlignInBits) {
return wrap(unwrap(Builder)->createStaticMemberType(
- unwrapDI<DIScope>(Scope), {Name, NameLen},
- unwrapDI<DIFile>(File), LineNumber, unwrapDI<DIType>(Type),
- map_from_llvmDIFlags(Flags), unwrap<Constant>(ConstantVal),
- AlignInBits));
+ unwrapDI<DIScope>(Scope), {Name, NameLen}, unwrapDI<DIFile>(File),
+ LineNumber, unwrapDI<DIType>(Type), map_from_llvmDIFlags(Flags),
+ unwrap<Constant>(ConstantVal), AlignInBits));
}
LLVMMetadataRef
|
82e6fef
to
051bd74
Compare
ping :) |
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.
Sorry for the delay!
Let's add the [DebugInfo][CGDebugInfo]
tags the commit title so that the git log is more searchable.
I think we should have at least one test in this patch as well
@@ -424,6 +424,7 @@ namespace llvm { | |||
/// \param OffsetInBits Member offset. | |||
/// \param Flags Flags to encode member attribute, e.g. private | |||
/// \param Elements class members. | |||
/// \param RunTimeLang Optional parameter, Objective-C runtime version. |
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.
let's use an optional
type to denote an optional value
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 think your entire patch would be a lot simpler if this were the last parameter of the function, as you wouldn't need to change as many callsites and have inline comments explaining the parameter. Did you have a motivation in mind for placing the argument 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.
I think your entire patch would be a lot simpler if this were the last parameter of the function, as you wouldn't need to change as many callsites and have inline comments explaining the parameter. Did you have a motivation in mind for placing the argument here?
I'm following the pattern on the ordering from the existing functions, for example:
DICompositeType *createStructType(
DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
uint64_t SizeInBits, uint32_t AlignInBits, DINode::DIFlags Flags,
DIType *DerivedFrom, DINodeArray Elements, unsigned RunTimeLang = 0,
DIType *VTableHolder = nullptr, StringRef UniqueIdentifier = "");
DICompositeType *createUnionType(DIScope *Scope, StringRef Name,
DIFile *File, unsigned LineNumber,
uint64_t SizeInBits, uint32_t AlignInBits,
DINode::DIFlags Flags,
DINodeArray Elements,
unsigned RunTimeLang = 0,
StringRef UniqueIdentifier = "");
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.
Ah, that's fair then
@felipepiovezan I don't this patch as it is has any changes that are testable. I haven't added any code that will emit a RuntimeLang, only added the option to do that so I can add those callers downstream. In retrospect I should've marked it as NFC. |
I see. I think this is yet another argument for flipping the argument order: if the new thing were the last argument, it would have been even more evident this is NFC :) |
RunTimeLang is already supported by DICompositeType, and already used by structs and unions. Add a new parameter in the class and enumeration create methods, so they can use the RunTimeLang attribute as well.
051bd74
to
8cebb68
Compare
In LLVM-18, RunTimeLang is added to enums and classes: llvm/llvm-project#72011 Rather than passing the parameter through, we default it to 0 since it will not reliably do anything until Rust requires LLVM 18, and we always pass 0 to the APIs for similar debug structures.
…ype() Added in LLVM in llvm/llvm-project#72011.
llvm-wrapper: Pass newly added param to DIBuilder::createEnumerationType() Added in LLVM in llvm/llvm-project#72011.
Makes llpc compatible with the change in llvm/llvm-project#72011
Makes llpc compatible with the change in llvm/llvm-project#72011
RunTimeLang is already supported by DICompositeType, and already used by structs and unions. Add a new parameter in the class and enumeration create methods, so they can use the RunTimeLang attribute as well.