-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[clang] Remove some uses of llvm::StructType::setBody. NFC. #113691
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
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
It is simple to create the struct body up front, now that we have transitioned to opaque pointers.
Member
|
@llvm/pr-subscribers-clang @llvm/pr-subscribers-clang-codegen Author: Jay Foad (jayfoad) ChangesIt is simple to create the struct body up front, now that we have Full diff: https://github.com/llvm/llvm-project/pull/113691.diff 4 Files Affected:
diff --git a/clang/lib/CodeGen/CGBlocks.cpp b/clang/lib/CodeGen/CGBlocks.cpp
index 41bb8d19d161eb..bfa9b0a2f836bc 100644
--- a/clang/lib/CodeGen/CGBlocks.cpp
+++ b/clang/lib/CodeGen/CGBlocks.cpp
@@ -2590,10 +2590,6 @@ const BlockByrefInfo &CodeGenFunction::getBlockByrefInfo(const VarDecl *D) {
if (it != BlockByrefInfos.end())
return it->second;
- llvm::StructType *byrefType =
- llvm::StructType::create(getLLVMContext(),
- "struct.__block_byref_" + D->getNameAsString());
-
QualType Ty = D->getType();
CharUnits size;
@@ -2658,7 +2654,9 @@ const BlockByrefInfo &CodeGenFunction::getBlockByrefInfo(const VarDecl *D) {
}
types.push_back(varTy);
- byrefType->setBody(types, packed);
+ llvm::StructType *byrefType = llvm::StructType::create(
+ getLLVMContext(), types, "struct.__block_byref_" + D->getNameAsString(),
+ packed);
BlockByrefInfo info;
info.Type = byrefType;
diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index 7a07284f8a8aa5..d6f5f2a43cf51b 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -1509,8 +1509,8 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
GetSectionBounds(StringRef Section) {
if (CGM.getTriple().isOSBinFormatCOFF()) {
if (emptyStruct == nullptr) {
- emptyStruct = llvm::StructType::create(VMContext, ".objc_section_sentinel");
- emptyStruct->setBody({}, /*isPacked*/true);
+ emptyStruct = llvm::StructType::create(
+ VMContext, {}, ".objc_section_sentinel", /*isPacked=*/true);
}
auto ZeroInit = llvm::Constant::getNullValue(emptyStruct);
auto Sym = [&](StringRef Prefix, StringRef SecSuffix) {
diff --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp
index 1c16d273a55357..47ea636c756438 100644
--- a/clang/lib/CodeGen/CGObjCMac.cpp
+++ b/clang/lib/CodeGen/CGObjCMac.cpp
@@ -5835,15 +5835,7 @@ ObjCTypesHelper::ObjCTypesHelper(CodeGen::CodeGenModule &cgm)
// struct _objc_protocol_extension *
ProtocolExtensionPtrTy = llvm::PointerType::getUnqual(ProtocolExtensionTy);
- // Handle recursive construction of Protocol and ProtocolList types
-
- ProtocolTy =
- llvm::StructType::create(VMContext, "struct._objc_protocol");
-
- ProtocolListTy =
- llvm::StructType::create(VMContext, "struct._objc_protocol_list");
- ProtocolListTy->setBody(llvm::PointerType::getUnqual(ProtocolListTy), LongTy,
- llvm::ArrayType::get(ProtocolTy, 0));
+ // Handle construction of Protocol and ProtocolList types
// struct _objc_protocol {
// struct _objc_protocol_extension *isa;
@@ -5852,9 +5844,16 @@ ObjCTypesHelper::ObjCTypesHelper(CodeGen::CodeGenModule &cgm)
// struct _objc_method_description_list *instance_methods;
// struct _objc_method_description_list *class_methods;
// }
- ProtocolTy->setBody(ProtocolExtensionPtrTy, Int8PtrTy,
- llvm::PointerType::getUnqual(ProtocolListTy),
- MethodDescriptionListPtrTy, MethodDescriptionListPtrTy);
+ ProtocolTy = llvm::StructType::create(
+ {ProtocolExtensionPtrTy, Int8PtrTy,
+ llvm::PointerType::getUnqual(VMContext), MethodDescriptionListPtrTy,
+ MethodDescriptionListPtrTy},
+ "struct._objc_protocol");
+
+ ProtocolListTy =
+ llvm::StructType::create({llvm::PointerType::getUnqual(VMContext), LongTy,
+ llvm::ArrayType::get(ProtocolTy, 0)},
+ "struct._objc_protocol_list");
// struct _objc_protocol_list *
ProtocolListPtrTy = llvm::PointerType::getUnqual(ProtocolListTy);
@@ -5886,8 +5885,6 @@ ObjCTypesHelper::ObjCTypesHelper(CodeGen::CodeGenModule &cgm)
"struct._objc_class_extension", IntTy, Int8PtrTy, PropertyListPtrTy);
ClassExtensionPtrTy = llvm::PointerType::getUnqual(ClassExtensionTy);
- ClassTy = llvm::StructType::create(VMContext, "struct._objc_class");
-
// struct _objc_class {
// Class isa;
// Class super_class;
@@ -5902,10 +5899,12 @@ ObjCTypesHelper::ObjCTypesHelper(CodeGen::CodeGenModule &cgm)
// char *ivar_layout;
// struct _objc_class_ext *ext;
// };
- ClassTy->setBody(llvm::PointerType::getUnqual(ClassTy),
- llvm::PointerType::getUnqual(ClassTy), Int8PtrTy, LongTy,
- LongTy, LongTy, IvarListPtrTy, MethodListPtrTy, CachePtrTy,
- ProtocolListPtrTy, Int8PtrTy, ClassExtensionPtrTy);
+ ClassTy = llvm::StructType::create(
+ {llvm::PointerType::getUnqual(VMContext),
+ llvm::PointerType::getUnqual(VMContext), Int8PtrTy, LongTy, LongTy,
+ LongTy, IvarListPtrTy, MethodListPtrTy, CachePtrTy, ProtocolListPtrTy,
+ Int8PtrTy, ClassExtensionPtrTy},
+ "struct._objc_class");
ClassPtrTy = llvm::PointerType::getUnqual(ClassTy);
@@ -5988,13 +5987,9 @@ ObjCNonFragileABITypesHelper::ObjCNonFragileABITypesHelper(CodeGen::CodeGenModul
// const struct _prop_list_t * class_properties;
// }
- // Holder for struct _protocol_list_t *
- ProtocolListnfABITy =
- llvm::StructType::create(VMContext, "struct._objc_protocol_list");
-
ProtocolnfABITy = llvm::StructType::create(
"struct._protocol_t", ObjectPtrTy, Int8PtrTy,
- llvm::PointerType::getUnqual(ProtocolListnfABITy), MethodListnfABIPtrTy,
+ llvm::PointerType::getUnqual(VMContext), MethodListnfABIPtrTy,
MethodListnfABIPtrTy, MethodListnfABIPtrTy, MethodListnfABIPtrTy,
PropertyListPtrTy, IntTy, IntTy, Int8PtrPtrTy, Int8PtrTy,
PropertyListPtrTy);
@@ -6006,8 +6001,9 @@ ObjCNonFragileABITypesHelper::ObjCNonFragileABITypesHelper(CodeGen::CodeGenModul
// long protocol_count; // Note, this is 32/64 bit
// struct _protocol_t *[protocol_count];
// }
- ProtocolListnfABITy->setBody(LongTy,
- llvm::ArrayType::get(ProtocolnfABIPtrTy, 0));
+ ProtocolListnfABITy = llvm::StructType::create(
+ {LongTy, llvm::ArrayType::get(ProtocolnfABIPtrTy, 0)},
+ "struct._objc_protocol_list");
// struct _objc_protocol_list*
ProtocolListnfABIPtrTy = llvm::PointerType::getUnqual(ProtocolListnfABITy);
@@ -6067,11 +6063,12 @@ ObjCNonFragileABITypesHelper::ObjCNonFragileABITypesHelper(CodeGen::CodeGenModul
// struct class_ro_t *ro;
// }
- ClassnfABITy = llvm::StructType::create(VMContext, "struct._class_t");
- ClassnfABITy->setBody(llvm::PointerType::getUnqual(ClassnfABITy),
- llvm::PointerType::getUnqual(ClassnfABITy), CachePtrTy,
- llvm::PointerType::getUnqual(ImpnfABITy),
- llvm::PointerType::getUnqual(ClassRonfABITy));
+ ClassnfABITy = llvm::StructType::create(
+ {llvm::PointerType::getUnqual(VMContext),
+ llvm::PointerType::getUnqual(VMContext), CachePtrTy,
+ llvm::PointerType::getUnqual(ImpnfABITy),
+ llvm::PointerType::getUnqual(ClassRonfABITy)},
+ "struct._class_t");
// LLVM for struct _class_t *
ClassnfABIPtrTy = llvm::PointerType::getUnqual(ClassnfABITy);
diff --git a/clang/lib/CodeGen/MicrosoftCXXABI.cpp b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
index 0b0b45ffead92f..3802dc8bcafc49 100644
--- a/clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -529,31 +529,29 @@ class MicrosoftCXXABI : public CGCXXABI {
if (ClassHierarchyDescriptorType)
return ClassHierarchyDescriptorType;
// Forward-declare RTTIClassHierarchyDescriptor to break a cycle.
- ClassHierarchyDescriptorType = llvm::StructType::create(
- CGM.getLLVMContext(), "rtti.ClassHierarchyDescriptor");
llvm::Type *FieldTypes[] = {CGM.IntTy, CGM.IntTy, CGM.IntTy,
getImageRelativeType(CGM.UnqualPtrTy)};
- ClassHierarchyDescriptorType->setBody(FieldTypes);
+ ClassHierarchyDescriptorType =
+ llvm::StructType::create(FieldTypes, "rtti.ClassHierarchyDescriptor");
return ClassHierarchyDescriptorType;
}
llvm::StructType *getCompleteObjectLocatorType() {
if (CompleteObjectLocatorType)
return CompleteObjectLocatorType;
- CompleteObjectLocatorType = llvm::StructType::create(
- CGM.getLLVMContext(), "rtti.CompleteObjectLocator");
llvm::Type *FieldTypes[] = {
CGM.IntTy,
CGM.IntTy,
CGM.IntTy,
getImageRelativeType(CGM.Int8PtrTy),
getImageRelativeType(CGM.UnqualPtrTy),
- getImageRelativeType(CompleteObjectLocatorType),
+ getImageRelativeType(CGM.VoidTy),
};
llvm::ArrayRef<llvm::Type *> FieldTypesRef(FieldTypes);
if (!isImageRelative())
FieldTypesRef = FieldTypesRef.drop_back();
- CompleteObjectLocatorType->setBody(FieldTypesRef);
+ CompleteObjectLocatorType =
+ llvm::StructType::create(FieldTypesRef, "rtti.CompleteObjectLocator");
return CompleteObjectLocatorType;
}
|
rjmccall
approved these changes
Oct 30, 2024
Contributor
rjmccall
left a comment
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.
LGTM
NoumanAmir657
pushed a commit
to NoumanAmir657/llvm-project
that referenced
this pull request
Nov 4, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
clang:codegen
IR generation bugs: mangling, exceptions, etc.
clang
Clang issues not falling into any other category
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
It is simple to create the struct body up front, now that we have
transitioned to opaque pointers.