@@ -424,32 +424,17 @@ if (ExpectedSizeInBytes == Size) {
424424 // store only the first ExpectedSizeInBytes bytes of Old
425425 llvm::Type *OldType = Old->getType ();
426426
427- llvm::Align SrcAlignLLVM = DL.getABITypeAlign (OldType);
428- llvm::Align DstAlignLLVM = DL.getABITypeAlign (ExpectedType);
429-
430- clang::CharUnits SrcAlign = clang::CharUnits::fromQuantity (SrcAlignLLVM.value ());
431- clang::CharUnits DstAlign = clang::CharUnits::fromQuantity (DstAlignLLVM.value ());
432-
433427 // Allocate temporary storage for Old value
434- llvm::AllocaInst *Alloca = CGF.CreateTempAlloca (OldType, " old.tmp" );
435-
436- // Wrap into clang::CodeGen::Address with proper type and alignment
437- Address OldStorage (Alloca, OldType, SrcAlign);
428+ Address OldTmp = CGF.CreateTempAlloca (OldType, Ptr.getAlignment (), " old.tmp" );
438429
439430 // Store Old into this temporary
440- CGF.Builder .CreateStore (Old, OldStorage);
441-
442- // Bitcast pointers to i8*
443- llvm::Type *I8PtrTy = llvm::PointerType::getUnqual (CGF.getLLVMContext ());
444-
445- llvm::Value *SrcPtr = CGF.Builder .CreateBitCast (OldStorage.getBasePointer (), I8PtrTy);
446- llvm::Value *DstPtr = CGF.Builder .CreateBitCast (ExpectedResult.getBasePointer (), I8PtrTy);
431+ CGF.Builder .CreateStore (Old, OldTmp);
447432
448433 // Perform memcpy for first ExpectedSizeInBytes bytes
449434 CGF.Builder .CreateMemCpy (
450- DstPtr, DstAlignLLVM ,
451- SrcPtr, SrcAlignLLVM ,
452- llvm::ConstantInt::get (CGF. IntPtrTy , ExpectedSizeInBytes) ,
435+ ExpectedResult ,
436+ OldTmp ,
437+ ExpectedSizeInBytes,
453438 /* isVolatile=*/ false );
454439}
455440
0 commit comments