@@ -3936,7 +3936,9 @@ static void emitWritebackArg(CodeGenFunction &CGF, CallArgList &args,
3936
3936
// because of the crazy ObjC compatibility rules.
3937
3937
3938
3938
llvm::PointerType *destType =
3939
- cast<llvm::PointerType>(CGF.ConvertType (CRE->getType ()));
3939
+ cast<llvm::PointerType>(CGF.ConvertType (CRE->getType ()));
3940
+ llvm::Type *destElemType =
3941
+ CGF.ConvertTypeForMem (CRE->getType ()->getPointeeType ());
3940
3942
3941
3943
// If the address is a constant null, just pass the appropriate null.
3942
3944
if (isProvablyNull (srcAddr.getPointer ())) {
@@ -3946,8 +3948,8 @@ static void emitWritebackArg(CodeGenFunction &CGF, CallArgList &args,
3946
3948
}
3947
3949
3948
3950
// Create the temporary.
3949
- Address temp = CGF. CreateTempAlloca (destType-> getPointerElementType (),
3950
- CGF.getPointerAlign (), " icr.temp" );
3951
+ Address temp =
3952
+ CGF. CreateTempAlloca (destElemType, CGF.getPointerAlign (), " icr.temp" );
3951
3953
// Loading an l-value can introduce a cleanup if the l-value is __weak,
3952
3954
// and that cleanup will be conditional if we can't prove that the l-value
3953
3955
// isn't null, so we need to register a dominating point so that the cleanups
@@ -3957,8 +3959,8 @@ static void emitWritebackArg(CodeGenFunction &CGF, CallArgList &args,
3957
3959
// Zero-initialize it if we're not doing a copy-initialization.
3958
3960
bool shouldCopy = CRE->shouldCopy ();
3959
3961
if (!shouldCopy) {
3960
- llvm::Value *null = llvm::ConstantPointerNull::get (
3961
- cast<llvm::PointerType>(destType-> getPointerElementType () ));
3962
+ llvm::Value *null =
3963
+ llvm::ConstantPointerNull::get ( cast<llvm::PointerType>(destElemType ));
3962
3964
CGF.Builder .CreateStore (null, temp);
3963
3965
}
3964
3966
@@ -4000,8 +4002,7 @@ static void emitWritebackArg(CodeGenFunction &CGF, CallArgList &args,
4000
4002
assert (srcRV.isScalar ());
4001
4003
4002
4004
llvm::Value *src = srcRV.getScalarVal ();
4003
- src = CGF.Builder .CreateBitCast (src, destType->getPointerElementType (),
4004
- " icr.cast" );
4005
+ src = CGF.Builder .CreateBitCast (src, destElemType, " icr.cast" );
4005
4006
4006
4007
// Use an ordinary store, not a store-to-lvalue.
4007
4008
CGF.Builder .CreateStore (src, temp);
@@ -5136,14 +5137,16 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
5136
5137
#ifndef NDEBUG
5137
5138
// Assert that these structs have equivalent element types.
5138
5139
llvm::StructType *FullTy = CallInfo.getArgStruct ();
5139
- llvm::StructType *DeclaredTy =
5140
- cast<llvm::StructType>(LastParamTy->getPointerElementType ());
5141
- assert (DeclaredTy->getNumElements () == FullTy->getNumElements ());
5142
- for (llvm::StructType::element_iterator DI = DeclaredTy->element_begin (),
5143
- DE = DeclaredTy->element_end (),
5144
- FI = FullTy->element_begin ();
5145
- DI != DE; ++DI, ++FI)
5146
- assert (*DI == *FI);
5140
+ if (!LastParamTy->isOpaquePointerTy ()) {
5141
+ llvm::StructType *DeclaredTy = cast<llvm::StructType>(
5142
+ LastParamTy->getNonOpaquePointerElementType ());
5143
+ assert (DeclaredTy->getNumElements () == FullTy->getNumElements ());
5144
+ for (auto DI = DeclaredTy->element_begin (),
5145
+ DE = DeclaredTy->element_end (),
5146
+ FI = FullTy->element_begin ();
5147
+ DI != DE; ++DI, ++FI)
5148
+ assert (*DI == *FI);
5149
+ }
5147
5150
#endif
5148
5151
Arg = Builder.CreateBitCast (Arg, LastParamTy);
5149
5152
}
0 commit comments