From: Ted Kremenek Date: Mon, 17 Dec 2007 17:38:43 +0000 (+0000) Subject: Fixed another case where sizeof() returns the size in bytes, not bits. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=060e470e53b73167114284eb0b8c3e25bb3dad99;p=clang Fixed another case where sizeof() returns the size in bytes, not bits. This parallels a previous patch (duplicate logic caused the bug to appear in multiple locations): r44316 (http://llvm.org/viewvc/llvm-project?rev=44316&view=rev). Patch provided by Nuno Lopes. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@45098 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/AST/Expr.cpp b/AST/Expr.cpp index 9747c47080..f4f89001f2 100644 --- a/AST/Expr.cpp +++ b/AST/Expr.cpp @@ -662,10 +662,16 @@ bool Expr::isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx, static_cast(Ctx.getTypeSize(getType(), Exp->getOperatorLoc()))); // Get information about the size or align. - if (Exp->isSizeOf()) - Result = Ctx.getTypeSize(Exp->getArgumentType(), Exp->getOperatorLoc()); + if (Exp->isSizeOf()) { + unsigned CharSize = + Ctx.Target.getCharWidth(Ctx.getFullLoc(Exp->getOperatorLoc())); + + Result = Ctx.getTypeSize(Exp->getArgumentType(), + Exp->getOperatorLoc()) / CharSize; + } else Result = Ctx.getTypeAlign(Exp->getArgumentType(), Exp->getOperatorLoc()); + break; } case BinaryOperatorClass: {