]> granicus.if.org Git - clang/commitdiff
Fix EmitNullInitializationToLValue for bitfield lvalues.
authorDaniel Dunbar <daniel@zuster.org>
Wed, 6 Aug 2008 05:32:55 +0000 (05:32 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Wed, 6 Aug 2008 05:32:55 +0000 (05:32 +0000)
 - PR2643

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

lib/CodeGen/CGExprAgg.cpp
test/CodeGen/PR2643-null-store-to-bitfield.c [new file with mode: 0644]

index df90ee09f5c6bfb390f3dda8cb175c6aa7bb86d9..e51a852451e96ae23ee7e9baf0e91dd5d6068fb1 100644 (file)
@@ -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/test/CodeGen/PR2643-null-store-to-bitfield.c b/test/CodeGen/PR2643-null-store-to-bitfield.c
new file mode 100644 (file)
index 0000000..4fef842
--- /dev/null
@@ -0,0 +1,10 @@
+// RUN: clang -emit-llvm -o - %s
+// PR2643
+
+void foo() {
+  struct {
+    int a : 1;
+    int b : 1;
+  } entry = {0};
+}
+