Clean up enum constants so that they're finally sane.  Fixes PR3173 and a
recently introduced crash.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@91070 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp
index 91fd166..0d55673 100644
--- a/lib/AST/ASTContext.cpp
+++ b/lib/AST/ASTContext.cpp
@@ -4522,7 +4522,7 @@
     return FWIT->getWidth();
   }
   if (EnumType *ET = dyn_cast<EnumType>(T))
-    T = ET->getDecl()->getPromotionType();
+    T = ET->getDecl()->getIntegerType();
   // For builtin types, just use the standard type sizing method
   return (unsigned)getTypeSize(T);
 }
diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp
index 670753c..ea30b19 100644
--- a/lib/AST/ExprConstant.cpp
+++ b/lib/AST/ExprConstant.cpp
@@ -848,16 +848,8 @@
 
 bool IntExprEvaluator::CheckReferencedDecl(const Expr* E, const Decl* D) {
   // Enums are integer constant exprs.
-  if (const EnumConstantDecl *ECD = dyn_cast<EnumConstantDecl>(D)) {
-    // FIXME: This is an ugly hack around the fact that enums don't set their
-    // signedness consistently; see PR3173.
-    APSInt SI = ECD->getInitVal();
-    SI.setIsUnsigned(!E->getType()->isSignedIntegerType());
-    // FIXME: This is an ugly hack around the fact that enums don't
-    // set their width (!?!) consistently; see PR3173.
-    SI.extOrTrunc(Info.Ctx.getIntWidth(E->getType()));
-    return Success(SI, E);
-  }
+  if (const EnumConstantDecl *ECD = dyn_cast<EnumConstantDecl>(D))
+    return Success(ECD->getInitVal(), E);
 
   // In C++, const, non-volatile integers initialized with ICEs are ICEs.
   // In C, they can also be folded, although they are not ICEs.