]> granicus.if.org Git - clang/commitdiff
set the correct width for a character literal when evaluating it as an i-c-e.
authorChris Lattner <sabre@nondot.org>
Sun, 15 Jul 2007 23:32:58 +0000 (23:32 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 15 Jul 2007 23:32:58 +0000 (23:32 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@39886 91177308-0d34-0410-b5e6-96231b3b80d8

AST/Expr.cpp
include/clang/AST/Expr.h

index f7bf8e58a545a67be3f6f6dbd0d2d22dadb8ed7b..23c67e571c527bf5a81b88c654d05927764b6c14 100644 (file)
@@ -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<IntegerLiteral>(this)->getValue();
     break;
-  case CharacterLiteralClass:
-    // FIXME: This doesn't set the right width etc.
-    Result.zextOrTrunc(32);  // FIXME: NOT RIGHT IN GENERAL.
-    Result = cast<CharacterLiteral>(this)->getValue();
+  case CharacterLiteralClass: {
+    const CharacterLiteral *CL = cast<CharacterLiteral>(this);
+    Result.zextOrTrunc(Ctx.getTypeSize(getType(), CL->getLoc()));                              
+    Result = CL->getValue();
+    Result.setIsSigned(getType()->isSignedIntegerType());
     break;
+  }
   case DeclRefExprClass:
     if (const EnumConstantDecl *D = 
           dyn_cast<EnumConstantDecl>(cast<DeclRefExpr>(this)->getDecl())) {
index 410c65095860d11fbc217615bb245fd2be10bc53..33a0dc12c0f4dba905fb66fe31ac072a04646219 100644 (file)
@@ -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; }