[cfe-commits] r80365 - in /cfe/trunk: lib/CodeGen/CGCXX.cpp lib/CodeGen/CGExpr.cpp lib/Sema/SemaCXXCast.cpp lib/Sema/SemaExprCXX.cpp test/SemaTemplate/instantiate-cast.cpp

Fariborz Jahanian fjahanian at apple.com
Fri Aug 28 08:11:24 PDT 2009


Author: fjahanian
Date: Fri Aug 28 10:11:24 2009
New Revision: 80365

URL: http://llvm.org/viewvc/llvm-project?rev=80365&view=rev
Log:
ir-gen related patch for type conversion
with class type conversion methods. WIP.

Modified:
    cfe/trunk/lib/CodeGen/CGCXX.cpp
    cfe/trunk/lib/CodeGen/CGExpr.cpp
    cfe/trunk/lib/Sema/SemaCXXCast.cpp
    cfe/trunk/lib/Sema/SemaExprCXX.cpp
    cfe/trunk/test/SemaTemplate/instantiate-cast.cpp

Modified: cfe/trunk/lib/CodeGen/CGCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXX.cpp?rev=80365&r1=80364&r2=80365&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXX.cpp Fri Aug 28 10:11:24 2009
@@ -262,19 +262,20 @@
          "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();
-  llvm::Constant *Callee;
-  if (CXXConstructorDecl *CD = dyn_cast<CXXConstructorDecl>(MD))
-    Callee = CGM.GetAddrOfCXXConstructor(CD, Ctor_Complete); 
-  else {
-    const llvm::Type *Ty = 
-      CGM.getTypes().GetFunctionType(CGM.getTypes().getFunctionInfo(MD), 
-                                     FPT->isVariadic());
-    Callee = CGM.GetAddrOfFunction(GlobalDecl(MD), Ty);
-  }
-  llvm::Value *This = EmitLValue(E->getSubExpr()).getAddress();
   
-  return EmitCXXMemberCall(MD, Callee, This, 0, 0);
+  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() {

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=80365&r1=80364&r2=80365&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Fri Aug 28 10:11:24 2009
@@ -1172,6 +1172,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) {
+    const CXXFunctionalCastExpr *CXXFExpr = cast<CXXFunctionalCastExpr>(E);
+    return  LValue::MakeAddr(EmitCXXFunctionalCastExpr(CXXFExpr).getScalarVal(), 0);
+  }
+  
   // If this is an aggregate-to-aggregate cast, just use the input's address as
   // the lvalue.
   if (E->getCastKind() == CastExpr::CK_NoOp)

Modified: cfe/trunk/lib/Sema/SemaCXXCast.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCXXCast.cpp?rev=80365&r1=80364&r2=80365&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaCXXCast.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCXXCast.cpp Fri Aug 28 10:11:24 2009
@@ -776,17 +776,6 @@
     msg = 0;
     return TC_Failed;
   }
-  if (DestType->isRecordType()) {
-    // There are no further possibilities for the target type being a class,
-    // neither in static_cast nor in a C-style cast. So we can fail here.
-    if ((ConversionDecl = 
-          Self.PerformInitializationByConstructor(DestType, &SrcExpr, 1,
-              OpRange.getBegin(), OpRange, DeclarationName(), Sema::IK_Direct)))
-      return TC_Success;
-    // The function already emitted an error.
-    msg = 0;
-    return TC_Failed;
-  }
 
   // FIXME: To get a proper error from invalid conversions here, we need to
   // reimplement more of this.
@@ -799,9 +788,9 @@
                                /*ForceRValue=*/false);
   
   if (ICS.ConversionKind  == ImplicitConversionSequence::UserDefinedConversion)
-    if (CXXConversionDecl *CV = 
-          dyn_cast<CXXConversionDecl>(ICS.UserDefined.ConversionFunction))
-      ConversionDecl = CV;
+    if (CXXMethodDecl *MD = 
+          dyn_cast<CXXMethodDecl>(ICS.UserDefined.ConversionFunction))
+      ConversionDecl = MD;
   return ICS.ConversionKind == ImplicitConversionSequence::BadConversion ?
     TC_NotApplicable : TC_Success;
 }

Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=80365&r1=80364&r2=80365&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Fri Aug 28 10:11:24 2009
@@ -228,12 +228,15 @@
     if (CheckCastTypes(TypeRange, Ty, Exprs[0], Kind, ConversionDecl,
                        /*functional-style*/true))
       return ExprError();
-    exprs.release();
-    return Owned(new (Context) CXXFunctionalCastExpr(Ty.getNonReferenceType(),
+    // We done't build this AST for X(i) where we are constructing an object.
+    if (!ConversionDecl || !isa<CXXConstructorDecl>(ConversionDecl)) {
+      exprs.release();
+      return Owned(new (Context) CXXFunctionalCastExpr(Ty.getNonReferenceType(),
                                           Ty, TyBeginLoc, 
                                           CastExpr::CK_UserDefinedConversion,
                                           Exprs[0], ConversionDecl, 
                                           RParenLoc));
+    }
   }
 
   if (const RecordType *RT = Ty->getAs<RecordType>()) {

Modified: cfe/trunk/test/SemaTemplate/instantiate-cast.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/instantiate-cast.cpp?rev=80365&r1=80364&r2=80365&view=diff

==============================================================================
--- cfe/trunk/test/SemaTemplate/instantiate-cast.cpp (original)
+++ cfe/trunk/test/SemaTemplate/instantiate-cast.cpp Fri Aug 28 10:11:24 2009
@@ -1,6 +1,6 @@
 // RUN: clang-cc -fsyntax-only -verify %s
 
-struct A { int x; }; // expected-note 2 {{candidate}}
+struct A { int x; }; 
 
 class Base { 
 public:
@@ -36,7 +36,7 @@
 template<typename T, typename U>
 struct StaticCast0 {
   void f(T t) {
-    (void)static_cast<U>(t); // expected-error{{initialization of 'struct A'}}
+    (void)static_cast<U>(t); // expected-error{{static_cast from 'int' to 'struct A' is not allowed}}
   }
 };
 





More information about the cfe-commits mailing list