Index: clang/include/clang/Basic/DiagnosticSemaKinds.td =================================================================== --- clang/include/clang/Basic/DiagnosticSemaKinds.td +++ clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -5174,6 +5174,8 @@ "%select{struct|interface|union|class|enum}1">; def err_flexible_array_has_nontrivial_dtor : Error< "flexible array member %0 of type %1 with non-trivial destruction">; +def err_flexible_array_in_objc_class : Error< + "%0 may not be used in interface due to flexible array member">; def ext_flexible_array_in_struct : Extension< "%0 may not be nested in a struct due to flexible array member">, InGroup; Index: clang/lib/Sema/SemaDecl.cpp =================================================================== --- clang/lib/Sema/SemaDecl.cpp +++ clang/lib/Sema/SemaDecl.cpp @@ -14989,6 +14989,12 @@ // Ivars can not have abstract class types FD->setInvalidDecl(); } + if (isa(EnclosingDecl) && FDTTy->getDecl()->hasFlexibleArrayMember()) { + Diag(FD->getLocation(), diag::err_flexible_array_in_objc_class) + << FD->getDeclName(); + FD->setInvalidDecl(); + EnclosingDecl->setInvalidDecl(); + } if (Record && FDTTy->getDecl()->hasObjectMember()) Record->setHasObjectMember(true); if (Record && FDTTy->getDecl()->hasVolatileMember()) Index: clang/test/SemaObjC/ivar-sem-check-3.m =================================================================== --- /dev/null +++ clang/test/SemaObjC/ivar-sem-check-3.m @@ -0,0 +1,19 @@ +// RUN: %clang_cc1 -emit-llvm-only -fobjc-arc -verify -Wno-objc-root-class %s + +// Test using structs with flexible array member as ivars. +struct Packet +{ + unsigned int size; + char data[]; +}; + +@interface INTF_FLEXIBLE_ARRAY_MEMBER +{ + // Pointer to a struct with flexible array member is acceptable. + struct Packet *packetPtr; + struct Packet packet; // expected-error {{'packet' may not be used in interface due to flexible array member}} +} +@end +// Implementation to trigger ivar layout. +@implementation INTF_FLEXIBLE_ARRAY_MEMBER +@end