Silence VC++ warnings, patch by Hartmut Kaiser

llvm-svn: 41693
This commit is contained in:
Chris Lattner 2007-09-04 02:45:27 +00:00
parent fb2eb6941a
commit 9cf21c5a2c
5 changed files with 36 additions and 23 deletions

View File

@ -499,20 +499,23 @@ bool Expr::isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx,
break;
case CharacterLiteralClass: {
const CharacterLiteral *CL = cast<CharacterLiteral>(this);
Result.zextOrTrunc(Ctx.getTypeSize(getType(), CL->getLoc()));
Result.zextOrTrunc(
static_cast<uint32_t>(Ctx.getTypeSize(getType(), CL->getLoc())));
Result = CL->getValue();
Result.setIsUnsigned(!getType()->isSignedIntegerType());
break;
}
case TypesCompatibleExprClass: {
const TypesCompatibleExpr *TCE = cast<TypesCompatibleExpr>(this);
Result.zextOrTrunc(Ctx.getTypeSize(getType(), TCE->getLocStart()));
Result.zextOrTrunc(
static_cast<uint32_t>(Ctx.getTypeSize(getType(), TCE->getLocStart())));
Result = TCE->typesAreCompatible();
break;
}
case CallExprClass: {
const CallExpr *CE = cast<CallExpr>(this);
Result.zextOrTrunc(Ctx.getTypeSize(getType(), CE->getLocStart()));
Result.zextOrTrunc(
static_cast<uint32_t>(Ctx.getTypeSize(getType(), CE->getLocStart())));
if (CE->isBuiltinClassifyType(Result))
break;
if (Loc) *Loc = getLocStart();
@ -550,7 +553,8 @@ bool Expr::isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx,
return false;
// Return the result in the right width.
Result.zextOrTrunc(Ctx.getTypeSize(getType(), Exp->getOperatorLoc()));
Result.zextOrTrunc(
static_cast<uint32_t>(Ctx.getTypeSize(getType(), Exp->getOperatorLoc())));
// Get information about the size or align.
if (Exp->getOpcode() == UnaryOperator::SizeOf)
@ -562,7 +566,8 @@ bool Expr::isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx,
break;
case UnaryOperator::LNot: {
bool Val = Result != 0;
Result.zextOrTrunc(Ctx.getTypeSize(getType(), Exp->getOperatorLoc()));
Result.zextOrTrunc(
static_cast<uint32_t>(Ctx.getTypeSize(getType(), Exp->getOperatorLoc())));
Result = Val;
break;
}
@ -584,7 +589,8 @@ bool Expr::isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx,
return false;
// Return the result in the right width.
Result.zextOrTrunc(Ctx.getTypeSize(getType(), Exp->getOperatorLoc()));
Result.zextOrTrunc(
static_cast<uint32_t>(Ctx.getTypeSize(getType(), Exp->getOperatorLoc())));
// Get information about the size or align.
if (Exp->isSizeOf())
@ -647,10 +653,12 @@ bool Expr::isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx,
case BinaryOperator::Add: Result += RHS; break;
case BinaryOperator::Sub: Result -= RHS; break;
case BinaryOperator::Shl:
Result <<= RHS.getLimitedValue(Result.getBitWidth()-1);
Result <<=
static_cast<uint32_t>(RHS.getLimitedValue(Result.getBitWidth()-1));
break;
case BinaryOperator::Shr:
Result >>= RHS.getLimitedValue(Result.getBitWidth()-1);
Result >>=
static_cast<uint32_t>(RHS.getLimitedValue(Result.getBitWidth()-1));
break;
case BinaryOperator::LT: Result = Result < RHS; break;
case BinaryOperator::GT: Result = Result > RHS; break;
@ -711,7 +719,8 @@ bool Expr::isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx,
return false;
// Figure out if this is a truncate, extend or noop cast.
unsigned DestWidth = Ctx.getTypeSize(getType(), CastLoc);
unsigned DestWidth =
static_cast<uint32_t>(Ctx.getTypeSize(getType(), CastLoc));
// If the input is signed, do a sign extend, noop, or truncate.
if (SubExpr->getType()->isSignedIntegerType())

View File

@ -475,7 +475,7 @@ static bool EvaluateDirectiveSubExpr(llvm::APSInt &LHS, unsigned MinPrec,
break;
case tok::lessless: {
// Determine whether overflow is about to happen.
unsigned ShAmt = RHS.getLimitedValue();
unsigned ShAmt = static_cast<unsigned>(RHS.getLimitedValue());
if (ShAmt >= LHS.getBitWidth())
Overflow = true, ShAmt = LHS.getBitWidth()-1;
else if (LHS.isUnsigned())
@ -490,7 +490,7 @@ static bool EvaluateDirectiveSubExpr(llvm::APSInt &LHS, unsigned MinPrec,
}
case tok::greatergreater: {
// Determine whether overflow is about to happen.
unsigned ShAmt = RHS.getLimitedValue();
unsigned ShAmt = static_cast<unsigned>(RHS.getLimitedValue());
if (ShAmt >= LHS.getBitWidth())
Overflow = true, ShAmt = LHS.getBitWidth()-1;
Res = LHS >> ShAmt;

View File

@ -36,8 +36,8 @@ namespace clang {
class TypedefDecl;
class FunctionDecl;
class QualType;
class LangOptions;
class DeclaratorChunk;
struct LangOptions;
struct DeclaratorChunk;
class Token;
class IntegerLiteral;
class ArrayType;

View File

@ -1190,7 +1190,8 @@ Sema::DeclTy *Sema::ParseEnumConstant(Scope *S, DeclTy *theEnumDecl,
} else {
// First value, set to zero.
EltTy = Context.IntTy;
EnumVal.zextOrTrunc(Context.getTypeSize(EltTy, IdLoc));
EnumVal.zextOrTrunc(
static_cast<uint32_t>(Context.getTypeSize(EltTy, IdLoc)));
}
}
@ -1420,7 +1421,7 @@ void Sema::HandleOCUVectorTypeAttribute(TypedefDecl *tDecl,
}
// unlike gcc's vector_size attribute, the size is specified as the
// number of elements, not the number of bytes.
unsigned vectorSize = vecSize.getZExtValue();
unsigned vectorSize = static_cast<unsigned>(vecSize.getZExtValue());
if (vectorSize == 0) {
Diag(rawAttr->getAttributeLoc(), diag::err_attribute_zero_size,
@ -1473,9 +1474,10 @@ QualType Sema::HandleVectorTypeAttribute(QualType curType,
curType.getCanonicalType().getAsString());
return QualType();
}
unsigned typeSize = Context.getTypeSize(curType, rawAttr->getAttributeLoc());
unsigned typeSize = static_cast<unsigned>(
Context.getTypeSize(curType, rawAttr->getAttributeLoc()));
// vecSize is specified in bytes - convert to bits.
unsigned vectorSize = vecSize.getZExtValue() * 8;
unsigned vectorSize = static_cast<unsigned>(vecSize.getZExtValue() * 8);
// the vector size needs to be an integral multiple of the type size.
if (vectorSize % typeSize) {

View File

@ -129,7 +129,8 @@ Action::ExprResult Sema::ParseNumericConstant(const Token &Tok) {
if (Tok.getLength() == 1) {
const char *t = PP.getSourceManager().getCharacterData(Tok.getLocation());
unsigned IntSize = Context.getTypeSize(Context.IntTy, Tok.getLocation());
unsigned IntSize = static_cast<unsigned>(
Context.getTypeSize(Context.IntTy, Tok.getLocation()));
return ExprResult(new IntegerLiteral(llvm::APInt(IntSize, *t-'0'),
Context.IntTy,
Tok.getLocation()));
@ -181,7 +182,8 @@ Action::ExprResult Sema::ParseNumericConstant(const Token &Tok) {
// Check from smallest to largest, picking the smallest type we can.
if (!Literal.isLong && !Literal.isLongLong) {
// Are int/unsigned possibilities?
unsigned IntSize = Context.getTypeSize(Context.IntTy,Tok.getLocation());
unsigned IntSize = static_cast<unsigned>(
Context.getTypeSize(Context.IntTy,Tok.getLocation()));
// Does it fit in a unsigned int?
if (ResultVal.isIntN(IntSize)) {
// Does it fit in a signed int?
@ -197,8 +199,8 @@ Action::ExprResult Sema::ParseNumericConstant(const Token &Tok) {
// Are long/unsigned long possibilities?
if (t.isNull() && !Literal.isLongLong) {
unsigned LongSize = Context.getTypeSize(Context.LongTy,
Tok.getLocation());
unsigned LongSize = static_cast<unsigned>(
Context.getTypeSize(Context.LongTy, Tok.getLocation()));
// Does it fit in a unsigned long?
if (ResultVal.isIntN(LongSize)) {
@ -214,8 +216,8 @@ Action::ExprResult Sema::ParseNumericConstant(const Token &Tok) {
// Finally, check long long if needed.
if (t.isNull()) {
unsigned LongLongSize =
Context.getTypeSize(Context.LongLongTy, Tok.getLocation());
unsigned LongLongSize = static_cast<unsigned>(
Context.getTypeSize(Context.LongLongTy, Tok.getLocation()));
// Does it fit in a unsigned long long?
if (ResultVal.isIntN(LongLongSize)) {