If a cast expression needs either a conversion function or a constructor to be called, generate implicit child expressions that call them.

llvm-svn: 81383
diff --git a/clang/lib/CodeGen/CGCXX.cpp b/clang/lib/CodeGen/CGCXX.cpp
index e311912..9963a9b 100644
--- a/clang/lib/CodeGen/CGCXX.cpp
+++ b/clang/lib/CodeGen/CGCXX.cpp
@@ -264,28 +264,6 @@
                            E->arg_begin() + 1, E->arg_end());
 }
 
-RValue
-CodeGenFunction::EmitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *E) {
-  assert((E->getCastKind() == CastExpr::CK_UserDefinedConversion) &&
-         "EmitCXXFunctionalCastExpr - called with wrong cast");
-
-  CXXMethodDecl *MD = E->getTypeConversionMethod();
-  assert(MD && "EmitCXXFunctionalCastExpr - null conversion method");
-  assert(isa<CXXConversionDecl>(MD) && "EmitCXXFunctionalCastExpr - not"
-         " method decl");
-  const FunctionProtoType *FPT = MD->getType()->getAsFunctionProtoType();
-
-  const llvm::Type *Ty =
-    CGM.getTypes().GetFunctionType(CGM.getTypes().getFunctionInfo(MD),
-                                   FPT->isVariadic());
-  llvm::Constant *Callee = CGM.GetAddrOfFunction(GlobalDecl(MD), Ty);
-  llvm::Value *This = EmitLValue(E->getSubExpr()).getAddress();
-  RValue RV = EmitCXXMemberCall(MD, Callee, This, 0, 0);
-  if (RV.isAggregate())
-    RV = RValue::get(RV.getAggregateAddr());
-  return RV;
-}
-
 llvm::Value *CodeGenFunction::LoadCXXThis() {
   assert(isa<CXXMethodDecl>(CurFuncDecl) &&
          "Must be in a C++ member function decl to load 'this'");
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 969b789..dde6899 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -1158,19 +1158,11 @@
 /// all the reasons that casts are permitted with aggregate result, including
 /// noop aggregate casts, and cast from scalar to union.
 LValue CodeGenFunction::EmitCastLValue(const CastExpr *E) {
-  if (E->getCastKind() == CastExpr::CK_UserDefinedConversion) {
-    if (const CXXFunctionalCastExpr *CXXFExpr =
-          dyn_cast<CXXFunctionalCastExpr>(E))
-      return  LValue::MakeAddr(
-                EmitCXXFunctionalCastExpr(CXXFExpr).getScalarVal(), 0);
-    assert(isa<CStyleCastExpr>(E) &&
-           "EmitCastLValue - Expected CStyleCastExpr");
-    return EmitLValue(E->getSubExpr());
-  }
-
   // If this is an aggregate-to-aggregate cast, just use the input's address as
   // the lvalue.
-  if (E->getCastKind() == CastExpr::CK_NoOp)
+  if (E->getCastKind() == CastExpr::CK_NoOp ||
+      E->getCastKind() == CastExpr::CK_ConstructorConversion ||
+      E->getCastKind() == CastExpr::CK_UserDefinedConversion)
     return EmitLValue(E->getSubExpr());
 
   // If this is an lvalue cast, treat it as a no-op.
diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp
index 8bda0f3..2e7e868 100644
--- a/clang/lib/CodeGen/CGExprAgg.cpp
+++ b/clang/lib/CodeGen/CGExprAgg.cpp
@@ -184,19 +184,12 @@
                                LValue::MakeAddr(CastPtr, 0));
     return;
   }
-  if (E->getCastKind() == CastExpr::CK_UserDefinedConversion) {
-    if (const CXXFunctionalCastExpr *CXXFExpr =
-          dyn_cast<CXXFunctionalCastExpr>(E))
-      CGF.EmitCXXFunctionalCastExpr(CXXFExpr);
-    else
-      if (isa<CStyleCastExpr>(E))
-        Visit(E->getSubExpr());
-    return;
-  }
 
   // FIXME: Remove the CK_Unknown check here.
   assert((E->getCastKind() == CastExpr::CK_NoOp ||
-          E->getCastKind() == CastExpr::CK_Unknown) &&
+          E->getCastKind() == CastExpr::CK_Unknown ||
+          E->getCastKind() == CastExpr::CK_UserDefinedConversion ||
+          E->getCastKind() == CastExpr::CK_ConstructorConversion) &&
          "Only no-op casts allowed!");
   assert(CGF.getContext().hasSameUnqualifiedType(E->getSubExpr()->getType(),
                                                  E->getType()) &&
diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp
index b4ce838..aecf955 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -227,14 +227,6 @@
     return llvm::Constant::getNullValue(ConvertType(E->getType()));
   }
   Value *VisitCastExpr(const CastExpr *E) {
-    if (E->getCastKind() == CastExpr::CK_UserDefinedConversion) {
-      if (const CXXFunctionalCastExpr *CXXFExpr =
-            dyn_cast<CXXFunctionalCastExpr>(E))
-        return CGF.EmitCXXFunctionalCastExpr(CXXFExpr).getScalarVal();
-      assert(isa<CStyleCastExpr>(E) &&
-             "VisitCastExpr - missing CStyleCastExpr");
-    }
-
     // Make sure to evaluate VLA bounds now so that we have them for later.
     if (E->getType()->isVariablyModifiedType())
       CGF.EmitVLASize(E->getType());
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp
index be2406d..05f9437 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -324,17 +324,6 @@
                                            llvm::BasicBlock *FalseBlock) {
   if (const ParenExpr *PE = dyn_cast<ParenExpr>(Cond))
     return EmitBranchOnBoolExpr(PE->getSubExpr(), TrueBlock, FalseBlock);
-  if (const CastExpr *E = dyn_cast<CastExpr>(Cond))
-    if (E->getCastKind() == CastExpr::CK_UserDefinedConversion) {
-      if (const CXXFunctionalCastExpr *CXXFExpr =
-            dyn_cast<CXXFunctionalCastExpr>(E)) {
-          EmitCXXFunctionalCastExpr(CXXFExpr);
-        return;
-      }
-      else if (isa<CStyleCastExpr>(E))
-        return EmitBranchOnBoolExpr(E->getSubExpr(), TrueBlock, FalseBlock);
-      assert(false && "EmitBranchOnBoolExpr - Expected CStyleCastExpr");
-    }
 
   if (const BinaryOperator *CondBOp = dyn_cast<BinaryOperator>(Cond)) {
     // Handle X && Y in a condition.
diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h
index 0fac947..07804a9 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -841,8 +841,6 @@
   RValue EmitCXXOperatorMemberCallExpr(const CXXOperatorCallExpr *E,
                                        const CXXMethodDecl *MD);
 
-  RValue EmitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *E);
-
   RValue EmitBuiltinExpr(const FunctionDecl *FD,
                          unsigned BuiltinID, const CallExpr *E);