From: Chris Lattner Date: Tue, 27 Nov 2007 18:22:04 +0000 (+0000) Subject: sizeof is defined by bitsin(char) not by units of 8 bits. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=da5a6b6d9fd52899499d5b7b46273ec844dcaa6e;p=clang sizeof is defined by bitsin(char) not by units of 8 bits. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44369 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/AST/Expr.cpp b/AST/Expr.cpp index 77221392f2..9bc6b903ad 100644 --- a/AST/Expr.cpp +++ b/AST/Expr.cpp @@ -15,6 +15,7 @@ #include "clang/AST/ASTContext.h" #include "clang/AST/StmtVisitor.h" #include "clang/Basic/IdentifierTable.h" +#include "clang/Basic/TargetInfo.h" using namespace clang; //===----------------------------------------------------------------------===// @@ -587,12 +588,14 @@ bool Expr::isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx, Exp->getOperatorLoc()))); // Get information about the size or align. - if (Exp->getOpcode() == UnaryOperator::SizeOf) - Result = Ctx.getTypeSize(Exp->getSubExpr()->getType(), - Exp->getOperatorLoc()) / 8; - else + if (Exp->getOpcode() == UnaryOperator::AlignOf) { Result = Ctx.getTypeAlign(Exp->getSubExpr()->getType(), Exp->getOperatorLoc()); + } else { + unsigned CharSize = Ctx.Target.getCharWidth(Exp->getOperatorLoc()); + Result = Ctx.getTypeSize(Exp->getSubExpr()->getType(), + Exp->getOperatorLoc()) / CharSize; + } break; case UnaryOperator::LNot: { bool Val = Result != 0;