Skip to content

Commit 463a4c1

Browse files
authored
[clang] Remove some uses of llvm::StructType::setBody. NFC. (#113691)
It is simple to create the struct body up front, now that we have transitioned to opaque pointers.
1 parent 311c077 commit 463a4c1

File tree

4 files changed

+37
-44
lines changed

4 files changed

+37
-44
lines changed

clang/lib/CodeGen/CGBlocks.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2590,10 +2590,6 @@ const BlockByrefInfo &CodeGenFunction::getBlockByrefInfo(const VarDecl *D) {
25902590
if (it != BlockByrefInfos.end())
25912591
return it->second;
25922592

2593-
llvm::StructType *byrefType =
2594-
llvm::StructType::create(getLLVMContext(),
2595-
"struct.__block_byref_" + D->getNameAsString());
2596-
25972593
QualType Ty = D->getType();
25982594

25992595
CharUnits size;
@@ -2658,7 +2654,9 @@ const BlockByrefInfo &CodeGenFunction::getBlockByrefInfo(const VarDecl *D) {
26582654
}
26592655
types.push_back(varTy);
26602656

2661-
byrefType->setBody(types, packed);
2657+
llvm::StructType *byrefType = llvm::StructType::create(
2658+
getLLVMContext(), types, "struct.__block_byref_" + D->getNameAsString(),
2659+
packed);
26622660

26632661
BlockByrefInfo info;
26642662
info.Type = byrefType;

clang/lib/CodeGen/CGObjCGNU.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,8 +1509,8 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
15091509
GetSectionBounds(StringRef Section) {
15101510
if (CGM.getTriple().isOSBinFormatCOFF()) {
15111511
if (emptyStruct == nullptr) {
1512-
emptyStruct = llvm::StructType::create(VMContext, ".objc_section_sentinel");
1513-
emptyStruct->setBody({}, /*isPacked*/true);
1512+
emptyStruct = llvm::StructType::create(
1513+
VMContext, {}, ".objc_section_sentinel", /*isPacked=*/true);
15141514
}
15151515
auto ZeroInit = llvm::Constant::getNullValue(emptyStruct);
15161516
auto Sym = [&](StringRef Prefix, StringRef SecSuffix) {

clang/lib/CodeGen/CGObjCMac.cpp

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5835,15 +5835,7 @@ ObjCTypesHelper::ObjCTypesHelper(CodeGen::CodeGenModule &cgm)
58355835
// struct _objc_protocol_extension *
58365836
ProtocolExtensionPtrTy = llvm::PointerType::getUnqual(ProtocolExtensionTy);
58375837

5838-
// Handle recursive construction of Protocol and ProtocolList types
5839-
5840-
ProtocolTy =
5841-
llvm::StructType::create(VMContext, "struct._objc_protocol");
5842-
5843-
ProtocolListTy =
5844-
llvm::StructType::create(VMContext, "struct._objc_protocol_list");
5845-
ProtocolListTy->setBody(llvm::PointerType::getUnqual(ProtocolListTy), LongTy,
5846-
llvm::ArrayType::get(ProtocolTy, 0));
5838+
// Handle construction of Protocol and ProtocolList types
58475839

58485840
// struct _objc_protocol {
58495841
// struct _objc_protocol_extension *isa;
@@ -5852,9 +5844,16 @@ ObjCTypesHelper::ObjCTypesHelper(CodeGen::CodeGenModule &cgm)
58525844
// struct _objc_method_description_list *instance_methods;
58535845
// struct _objc_method_description_list *class_methods;
58545846
// }
5855-
ProtocolTy->setBody(ProtocolExtensionPtrTy, Int8PtrTy,
5856-
llvm::PointerType::getUnqual(ProtocolListTy),
5857-
MethodDescriptionListPtrTy, MethodDescriptionListPtrTy);
5847+
ProtocolTy = llvm::StructType::create(
5848+
{ProtocolExtensionPtrTy, Int8PtrTy,
5849+
llvm::PointerType::getUnqual(VMContext), MethodDescriptionListPtrTy,
5850+
MethodDescriptionListPtrTy},
5851+
"struct._objc_protocol");
5852+
5853+
ProtocolListTy =
5854+
llvm::StructType::create({llvm::PointerType::getUnqual(VMContext), LongTy,
5855+
llvm::ArrayType::get(ProtocolTy, 0)},
5856+
"struct._objc_protocol_list");
58585857

58595858
// struct _objc_protocol_list *
58605859
ProtocolListPtrTy = llvm::PointerType::getUnqual(ProtocolListTy);
@@ -5886,8 +5885,6 @@ ObjCTypesHelper::ObjCTypesHelper(CodeGen::CodeGenModule &cgm)
58865885
"struct._objc_class_extension", IntTy, Int8PtrTy, PropertyListPtrTy);
58875886
ClassExtensionPtrTy = llvm::PointerType::getUnqual(ClassExtensionTy);
58885887

5889-
ClassTy = llvm::StructType::create(VMContext, "struct._objc_class");
5890-
58915888
// struct _objc_class {
58925889
// Class isa;
58935890
// Class super_class;
@@ -5902,10 +5899,12 @@ ObjCTypesHelper::ObjCTypesHelper(CodeGen::CodeGenModule &cgm)
59025899
// char *ivar_layout;
59035900
// struct _objc_class_ext *ext;
59045901
// };
5905-
ClassTy->setBody(llvm::PointerType::getUnqual(ClassTy),
5906-
llvm::PointerType::getUnqual(ClassTy), Int8PtrTy, LongTy,
5907-
LongTy, LongTy, IvarListPtrTy, MethodListPtrTy, CachePtrTy,
5908-
ProtocolListPtrTy, Int8PtrTy, ClassExtensionPtrTy);
5902+
ClassTy = llvm::StructType::create(
5903+
{llvm::PointerType::getUnqual(VMContext),
5904+
llvm::PointerType::getUnqual(VMContext), Int8PtrTy, LongTy, LongTy,
5905+
LongTy, IvarListPtrTy, MethodListPtrTy, CachePtrTy, ProtocolListPtrTy,
5906+
Int8PtrTy, ClassExtensionPtrTy},
5907+
"struct._objc_class");
59095908

59105909
ClassPtrTy = llvm::PointerType::getUnqual(ClassTy);
59115910

@@ -5988,13 +5987,9 @@ ObjCNonFragileABITypesHelper::ObjCNonFragileABITypesHelper(CodeGen::CodeGenModul
59885987
// const struct _prop_list_t * class_properties;
59895988
// }
59905989

5991-
// Holder for struct _protocol_list_t *
5992-
ProtocolListnfABITy =
5993-
llvm::StructType::create(VMContext, "struct._objc_protocol_list");
5994-
59955990
ProtocolnfABITy = llvm::StructType::create(
59965991
"struct._protocol_t", ObjectPtrTy, Int8PtrTy,
5997-
llvm::PointerType::getUnqual(ProtocolListnfABITy), MethodListnfABIPtrTy,
5992+
llvm::PointerType::getUnqual(VMContext), MethodListnfABIPtrTy,
59985993
MethodListnfABIPtrTy, MethodListnfABIPtrTy, MethodListnfABIPtrTy,
59995994
PropertyListPtrTy, IntTy, IntTy, Int8PtrPtrTy, Int8PtrTy,
60005995
PropertyListPtrTy);
@@ -6006,8 +6001,9 @@ ObjCNonFragileABITypesHelper::ObjCNonFragileABITypesHelper(CodeGen::CodeGenModul
60066001
// long protocol_count; // Note, this is 32/64 bit
60076002
// struct _protocol_t *[protocol_count];
60086003
// }
6009-
ProtocolListnfABITy->setBody(LongTy,
6010-
llvm::ArrayType::get(ProtocolnfABIPtrTy, 0));
6004+
ProtocolListnfABITy = llvm::StructType::create(
6005+
{LongTy, llvm::ArrayType::get(ProtocolnfABIPtrTy, 0)},
6006+
"struct._objc_protocol_list");
60116007

60126008
// struct _objc_protocol_list*
60136009
ProtocolListnfABIPtrTy = llvm::PointerType::getUnqual(ProtocolListnfABITy);
@@ -6067,11 +6063,12 @@ ObjCNonFragileABITypesHelper::ObjCNonFragileABITypesHelper(CodeGen::CodeGenModul
60676063
// struct class_ro_t *ro;
60686064
// }
60696065

6070-
ClassnfABITy = llvm::StructType::create(VMContext, "struct._class_t");
6071-
ClassnfABITy->setBody(llvm::PointerType::getUnqual(ClassnfABITy),
6072-
llvm::PointerType::getUnqual(ClassnfABITy), CachePtrTy,
6073-
llvm::PointerType::getUnqual(ImpnfABITy),
6074-
llvm::PointerType::getUnqual(ClassRonfABITy));
6066+
ClassnfABITy = llvm::StructType::create(
6067+
{llvm::PointerType::getUnqual(VMContext),
6068+
llvm::PointerType::getUnqual(VMContext), CachePtrTy,
6069+
llvm::PointerType::getUnqual(ImpnfABITy),
6070+
llvm::PointerType::getUnqual(ClassRonfABITy)},
6071+
"struct._class_t");
60756072

60766073
// LLVM for struct _class_t *
60776074
ClassnfABIPtrTy = llvm::PointerType::getUnqual(ClassnfABITy);

clang/lib/CodeGen/MicrosoftCXXABI.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -529,31 +529,29 @@ class MicrosoftCXXABI : public CGCXXABI {
529529
if (ClassHierarchyDescriptorType)
530530
return ClassHierarchyDescriptorType;
531531
// Forward-declare RTTIClassHierarchyDescriptor to break a cycle.
532-
ClassHierarchyDescriptorType = llvm::StructType::create(
533-
CGM.getLLVMContext(), "rtti.ClassHierarchyDescriptor");
534532
llvm::Type *FieldTypes[] = {CGM.IntTy, CGM.IntTy, CGM.IntTy,
535533
getImageRelativeType(CGM.UnqualPtrTy)};
536-
ClassHierarchyDescriptorType->setBody(FieldTypes);
534+
ClassHierarchyDescriptorType =
535+
llvm::StructType::create(FieldTypes, "rtti.ClassHierarchyDescriptor");
537536
return ClassHierarchyDescriptorType;
538537
}
539538

540539
llvm::StructType *getCompleteObjectLocatorType() {
541540
if (CompleteObjectLocatorType)
542541
return CompleteObjectLocatorType;
543-
CompleteObjectLocatorType = llvm::StructType::create(
544-
CGM.getLLVMContext(), "rtti.CompleteObjectLocator");
545542
llvm::Type *FieldTypes[] = {
546543
CGM.IntTy,
547544
CGM.IntTy,
548545
CGM.IntTy,
549546
getImageRelativeType(CGM.Int8PtrTy),
550547
getImageRelativeType(CGM.UnqualPtrTy),
551-
getImageRelativeType(CompleteObjectLocatorType),
548+
getImageRelativeType(CGM.VoidTy),
552549
};
553550
llvm::ArrayRef<llvm::Type *> FieldTypesRef(FieldTypes);
554551
if (!isImageRelative())
555552
FieldTypesRef = FieldTypesRef.drop_back();
556-
CompleteObjectLocatorType->setBody(FieldTypesRef);
553+
CompleteObjectLocatorType =
554+
llvm::StructType::create(FieldTypesRef, "rtti.CompleteObjectLocator");
557555
return CompleteObjectLocatorType;
558556
}
559557

0 commit comments

Comments
 (0)