Skip to content

Commit ea2cfda

Browse files
committed
[CGExpr] Use getCharWidth() more consistently in CCGExprConstant. NFC
Most of CGExprConstant.cpp is using the CharUnits abstraction and is using getCharWidth() (directly of indirectly) when converting between size of a char and size in bits. This patch is making that abstraction more consistent by adding CharTy to the CodeGenTypeCache (honoring getCharWidth() when mapping from char to LLVM IR types, instead of using Int8Ty directly). Reviewed By: rjmccall Differential Revision: https://reviews.llvm.org/D94979
1 parent 72f863f commit ea2cfda

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

clang/lib/CodeGen/CGExprConstant.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ struct ConstantAggregateBuilderUtils {
5858
}
5959

6060
llvm::Constant *getPadding(CharUnits PadSize) const {
61-
llvm::Type *Ty = CGM.Int8Ty;
61+
llvm::Type *Ty = CGM.CharTy;
6262
if (PadSize > CharUnits::One())
6363
Ty = llvm::ArrayType::get(Ty, PadSize.getQuantity());
6464
return llvm::UndefValue::get(Ty);
6565
}
6666

6767
llvm::Constant *getZeroes(CharUnits ZeroSize) const {
68-
llvm::Type *Ty = llvm::ArrayType::get(CGM.Int8Ty, ZeroSize.getQuantity());
68+
llvm::Type *Ty = llvm::ArrayType::get(CGM.CharTy, ZeroSize.getQuantity());
6969
return llvm::ConstantAggregateZero::get(Ty);
7070
}
7171
};
@@ -1069,7 +1069,7 @@ class ConstExprEmitter :
10691069

10701070
assert(CurSize <= TotalSize && "Union size mismatch!");
10711071
if (unsigned NumPadBytes = TotalSize - CurSize) {
1072-
llvm::Type *Ty = CGM.Int8Ty;
1072+
llvm::Type *Ty = CGM.CharTy;
10731073
if (NumPadBytes > 1)
10741074
Ty = llvm::ArrayType::get(Ty, NumPadBytes);
10751075

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ CodeGenModule::CodeGenModule(ASTContext &C, const HeaderSearchOptions &HSO,
123123
C.toCharUnitsFromBits(C.getTargetInfo().getMaxPointerWidth()).getQuantity();
124124
IntAlignInBytes =
125125
C.toCharUnitsFromBits(C.getTargetInfo().getIntAlign()).getQuantity();
126+
CharTy =
127+
llvm::IntegerType::get(LLVMContext, C.getTargetInfo().getCharWidth());
126128
IntTy = llvm::IntegerType::get(LLVMContext, C.getTargetInfo().getIntWidth());
127129
IntPtrTy = llvm::IntegerType::get(LLVMContext,
128130
C.getTargetInfo().getMaxPointerWidth());

clang/lib/CodeGen/CodeGenTypeCache.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ struct CodeGenTypeCache {
4141
/// int
4242
llvm::IntegerType *IntTy;
4343

44+
/// char
45+
llvm::IntegerType *CharTy;
46+
4447
/// intptr_t, size_t, and ptrdiff_t, which we assume are the same size.
4548
union {
4649
llvm::IntegerType *IntPtrTy;

0 commit comments

Comments
 (0)