Move promoteExprToType from being a static method in SemaExpr.cpp to being
a method named ImpCastExprToType in Sema.

Use this method to insert implicit casts for case statements from their 
operand type to the condition type of the switch.  This fixes a crash on
test/CodeGen/statements.c, reported by Eli Friedman.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46083 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Sema/Sema.cpp b/Sema/Sema.cpp
index a51b075..b53147f 100644
--- a/Sema/Sema.cpp
+++ b/Sema/Sema.cpp
@@ -120,6 +120,19 @@
   TUScope = 0;
 }
 
+/// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit cast. 
+/// If there is already an implicit cast, merge into the existing one.
+void Sema::ImpCastExprToType(Expr *&Expr, QualType Type) {
+  if (Expr->getType() == Type) return;
+  
+  if (ImplicitCastExpr *ImpCast = dyn_cast<ImplicitCastExpr>(Expr))
+    ImpCast->setType(Type);
+  else 
+    Expr = new ImplicitCastExpr(Type, Expr);
+}
+
+
+
 void Sema::DeleteExpr(ExprTy *E) {
   delete static_cast<Expr*>(E);
 }