Author: Bjorn Pettersson Date: 2021-01-22T21:12:17+01:00 New Revision: 72f863fd37c3471e7e1b152ac613da00ab6faaba
URL: https://github.com/llvm/llvm-project/commit/72f863fd37c3471e7e1b152ac613da00ab6faaba DIFF: https://github.com/llvm/llvm-project/commit/72f863fd37c3471e7e1b152ac613da00ab6faaba.diff LOG: [CodeGen] Use getCharWidth() more consistently in CGRecordLowering. NFC When using getByteArrayType the requested size is calculated in char units, but the type used for the array was hardcoded to the Int8Ty. This patch is using getCharWIdth a bit more consistently by using getIntNTy in combination with getCharWidth, instead of explictly using getInt8Ty. Reviewed By: rjmccall Differential Revision: https://reviews.llvm.org/D94977 Added: Modified: clang/lib/CodeGen/CGRecordLayoutBuilder.cpp Removed: ################################################################################ diff --git a/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp b/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp index 880342dfed1f..cf8313f92587 100644 --- a/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp +++ b/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp @@ -127,15 +127,20 @@ struct CGRecordLowering { /// Wraps llvm::Type::getIntNTy with some implicit arguments. llvm::Type *getIntNType(uint64_t NumBits) { + unsigned AlignedBits = llvm::alignTo(NumBits, Context.getCharWidth()); + return llvm::Type::getIntNTy(Types.getLLVMContext(), AlignedBits); + } + /// Get the LLVM type sized as one character unit. + llvm::Type *getCharType() { return llvm::Type::getIntNTy(Types.getLLVMContext(), - (unsigned)llvm::alignTo(NumBits, 8)); + Context.getCharWidth()); } - /// Gets an llvm type of size NumBytes and alignment 1. - llvm::Type *getByteArrayType(CharUnits NumBytes) { - assert(!NumBytes.isZero() && "Empty byte arrays aren't allowed."); - llvm::Type *Type = llvm::Type::getInt8Ty(Types.getLLVMContext()); - return NumBytes == CharUnits::One() ? Type : - (llvm::Type *)llvm::ArrayType::get(Type, NumBytes.getQuantity()); + /// Gets an llvm type of size NumChars and alignment 1. + llvm::Type *getByteArrayType(CharUnits NumChars) { + assert(!NumChars.isZero() && "Empty byte arrays aren't allowed."); + llvm::Type *Type = getCharType(); + return NumChars == CharUnits::One() ? Type : + (llvm::Type *)llvm::ArrayType::get(Type, NumChars.getQuantity()); } /// Gets the storage type for a field decl and handles storage /// for itanium bitfields that are smaller than their declared type. _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits