summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-05-09 05:59:00 +0000
committerChris Lattner <sabre@nondot.org>2008-05-09 05:59:00 +0000
commit55258cf27822b9ee51fc7aea3f4b636d51e72479 (patch)
treed9f37eb5217e1cdee672fda216bde731c59f185e /clang/lib/Sema
parent5a9aaaf687ca4e6d17209ceb9b9f1d9a954df416 (diff)
downloadbcm5719-llvm-55258cf27822b9ee51fc7aea3f4b636d51e72479.tar.gz
bcm5719-llvm-55258cf27822b9ee51fc7aea3f4b636d51e72479.zip
simplify some code, don't assume that sizeof(long) < sizeof(long long).
llvm-svn: 50888
Diffstat (limited to 'clang/lib/Sema')
-rw-r--r--clang/lib/Sema/SemaExpr.cpp23
1 files changed, 12 insertions, 11 deletions
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index edd9284a39a..4dcc6843184 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -253,10 +253,11 @@ Action::ExprResult Sema::ActOnNumericConstant(const Token &Tok) {
bool AllowUnsigned = Literal.isUnsigned || Literal.getRadix() != 10;
// Check from smallest to largest, picking the smallest type we can.
+ unsigned Width = 0;
if (!Literal.isLong && !Literal.isLongLong) {
// Are int/unsigned possibilities?
- unsigned IntSize =
- static_cast<unsigned>(Context.getTypeSize(Context.IntTy));
+ unsigned IntSize = Context.Target.getIntWidth();
+
// Does it fit in a unsigned int?
if (ResultVal.isIntN(IntSize)) {
// Does it fit in a signed int?
@@ -264,16 +265,13 @@ Action::ExprResult Sema::ActOnNumericConstant(const Token &Tok) {
Ty = Context.IntTy;
else if (AllowUnsigned)
Ty = Context.UnsignedIntTy;
+ Width = IntSize;
}
-
- if (!Ty.isNull())
- ResultVal.trunc(IntSize);
}
// Are long/unsigned long possibilities?
if (Ty.isNull() && !Literal.isLongLong) {
- unsigned LongSize =
- static_cast<unsigned>(Context.getTypeSize(Context.LongTy));
+ unsigned LongSize = Context.Target.getLongWidth();
// Does it fit in a unsigned long?
if (ResultVal.isIntN(LongSize)) {
@@ -282,15 +280,13 @@ Action::ExprResult Sema::ActOnNumericConstant(const Token &Tok) {
Ty = Context.LongTy;
else if (AllowUnsigned)
Ty = Context.UnsignedLongTy;
+ Width = LongSize;
}
- if (!Ty.isNull())
- ResultVal.trunc(LongSize);
}
// Finally, check long long if needed.
if (Ty.isNull()) {
- unsigned LongLongSize =
- static_cast<unsigned>(Context.getTypeSize(Context.LongLongTy));
+ unsigned LongLongSize = Context.Target.getLongLongWidth();
// Does it fit in a unsigned long long?
if (ResultVal.isIntN(LongLongSize)) {
@@ -299,6 +295,7 @@ Action::ExprResult Sema::ActOnNumericConstant(const Token &Tok) {
Ty = Context.LongLongTy;
else if (AllowUnsigned)
Ty = Context.UnsignedLongLongTy;
+ Width = LongLongSize;
}
}
@@ -307,7 +304,11 @@ Action::ExprResult Sema::ActOnNumericConstant(const Token &Tok) {
if (Ty.isNull()) {
Diag(Tok.getLocation(), diag::warn_integer_too_large_for_signed);
Ty = Context.UnsignedLongLongTy;
+ Width = Context.Target.getLongLongWidth();
}
+
+ if (ResultVal.getBitWidth() != Width)
+ ResultVal.trunc(Width);
}
Res = new IntegerLiteral(ResultVal, Ty, Tok.getLocation());
OpenPOWER on IntegriCloud