]> granicus.if.org Git - clang/commitdiff
Make sure null initialization in arrays works correctly with ARC types. <rdar:/...
authorEli Friedman <eli.friedman@gmail.com>
Wed, 22 Feb 2012 05:38:59 +0000 (05:38 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Wed, 22 Feb 2012 05:38:59 +0000 (05:38 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@151133 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGExprAgg.cpp
test/CodeGenObjC/arc.m

index 5fb334bd8e86a1534e01efddb86ee98c3ebe8783..80d754a98a4c443abaea48ebcccd01df6aab54df 100644 (file)
@@ -853,9 +853,14 @@ void AggExprEmitter::EmitNullInitializationToLValue(LValue lv) {
     return;
   
   if (!CGF.hasAggregateLLVMType(type)) {
-    // For non-aggregates, we can store zero
+    // For non-aggregates, we can store zero.
     llvm::Value *null = llvm::Constant::getNullValue(CGF.ConvertType(type));
-    CGF.EmitStoreThroughLValue(RValue::get(null), lv);
+    // Note that the following is not equivalent to
+    // EmitStoreThroughBitfieldLValue for ARC types.
+    if (lv.isBitField())
+      CGF.EmitStoreThroughBitfieldLValue(RValue::get(null), lv);
+    assert(lv.isSimple());
+    CGF.EmitStoreOfScalar(null, lv, /* isInitialization */ true);
   } else {
     // There's a potential optimization opportunity in combining
     // memsets; that would be easy for arrays, but relatively
index 97abb472437d064fc84b84cf0e6416af714b3976..1db00affe8246beedf993864da23c51f2ae9990a 100644 (file)
@@ -1533,3 +1533,15 @@ void test68(void) {
 // CHECK:      [[T0:%.*]] = load [[TEST69]]** [[SELF]], align 8
 // CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST69]]* [[T0]] to i8*
 // CHECK-NEXT: ret i8* [[T1]]
+
+// rdar://problem/10907547
+void test70(id i) {
+  // CHECK: define void @test70
+  // CHECK: store i8* null, i8**
+  // CHECK: store i8* null, i8**
+  // CHECK: [[ID:%.*]] = call i8* @objc_retain(i8*
+  // CHECK: store i8* [[ID]], i8**
+  id x[3] = {
+    [2] = i
+  };
+}