From: Chris Lattner Date: Sun, 15 Jul 2007 23:32:58 +0000 (+0000) Subject: set the correct width for a character literal when evaluating it as an i-c-e. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2eadfb638eb1bb6ccfd6fd0453e764d47e27eed9;p=clang set the correct width for a character literal when evaluating it as an i-c-e. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@39886 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/AST/Expr.cpp b/AST/Expr.cpp index f7bf8e58a5..23c67e571c 100644 --- a/AST/Expr.cpp +++ b/AST/Expr.cpp @@ -12,6 +12,7 @@ //===----------------------------------------------------------------------===// #include "clang/AST/Expr.h" +#include "clang/AST/ASTContext.h" #include "clang/AST/StmtVisitor.h" #include "clang/Lex/IdentifierTable.h" using namespace clang; @@ -287,11 +288,13 @@ bool Expr::isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx, case IntegerLiteralClass: Result = cast(this)->getValue(); break; - case CharacterLiteralClass: - // FIXME: This doesn't set the right width etc. - Result.zextOrTrunc(32); // FIXME: NOT RIGHT IN GENERAL. - Result = cast(this)->getValue(); + case CharacterLiteralClass: { + const CharacterLiteral *CL = cast(this); + Result.zextOrTrunc(Ctx.getTypeSize(getType(), CL->getLoc())); + Result = CL->getValue(); + Result.setIsSigned(getType()->isSignedIntegerType()); break; + } case DeclRefExprClass: if (const EnumConstantDecl *D = dyn_cast(cast(this)->getDecl())) { diff --git a/include/clang/AST/Expr.h b/include/clang/AST/Expr.h index 410c650958..33a0dc12c0 100644 --- a/include/clang/AST/Expr.h +++ b/include/clang/AST/Expr.h @@ -161,6 +161,8 @@ public: CharacterLiteral(unsigned value, QualType type, SourceLocation l) : Expr(CharacterLiteralClass, type), Value(value), Loc(l) { } + SourceLocation getLoc() const { return Loc; } + virtual SourceRange getSourceRange() const { return SourceRange(Loc); } unsigned getValue() const { return Value; }