From: David Majnemer Date: Mon, 31 Oct 2016 16:48:30 +0000 (+0000) Subject: Use toCharUnitsFromBits instead of TargetInfo::getCharWidth X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f021623fdd2a24fcb37e225a71000d3ad4692874;p=clang Use toCharUnitsFromBits instead of TargetInfo::getCharWidth git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@285595 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGBuiltin.cpp b/lib/CodeGen/CGBuiltin.cpp index 54566aa7e5..4728aadf73 100644 --- a/lib/CodeGen/CGBuiltin.cpp +++ b/lib/CodeGen/CGBuiltin.cpp @@ -1142,7 +1142,9 @@ RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD, const TargetInfo &TI = getContext().getTargetInfo(); // The alignment of the alloca should correspond to __BIGGEST_ALIGNMENT__. unsigned SuitableAlignmentInBytes = - TI.getSuitableAlign() / TI.getCharWidth(); + CGM.getContext() + .toCharUnitsFromBits(TI.getSuitableAlign()) + .getQuantity(); AllocaInst *AI = Builder.CreateAlloca(Builder.getInt8Ty(), Size); AI->setAlignment(SuitableAlignmentInBytes); return RValue::get(AI); @@ -1150,11 +1152,11 @@ RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD, case Builtin::BI__builtin_alloca_with_align: { Value *Size = EmitScalarExpr(E->getArg(0)); - Value *AlignmentValue = EmitScalarExpr(E->getArg(1)); - auto *AlignmentCI = cast(AlignmentValue); - unsigned Alignment = AlignmentCI->getZExtValue(); - const TargetInfo &TI = getContext().getTargetInfo(); - unsigned AlignmentInBytes = Alignment / TI.getCharWidth(); + Value *AlignmentInBitsValue = EmitScalarExpr(E->getArg(1)); + auto *AlignmentInBitsCI = cast(AlignmentInBitsValue); + unsigned AlignmentInBits = AlignmentInBitsCI->getZExtValue(); + unsigned AlignmentInBytes = + CGM.getContext().toCharUnitsFromBits(AlignmentInBits).getQuantity(); AllocaInst *AI = Builder.CreateAlloca(Builder.getInt8Ty(), Size); AI->setAlignment(AlignmentInBytes); return RValue::get(AI);