Index: clang/lib/CodeGen/CodeGenFunction.cpp =================================================================== --- clang/lib/CodeGen/CodeGenFunction.cpp +++ clang/lib/CodeGen/CodeGenFunction.cpp @@ -2103,13 +2103,16 @@ arrayType = getContext().getAsArrayType(eltType); } - llvm::Type *baseType = ConvertType(eltType); + llvm::Type *baseType = ConvertTypeForMem(eltType); addr = Builder.CreateElementBitCast(addr, baseType, "array.begin"); } else { // Create the actual GEP. - addr = Address(Builder.CreateInBoundsGEP( - addr.getElementType(), addr.getPointer(), gepIndices, "array.begin"), - addr.getAlignment()); + llvm::Value *ptr = Builder.CreateInBoundsGEP( + addr.getElementType(), addr.getPointer(), gepIndices, "array.begin"); + llvm::Type *llvmEltType = ConvertTypeForMem(eltType); + ptr = Builder.CreateBitCast( + ptr, llvmEltType->getPointerTo(addr.getAddressSpace())); + addr = Address(ptr, llvmEltType, addr.getAlignment()); } baseType = eltType; Index: clang/test/CodeGenCXX/global-array-destruction.cpp =================================================================== --- clang/test/CodeGenCXX/global-array-destruction.cpp +++ clang/test/CodeGenCXX/global-array-destruction.cpp @@ -39,7 +39,7 @@ T t[2][3] = { 1.0, 2, 3.0, 4, 5.0, 6, 7.0, 8, 9.0, 10, 11.0, 12 }; // CHECK: call {{.*}} @__cxa_atexit -// CHECK: getelementptr inbounds ({{.*}} getelementptr inbounds ([2 x [3 x {{.*}}]], [2 x [3 x {{.*}}]]* @t, i32 0, i32 0, i32 0), i64 6) +// CHECK: getelementptr inbounds (%struct.T, %struct.T* bitcast ([2 x [3 x {{.*}}]]* @t to %struct.T*), i64 6) // CHECK: call void @_ZN1TD1Ev // CHECK: icmp eq {{.*}} @t // CHECK: br i1 {{.*}} @@ -47,7 +47,7 @@ static T t2[2][3] = { 1.0, 2, 3.0, 4, 5.0, 6, 7.0, 8, 9.0, 10, 11.0, 12 }; // CHECK: call {{.*}} @__cxa_atexit -// CHECK: getelementptr inbounds ({{.*}} getelementptr inbounds ([2 x [3 x {{.*}}]], [2 x [3 x {{.*}}]]* @_ZL2t2, i32 0, i32 0, i32 0), i64 6) +// CHECK: getelementptr inbounds (%struct.T, %struct.T* bitcast ([2 x [3 x {{.*}}]]* @_ZL2t2 to %struct.T*), i64 6) // CHECK: call void @_ZN1TD1Ev // CHECK: icmp eq {{.*}} @_ZL2t2 // CHECK: br i1 {{.*}} @@ -56,7 +56,7 @@ U &&u = U{ {{1.0, 2}, {3.0, 4}, {5.0, 6}}, {{7.0, 8}, {9.0, 10}, {11.0, 12}} }; // CHECK: call {{.*}} @__cxa_atexit -// CHECK: getelementptr inbounds ({{.*}}* getelementptr inbounds ([2 x [3 x {{.*}}]], [2 x [3 x {{.*}}]]* @_ZGR1u_, i32 0, i32 0, i32 0), i64 6) +// CHECK: getelementptr inbounds (%struct.T, %struct.T* getelementptr inbounds ([2 x [3 x {{.*}}]], [2 x [3 x {{.*}}]]* @_ZGR1u_, i32 0, i32 0, i32 0), i64 6) // CHECK: call void @_ZN1TD1Ev // CHECK: icmp eq {{.*}} @_ZGR1u_ // CHECK: br i1 {{.*}}