[cfe-commits] r134139 - /cfe/trunk/lib/AST/ExprConstant.cpp

Abramo Bagnara abramo.bagnara at gmail.com
Thu Jun 30 02:36:05 PDT 2011


Author: abramo
Date: Thu Jun 30 04:36:05 2011
New Revision: 134139

URL: http://llvm.org/viewvc/llvm-project?rev=134139&view=rev
Log:
Fixed enum constant evaluation assertions.

Modified:
    cfe/trunk/lib/AST/ExprConstant.cpp

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=134139&r1=134138&r2=134139&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Thu Jun 30 04:36:05 2011
@@ -955,17 +955,21 @@
   IntExprEvaluator(EvalInfo &info, APValue &result)
     : ExprEvaluatorBaseTy(info), Result(result) {}
 
-  bool Success(const llvm::APSInt &SI, const Expr *E) {
-    assert(E->getType()->isIntegralOrEnumerationType() && 
+  bool Success(const llvm::APSInt &SI, QualType Ty) {
+    assert(Ty->isIntegralOrEnumerationType() &&
            "Invalid evaluation result.");
-    assert(SI.isSigned() == E->getType()->isSignedIntegerOrEnumerationType() &&
+    assert(SI.isSigned() == Ty->isSignedIntegerOrEnumerationType() &&
            "Invalid evaluation result.");
-    assert(SI.getBitWidth() == Info.Ctx.getIntWidth(E->getType()) &&
+    assert(SI.getBitWidth() == Info.Ctx.getIntWidth(Ty) &&
            "Invalid evaluation result.");
     Result = APValue(SI);
     return true;
   }
 
+  bool Success(const llvm::APSInt &SI, const Expr *E) {
+    return Success(SI, E->getType());
+  }
+
   bool Success(const llvm::APInt &I, const Expr *E) {
     assert(E->getType()->isIntegralOrEnumerationType() && 
            "Invalid evaluation result.");
@@ -1106,8 +1110,11 @@
 
 bool IntExprEvaluator::CheckReferencedDecl(const Expr* E, const Decl* D) {
   // Enums are integer constant exprs.
-  if (const EnumConstantDecl *ECD = dyn_cast<EnumConstantDecl>(D))
-    return Success(ECD->getInitVal(), E);
+  if (const EnumConstantDecl *ECD = dyn_cast<EnumConstantDecl>(D)) {
+    // Note: provide the type of ECD (rather than that of E),
+    // so that signedness/width will match the ECD init value.
+    return Success(ECD->getInitVal(), ECD->getType());
+  }
 
   // In C++, const, non-volatile integers initialized with ICEs are ICEs.
   // In C, they can also be folded, although they are not ICEs.





More information about the cfe-commits mailing list