Author: arphaman Date: Thu Oct 6 04:47:29 2016 New Revision: 283432 URL: http://llvm.org/viewvc/llvm-project?rev=283432&view=rev Log: [Sema] Fix PR30520: Handle incomplete field types in transparent_union unions
This commit fixes a crash that happens when clang is analyzing a transparent_union attribute on a union which has a field with incomplete type. rdar://28630028 Differential Revision: https://reviews.llvm.org/D25273 Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp cfe/trunk/test/Sema/transparent-union.c Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=283432&r1=283431&r2=283432&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original) +++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Thu Oct 6 04:47:29 2016 @@ -3044,10 +3044,14 @@ static void handleTransparentUnionAttr(S return; } + if (FirstType->isIncompleteType()) + return; uint64_t FirstSize = S.Context.getTypeSize(FirstType); uint64_t FirstAlign = S.Context.getTypeAlign(FirstType); for (; Field != FieldEnd; ++Field) { QualType FieldType = Field->getType(); + if (FieldType->isIncompleteType()) + return; // FIXME: this isn't fully correct; we also need to test whether the // members of the union would all have the same calling convention as the // first member of the union. Checking just the size and alignment isn't Modified: cfe/trunk/test/Sema/transparent-union.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/transparent-union.c?rev=283432&r1=283431&r2=283432&view=diff ============================================================================== --- cfe/trunk/test/Sema/transparent-union.c (original) +++ cfe/trunk/test/Sema/transparent-union.c Thu Oct 6 04:47:29 2016 @@ -89,3 +89,12 @@ union pr15134v2 { unsigned int u3; } __attribute__((aligned(8))); } __attribute__((transparent_union)); + +union pr30520v { void b; } __attribute__((transparent_union)); // expected-error {{field has incomplete type 'void'}} + +union pr30520a { int b[]; } __attribute__((transparent_union)); // expected-error {{field has incomplete type 'int []'}} + +// expected-note@+1 2 {{forward declaration of 'struct stb'}} +union pr30520s { struct stb b; } __attribute__((transparent_union)); // expected-error {{field has incomplete type 'struct stb'}} + +union pr30520s2 { int *v; struct stb b; } __attribute__((transparent_union)); // expected-error {{field has incomplete type 'struct stb'}} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits