r343556 - [CodeGen] Before entering the loop that copies a non-trivial array field
Akira Hatanaka via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 1 18:00:45 PDT 2018
Author: ahatanak
Date: Mon Oct 1 18:00:44 2018
New Revision: 343556
URL: http://llvm.org/viewvc/llvm-project?rev=343556&view=rev
Log:
[CodeGen] Before entering the loop that copies a non-trivial array field
of a non-trivial C struct, copy the preceding trivial fields that
haven't been copied.
This commit fixes a bug where the instructions used to copy the
preceding trivial fields were emitted inside the loop body.
rdar://problem/44185064
Modified:
cfe/trunk/lib/CodeGen/CGNonTrivialStruct.cpp
cfe/trunk/test/CodeGenObjC/strong-in-c-struct.m
Modified: cfe/trunk/lib/CodeGen/CGNonTrivialStruct.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGNonTrivialStruct.cpp?rev=343556&r1=343555&r2=343556&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGNonTrivialStruct.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGNonTrivialStruct.cpp Mon Oct 1 18:00:44 2018
@@ -187,6 +187,7 @@ template <class Derived> struct GenFuncN
if (!FK)
return asDerived().visitTrivial(QualType(AT, 0), FD, CurStructOffset);
+ asDerived().flushTrivialFields();
CharUnits FieldOffset = CurStructOffset + asDerived().getFieldOffset(FD);
ASTContext &Ctx = asDerived().getContext();
const ConstantArrayType *CAT = cast<ConstantArrayType>(AT);
@@ -336,6 +337,7 @@ template <class Derived> struct GenFuncB
return asDerived().visitTrivial(QualType(AT, 0), FD, CurStackOffset,
Addrs);
+ asDerived().flushTrivialFields(Addrs);
CodeGenFunction &CGF = *this->CGF;
ASTContext &Ctx = CGF.getContext();
Modified: cfe/trunk/test/CodeGenObjC/strong-in-c-struct.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/strong-in-c-struct.m?rev=343556&r1=343555&r2=343556&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenObjC/strong-in-c-struct.m (original)
+++ cfe/trunk/test/CodeGenObjC/strong-in-c-struct.m Mon Oct 1 18:00:44 2018
@@ -485,8 +485,39 @@ void test_constructor_destructor_StructA
StructArray t;
}
+// Test that StructArray's field 'd' is copied before entering the loop.
+
+// CHECK: define linkonce_odr hidden void @__copy_constructor_8_8_t0w8_AB8s24n4_t8w16_s24_AE(i8** %[[DST:.*]], i8** %[[SRC:.*]])
+// CHECK: entry:
+// CHECK: %[[DST_ADDR:.*]] = alloca i8**, align 8
+// CHECK: %[[SRC_ADDR:.*]] = alloca i8**, align 8
+// CHECK: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8
+// CHECK: store i8** %[[SRC]], i8*** %[[SRC_ADDR]], align 8
+// CHECK: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8
+// CHECK: %[[V1:.*]] = load i8**, i8*** %[[SRC_ADDR]], align 8
+// CHECK: %[[V2:.*]] = bitcast i8** %[[V0]] to i64*
+// CHECK: %[[V3:.*]] = bitcast i8** %[[V1]] to i64*
+// CHECK: %[[V4:.*]] = load i64, i64* %[[V3]], align 8
+// CHECK: store i64 %[[V4]], i64* %[[V2]], align 8
+
+// CHECK: phi i8**
+// CHECK: phi i8**
+
+// CHECK: phi i8**
+// CHECK: phi i8**
+
+// CHECK-NOT: load i64, i64* %
+// CHECK-NOT: store i64 %
+// CHECK: call void @__copy_constructor_8_8_t0w16_s16(
+
+void test_copy_constructor_StructArray(StructArray a) {
+ StructArray t = a;
+}
+
// Check that IRGen copies the 9-bit bitfield emitting i16 load and store.
+// CHECK: define void @test_copy_constructor_Bitfield0(
+
// CHECK: define linkonce_odr hidden void @__copy_constructor_8_8_s0_t8w2(
// CHECK: %[[V4:.*]] = bitcast i8** %{{.*}} to i8*
// CHECK: %[[V5:.*]] = getelementptr inbounds i8, i8* %[[V4]], i64 8
More information about the cfe-commits
mailing list