]> granicus.if.org Git - clang/commitdiff
[Sema] Fix PR30520: Handle incomplete field types in transparent_union unions
authorAlex Lorenz <arphaman@gmail.com>
Thu, 6 Oct 2016 09:47:29 +0000 (09:47 +0000)
committerAlex Lorenz <arphaman@gmail.com>
Thu, 6 Oct 2016 09:47:29 +0000 (09:47 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@283432 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDeclAttr.cpp
test/Sema/transparent-union.c

index e06f110f0e4917ae5f39d8b0a3c8dc8c9a071c7d..3e8a39a57860f32f581b3002860f14abea372dad 100644 (file)
@@ -3044,10 +3044,14 @@ static void handleTransparentUnionAttr(Sema &S, Decl *D,
     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
index 8ef70bb1c7e32deb85e7c037ee1a3a7b90434940..a1a67dfd26fc94261538f2a4af2f1603579dda31 100644 (file)
@@ -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'}}