diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp --- a/clang/lib/CodeGen/CGCall.cpp +++ b/clang/lib/CodeGen/CGCall.cpp @@ -2848,12 +2848,13 @@ llvm::StructType *STy = dyn_cast(ArgI.getCoerceToType()); if (ArgI.isDirect() && ArgI.getCanBeFlattened() && STy && STy->getNumElements() > 1) { - uint64_t SrcSize = CGM.getDataLayout().getTypeAllocSize(STy); + llvm::TypeSize SrcSize = CGM.getDataLayout().getTypeAllocSize(STy); llvm::Type *DstTy = Ptr.getElementType(); - uint64_t DstSize = CGM.getDataLayout().getTypeAllocSize(DstTy); + llvm::TypeSize DstSize = CGM.getDataLayout().getTypeAllocSize(DstTy); Address AddrToStoreInto = Address::invalid(); - if (SrcSize <= DstSize) { + assert(SrcSize.isScalable() == DstSize.isScalable()); + if (llvm::TypeSize::isKnownLE(SrcSize, DstSize)) { AddrToStoreInto = Builder.CreateElementBitCast(Ptr, STy); } else { AddrToStoreInto = @@ -2878,7 +2879,7 @@ } } - if (SrcSize > DstSize) { + if (llvm::TypeSize::isKnownGT(SrcSize, DstSize)) { Builder.CreateMemCpy(Ptr, AddrToStoreInto, DstSize); } @@ -4915,18 +4916,18 @@ dyn_cast(ArgInfo.getCoerceToType()); if (STy && ArgInfo.isDirect() && ArgInfo.getCanBeFlattened()) { llvm::Type *SrcTy = Src.getElementType(); - uint64_t SrcSize = CGM.getDataLayout().getTypeAllocSize(SrcTy); - uint64_t DstSize = CGM.getDataLayout().getTypeAllocSize(STy); + llvm::TypeSize SrcSize = CGM.getDataLayout().getTypeAllocSize(SrcTy); + llvm::TypeSize DstSize = CGM.getDataLayout().getTypeAllocSize(STy); // If the source type is smaller than the destination type of the // coerce-to logic, copy the source value into a temp alloca the size // of the destination type to allow loading all of it. The bits past // the source value are left undef. - if (SrcSize < DstSize) { + if (llvm::TypeSize::isKnownLT(SrcSize, DstSize)) { Address TempAlloca = CreateTempAlloca(STy, Src.getAlignment(), Src.getName() + ".coerce"); - Builder.CreateMemCpy(TempAlloca, Src, SrcSize); + Builder.CreateMemCpy(TempAlloca, Src, SrcSize.getFixedSize()); Src = TempAlloca; } else { Src = Builder.CreateBitCast(Src, diff --git a/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp b/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp --- a/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp +++ b/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp @@ -159,7 +159,8 @@ return Context.toCharUnitsFromBits(BitOffset); } CharUnits getSize(llvm::Type *Type) { - return CharUnits::fromQuantity(DataLayout.getTypeAllocSize(Type)); + return CharUnits::fromQuantity( + DataLayout.getTypeAllocSize(Type).getKnownMinValue()); } CharUnits getAlignment(llvm::Type *Type) { return CharUnits::fromQuantity(DataLayout.getABITypeAlignment(Type)); @@ -929,7 +930,8 @@ const ASTRecordLayout &Layout = getContext().getASTRecordLayout(D); uint64_t TypeSizeInBits = getContext().toBits(Layout.getSize()); - assert(TypeSizeInBits == getDataLayout().getTypeAllocSizeInBits(Ty) && + assert(TypeSizeInBits == + getDataLayout().getTypeAllocSizeInBits(Ty).getKnownMinValue() && "Type size mismatch!"); if (BaseTy) { @@ -938,9 +940,10 @@ uint64_t AlignedNonVirtualTypeSizeInBits = getContext().toBits(NonVirtualSize); - assert(AlignedNonVirtualTypeSizeInBits == - getDataLayout().getTypeAllocSizeInBits(BaseTy) && - "Type size mismatch!"); + assert( + AlignedNonVirtualTypeSizeInBits == + getDataLayout().getTypeAllocSizeInBits(BaseTy).getKnownMinValue() && + "Type size mismatch!"); } // Verify that the LLVM and AST field offsets agree. @@ -960,7 +963,8 @@ // AST offset. if (!FD->isBitField()) { unsigned FieldNo = RL->getLLVMFieldNo(FD); - assert(AST_RL.getFieldOffset(i) == SL->getElementOffsetInBits(FieldNo) && + assert(AST_RL.getFieldOffset(i) == + SL->getElementOffsetInBits(FieldNo).getKnownMinSize() && "Invalid field offset!"); continue; }