diff --git a/clang/lib/CodeGen/CGExprConstant.cpp b/clang/lib/CodeGen/CGExprConstant.cpp index f22321f0e738a1..dd65080a840446 100644 --- a/clang/lib/CodeGen/CGExprConstant.cpp +++ b/clang/lib/CodeGen/CGExprConstant.cpp @@ -738,7 +738,7 @@ bool ConstStructBuilder::Build(const InitListExpr *ILE, bool AllowOverwrite) { // Zero-sized fields are not emitted, but their initializers may still // prevent emission of this struct as a constant. if (isEmptyFieldForLayout(CGM.getContext(), Field)) { - if (Init->HasSideEffects(CGM.getContext())) + if (Init && Init->HasSideEffects(CGM.getContext())) return false; continue; } diff --git a/clang/test/CodeGen/union-init2.c b/clang/test/CodeGen/union-init2.c index 2c167683c4e55d..048ff00517b4e8 100644 --- a/clang/test/CodeGen/union-init2.c +++ b/clang/test/CodeGen/union-init2.c @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -emit-llvm %s -o - -triple i686-pc-linux-gnu | FileCheck %s +// RUN: %clang_cc1 -x c++ %s -emit-llvm -triple x86_64-linux-gnu -o - | FileCheck %s --check-prefixes=CHECK-CXX // Make sure we generate something sane instead of a ptrtoint // CHECK: @r, [4 x i8] undef @@ -11,3 +12,10 @@ union z { long long b; }; union z y = {}; + +// CHECK: @foo = {{.*}}global %union.Foo undef, align 1 +// CHECK-CXX: @foo = {{.*}}global %union.Foo undef, align 1 +union Foo { + struct Empty {} val; +}; +union Foo foo = {};