]> granicus.if.org Git - clang/commitdiff
Prevent a code gen. crash on empty unions - pr5408.
authorFariborz Jahanian <fjahanian@apple.com>
Fri, 6 Nov 2009 20:47:40 +0000 (20:47 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Fri, 6 Nov 2009 20:47:40 +0000 (20:47 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86287 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGRecordLayoutBuilder.cpp
test/CodeGenCXX/empty-union.cpp [new file with mode: 0644]

index 7baf69d87689f1b368d5dff00880f9f78373f201..8e0864b8dd83d44172fd2eb2b7fdd09ee6865a88 100644 (file)
@@ -208,7 +208,11 @@ void CGRecordLayoutBuilder::LayoutUnion(const RecordDecl *D) {
       Align = 1;
     }
   }
-
+  if (!Align) {
+    assert((D->field_begin() == D->field_end()) && "LayoutUnion - Align 0");
+    Align = 1;
+  }
+  
   // Append tail padding.
   if (Layout.getSize() / 8 > Size)
     AppendPadding(Layout.getSize() / 8, Align);
diff --git a/test/CodeGenCXX/empty-union.cpp b/test/CodeGenCXX/empty-union.cpp
new file mode 100644 (file)
index 0000000..fdd9741
--- /dev/null
@@ -0,0 +1,10 @@
+// RUN: clang-cc -emit-llvm -o - %s
+
+union sigval { };
+
+union sigval sigev_value;
+
+int main()
+{
+  return sizeof(sigev_value);
+}