[cfe-commits] r80178 - in /cfe/trunk/lib: CodeGen/CGCXX.cpp CodeGen/CGExprAgg.cpp CodeGen/CGExprScalar.cpp CodeGen/CodeGenFunction.h Sema/SemaCXXCast.cpp
Fariborz Jahanian
fjahanian at apple.com
Wed Aug 26 16:31:31 PDT 2009
Author: fjahanian
Date: Wed Aug 26 18:31:30 2009
New Revision: 80178
URL: http://llvm.org/viewvc/llvm-project?rev=80178&view=rev
Log:
ir-gen for type convesion of class objects. WIP.
Modified:
cfe/trunk/lib/CodeGen/CGCXX.cpp
cfe/trunk/lib/CodeGen/CGExprAgg.cpp
cfe/trunk/lib/CodeGen/CGExprScalar.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/lib/Sema/SemaCXXCast.cpp
Modified: cfe/trunk/lib/CodeGen/CGCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXX.cpp?rev=80178&r1=80177&r2=80178&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXX.cpp Wed Aug 26 18:31:30 2009
@@ -256,6 +256,27 @@
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();
+ 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);
+}
+
llvm::Value *CodeGenFunction::LoadCXXThis() {
assert(isa<CXXMethodDecl>(CurFuncDecl) &&
"Must be in a C++ member function decl to load 'this'");
Modified: cfe/trunk/lib/CodeGen/CGExprAgg.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprAgg.cpp?rev=80178&r1=80177&r2=80178&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprAgg.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprAgg.cpp Wed Aug 26 18:31:30 2009
@@ -177,7 +177,12 @@
LValue::MakeAddr(CastPtr, 0));
return;
}
-
+ if (E->getCastKind() == CastExpr::CK_UserDefinedConversion) {
+ CXXFunctionalCastExpr *CXXFExpr = cast<CXXFunctionalCastExpr>(E);
+ CGF.EmitCXXFunctionalCastExpr(CXXFExpr);
+ return;
+ }
+
// FIXME: Remove the CK_Unknown check here.
assert((E->getCastKind() == CastExpr::CK_NoOp ||
E->getCastKind() == CastExpr::CK_Unknown) &&
Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=80178&r1=80177&r2=80178&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Wed Aug 26 18:31:30 2009
@@ -227,6 +227,11 @@
return llvm::Constant::getNullValue(ConvertType(E->getType()));
}
Value *VisitCastExpr(const CastExpr *E) {
+ if (E->getCastKind() == CastExpr::CK_UserDefinedConversion) {
+ const CXXFunctionalCastExpr *CXXFExpr = cast<CXXFunctionalCastExpr>(E);
+ return CGF.EmitCXXFunctionalCastExpr(CXXFExpr).getScalarVal();
+ }
+
// Make sure to evaluate VLA bounds now so that we have them for later.
if (E->getType()->isVariablyModifiedType())
CGF.EmitVLASize(E->getType());
Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=80178&r1=80177&r2=80178&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Wed Aug 26 18:31:30 2009
@@ -838,6 +838,8 @@
RValue EmitCXXOperatorMemberCallExpr(const CXXOperatorCallExpr *E,
const CXXMethodDecl *MD);
+ RValue EmitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *E);
+
RValue EmitBuiltinExpr(const FunctionDecl *FD,
unsigned BuiltinID, const CallExpr *E);
Modified: cfe/trunk/lib/Sema/SemaCXXCast.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCXXCast.cpp?rev=80178&r1=80177&r2=80178&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCXXCast.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCXXCast.cpp Wed Aug 26 18:31:30 2009
@@ -789,6 +789,10 @@
// check for ambiguity or access.
ImplicitConversionSequence ICS = Self.TryImplicitConversion(
SrcExpr, DestType);
+ if (ICS.ConversionKind == ImplicitConversionSequence::UserDefinedConversion)
+ if (CXXConversionDecl *CV =
+ dyn_cast<CXXConversionDecl>(ICS.UserDefined.ConversionFunction))
+ ConversionDecl = CV;
return ICS.ConversionKind == ImplicitConversionSequence::BadConversion ?
TC_NotApplicable : TC_Success;
}
More information about the cfe-commits
mailing list