Skip to content

Commit ddd4403

Browse files
committed
Skip ivars that aren't available
This fixes a crash in CodeGen. rdar://137999979
1 parent a5a7ef3 commit ddd4403

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

clang/lib/CodeGen/CGObjCMac.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5308,6 +5308,9 @@ void IvarLayoutBuilder::visitAggregate(Iterator begin, Iterator end,
53085308
for (; begin != end; ++begin) {
53095309
auto field = *begin;
53105310

5311+
if (CGM.getContext().hasUnavailableFeature(field))
5312+
continue;
5313+
53115314
// Skip over bitfields.
53125315
if (field->isBitField()) {
53135316
continue;

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6759,9 +6759,12 @@ void CodeGenModule::EmitObjCPropertyImplementations(const
67596759
static bool needsDestructMethod(ObjCImplementationDecl *impl) {
67606760
const ObjCInterfaceDecl *iface = impl->getClassInterface();
67616761
for (const ObjCIvarDecl *ivar = iface->all_declared_ivar_begin();
6762-
ivar; ivar = ivar->getNextIvar())
6762+
ivar; ivar = ivar->getNextIvar()) {
6763+
if (impl->getASTContext().hasUnavailableFeature(ivar))
6764+
continue;
67636765
if (ivar->getType().isDestructedType())
67646766
return true;
6767+
}
67656768

67666769
return false;
67676770
}

clang/test/CodeGenObjC/feature-availability.m

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
// CHECK-NEXT: @"_OBJC_$_PROP_LIST_C2" = internal global { i32, i32, [3 x %struct._prop_t] } { i32 16, i32 3, [3 x %struct._prop_t] [%struct._prop_t { ptr @OBJC_PROP_NAME_ATTR_.24, ptr @OBJC_PROP_NAME_ATTR_.25 }, %struct._prop_t { ptr @OBJC_PROP_NAME_ATTR_.26, ptr @OBJC_PROP_NAME_ATTR_.27 }, %struct._prop_t { ptr @OBJC_PROP_NAME_ATTR_.28, ptr @OBJC_PROP_NAME_ATTR_.29 }] }, section "__DATA, __objc_const", align 8
7070
// CHECK-NEXT: @"_OBJC_CLASS_RO_$_C2" = internal global %struct._class_ro_t { i32 0, i32 8, i32 32, ptr null, ptr @OBJC_CLASS_NAME_.11, ptr @"_OBJC_$_INSTANCE_METHODS_C2", ptr null, ptr @"_OBJC_$_INSTANCE_VARIABLES_C2", ptr null, ptr @"_OBJC_$_PROP_LIST_C2" }, section "__DATA, __objc_const", align 8
7171
// CHECK-NEXT: @"OBJC_CLASS_$_C2" = global %struct._class_t { ptr @"OBJC_METACLASS_$_C2", ptr @"OBJC_CLASS_$_NSObject", ptr @_objc_empty_cache, ptr @_objc_empty_vtable, ptr @"_OBJC_CLASS_RO_$_C2" }, section "__DATA, __objc_data", align 8
72-
// CHECK-NEXT: @"OBJC_LABEL_CLASS_$" = private global [2 x ptr] [ptr @"OBJC_CLASS_$_C0", ptr @"OBJC_CLASS_$_C2"], section "__DATA,__objc_classlist,regular,no_dead_strip", align 8
72+
// CHECK: @"OBJC_LABEL_CLASS_$" = private global [3 x ptr] [ptr @"OBJC_CLASS_$_C0", ptr @"OBJC_CLASS_$_C2", ptr @"OBJC_CLASS_$_C3"], section "__DATA,__objc_classlist,regular,no_dead_strip", align 8
7373

7474
@interface NSObject {
7575
id a;
@@ -172,3 +172,10 @@ @interface C2 : NSObject
172172

173173
@implementation C2
174174
@end
175+
176+
@interface C3 : NSObject
177+
@property id prop0 __attribute__((availability(domain:feature2, AVAIL)));
178+
@end
179+
180+
@implementation C3
181+
@end

0 commit comments

Comments
 (0)