diff options
| author | Fariborz Jahanian <fjahanian@apple.com> | 2009-08-29 19:15:16 +0000 |
|---|---|---|
| committer | Fariborz Jahanian <fjahanian@apple.com> | 2009-08-29 19:15:16 +0000 |
| commit | 3df87678694de01bb51851f3555629a869627c26 (patch) | |
| tree | c1cfd4d995412851a1992e44452b2ba2e23324fd /clang/lib | |
| parent | 9ab0319b2b2c14ab96d39d82afe6c6a0e919670d (diff) | |
| download | bcm5719-llvm-3df87678694de01bb51851f3555629a869627c26.tar.gz bcm5719-llvm-3df87678694de01bb51851f3555629a869627c26.zip | |
Patch for code gen. for c-style cast which ends in
using class's conversion functions [12.3.2-p2]
llvm-svn: 80433
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/CodeGen/CGExpr.cpp | 13 | ||||
| -rw-r--r-- | clang/lib/CodeGen/CGExprAgg.cpp | 8 | ||||
| -rw-r--r-- | clang/lib/CodeGen/CGExprScalar.cpp | 7 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 13 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaExprCXX.cpp | 1 |
5 files changed, 32 insertions, 10 deletions
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index 24442c3a733..400d45ffe56 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -1173,8 +1173,13 @@ LValue CodeGenFunction::EmitConditionalOperator(const ConditionalOperator* E) { /// 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 (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 @@ -1188,10 +1193,6 @@ LValue CodeGenFunction::EmitCastLValue(const CastExpr *E) { if (ICE->isLvalueCast()) return EmitLValue(E->getSubExpr()); - // FIXME: Implement this properly! - if (E->getCastKind() == CastExpr::CK_UserDefinedConversion) - return EmitUnsupportedLValue(E, "user-defined conversion"); - // Otherwise, we must have a cast from scalar to union. assert(E->getCastKind() == CastExpr::CK_ToUnion && "Expected scalar-to-union cast"); diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp index 002c77430f8..4155738a22f 100644 --- a/clang/lib/CodeGen/CGExprAgg.cpp +++ b/clang/lib/CodeGen/CGExprAgg.cpp @@ -178,8 +178,12 @@ void AggExprEmitter::VisitCastExpr(CastExpr *E) { return; } if (E->getCastKind() == CastExpr::CK_UserDefinedConversion) { - CXXFunctionalCastExpr *CXXFExpr = cast<CXXFunctionalCastExpr>(E); - CGF.EmitCXXFunctionalCastExpr(CXXFExpr); + if (const CXXFunctionalCastExpr *CXXFExpr = + dyn_cast<CXXFunctionalCastExpr>(E)) + CGF.EmitCXXFunctionalCastExpr(CXXFExpr); + else + if (isa<CStyleCastExpr>(E)) + Visit(E->getSubExpr()); return; } diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp index 299296a6339..f3a841dbb2f 100644 --- a/clang/lib/CodeGen/CGExprScalar.cpp +++ b/clang/lib/CodeGen/CGExprScalar.cpp @@ -228,8 +228,11 @@ public: } Value *VisitCastExpr(const CastExpr *E) { if (E->getCastKind() == CastExpr::CK_UserDefinedConversion) { - const CXXFunctionalCastExpr *CXXFExpr = cast<CXXFunctionalCastExpr>(E); - return CGF.EmitCXXFunctionalCastExpr(CXXFExpr).getScalarVal(); + 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. diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 474ddf06355..cfb9eb658de 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -3060,6 +3060,19 @@ Sema::ActOnCastExpr(Scope *S, SourceLocation LParenLoc, TypeTy *Ty, if (CheckCastTypes(SourceRange(LParenLoc, RParenLoc), castType, castExpr, Kind, ConversionDecl)) return ExprError(); + if (ConversionDecl) { + // encounterred a c-style cast requiring a conversion function. + if (CXXConversionDecl *CD = dyn_cast<CXXConversionDecl>(ConversionDecl)) { + castExpr = + new (Context) CXXFunctionalCastExpr(castType.getNonReferenceType(), + castType, LParenLoc, + CastExpr::CK_UserDefinedConversion, + castExpr, CD, + RParenLoc); + Kind = CastExpr::CK_UserDefinedConversion; + } + // FIXME. AST for when dealing with conversion functions (FunctionDecl). + } Op.release(); return Owned(new (Context) CStyleCastExpr(castType.getNonReferenceType(), diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp index fe67ec6face..16e83e6514f 100644 --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/lib/Sema/SemaExprCXX.cpp @@ -939,6 +939,7 @@ Sema::PerformImplicitConversion(Expr *&From, QualType ToType, OwningExprResult InitResult = BuildCXXConstructExpr(ToType.getNonReferenceType(), CD, &From, 1); + // Take ownership of this expression. From = InitResult.takeAs<Expr>(); CastKind = CastExpr::CK_ConstructorConversion ; } |

