Skip to content

Commit 72f863f

Browse files
committed
[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
1 parent 29d420e commit 72f863f

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

clang/lib/CodeGen/CGRecordLayoutBuilder.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,20 @@ struct CGRecordLowering {
127127

128128
/// Wraps llvm::Type::getIntNTy with some implicit arguments.
129129
llvm::Type *getIntNType(uint64_t NumBits) {
130+
unsigned AlignedBits = llvm::alignTo(NumBits, Context.getCharWidth());
131+
return llvm::Type::getIntNTy(Types.getLLVMContext(), AlignedBits);
132+
}
133+
/// Get the LLVM type sized as one character unit.
134+
llvm::Type *getCharType() {
130135
return llvm::Type::getIntNTy(Types.getLLVMContext(),
131-
(unsigned)llvm::alignTo(NumBits, 8));
136+
Context.getCharWidth());
132137
}
133-
/// Gets an llvm type of size NumBytes and alignment 1.
134-
llvm::Type *getByteArrayType(CharUnits NumBytes) {
135-
assert(!NumBytes.isZero() && "Empty byte arrays aren't allowed.");
136-
llvm::Type *Type = llvm::Type::getInt8Ty(Types.getLLVMContext());
137-
return NumBytes == CharUnits::One() ? Type :
138-
(llvm::Type *)llvm::ArrayType::get(Type, NumBytes.getQuantity());
138+
/// Gets an llvm type of size NumChars and alignment 1.
139+
llvm::Type *getByteArrayType(CharUnits NumChars) {
140+
assert(!NumChars.isZero() && "Empty byte arrays aren't allowed.");
141+
llvm::Type *Type = getCharType();
142+
return NumChars == CharUnits::One() ? Type :
143+
(llvm::Type *)llvm::ArrayType::get(Type, NumChars.getQuantity());
139144
}
140145
/// Gets the storage type for a field decl and handles storage
141146
/// for itanium bitfields that are smaller than their declared type.

0 commit comments

Comments
 (0)