diff --git a/clang/lib/CodeGen/CGExprConstant.cpp b/clang/lib/CodeGen/CGExprConstant.cpp --- a/clang/lib/CodeGen/CGExprConstant.cpp +++ b/clang/lib/CodeGen/CGExprConstant.cpp @@ -58,14 +58,15 @@ } llvm::Constant *getPadding(CharUnits PadSize) const { - llvm::Type *Ty = CGM.Int8Ty; + llvm::Type *Ty = CGM.getCharSizedType(); if (PadSize > CharUnits::One()) Ty = llvm::ArrayType::get(Ty, PadSize.getQuantity()); return llvm::UndefValue::get(Ty); } llvm::Constant *getZeroes(CharUnits ZeroSize) const { - llvm::Type *Ty = llvm::ArrayType::get(CGM.Int8Ty, ZeroSize.getQuantity()); + llvm::Type *Ty = llvm::ArrayType::get(CGM.getCharSizedType(), + ZeroSize.getQuantity()); return llvm::ConstantAggregateZero::get(Ty); } }; @@ -1069,7 +1070,7 @@ assert(CurSize <= TotalSize && "Union size mismatch!"); if (unsigned NumPadBytes = TotalSize - CurSize) { - llvm::Type *Ty = CGM.Int8Ty; + llvm::Type *Ty = CGM.getCharSizedType(); if (NumPadBytes > 1) Ty = llvm::ArrayType::get(Ty, NumPadBytes); diff --git a/clang/lib/CodeGen/CodeGenModule.h b/clang/lib/CodeGen/CodeGenModule.h --- a/clang/lib/CodeGen/CodeGenModule.h +++ b/clang/lib/CodeGen/CodeGenModule.h @@ -1225,6 +1225,9 @@ /// Return the store size, in character units, of the given LLVM type. CharUnits GetTargetTypeStoreSize(llvm::Type *Ty) const; + // Return the LLVM type sized as one character unit. + llvm::Type *getCharSizedType(); + /// Returns LLVM linkage for a declarator. llvm::GlobalValue::LinkageTypes getLLVMLinkageForDeclarator(const DeclaratorDecl *D, GVALinkage Linkage, diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -3982,6 +3982,11 @@ getDataLayout().getTypeStoreSizeInBits(Ty)); } +llvm::Type *CodeGenModule::getCharSizedType() { + return llvm::Type::getIntNTy(getLLVMContext(), + getContext().getCharWidth()); +} + LangAS CodeGenModule::GetGlobalVarAddressSpace(const VarDecl *D) { LangAS AddrSpace = LangAS::Default; if (LangOpts.OpenCL) {