summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/lib/CodeGen/CGExprAgg.cpp6
-rw-r--r--clang/test/CodeGen/PR2643-null-store-to-bitfield.c10
2 files changed, 12 insertions, 4 deletions
diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp
index df90ee09f5c..e51a852451e 100644
--- a/clang/lib/CodeGen/CGExprAgg.cpp
+++ b/clang/lib/CodeGen/CGExprAgg.cpp
@@ -340,10 +340,8 @@ void AggExprEmitter::EmitInitializationToLValue(Expr* E, LValue LV) {
void AggExprEmitter::EmitNullInitializationToLValue(LValue LV, QualType T) {
if (!CGF.hasAggregateLLVMType(T)) {
// For non-aggregates, we can store zero
- const llvm::Type *T =
- cast<llvm::PointerType>(LV.getAddress()->getType())->getElementType();
- // FIXME: volatility
- Builder.CreateStore(llvm::Constant::getNullValue(T), LV.getAddress());
+ llvm::Value *Null = llvm::Constant::getNullValue(CGF.ConvertType(T));
+ CGF.EmitStoreThroughLValue(RValue::get(Null), LV, T);
} else {
// Otherwise, just memset the whole thing to zero. This is legal
// because in LLVM, all default initializers are guaranteed to have a
diff --git a/clang/test/CodeGen/PR2643-null-store-to-bitfield.c b/clang/test/CodeGen/PR2643-null-store-to-bitfield.c
new file mode 100644
index 00000000000..4fef84255a5
--- /dev/null
+++ b/clang/test/CodeGen/PR2643-null-store-to-bitfield.c
@@ -0,0 +1,10 @@
+// RUN: clang -emit-llvm -o - %s
+// PR2643
+
+void foo() {
+ struct {
+ int a : 1;
+ int b : 1;
+ } entry = {0};
+}
+
OpenPOWER on IntegriCloud