From 4c5fad3f73957420b0410f7370cbd63b09f32a1c Mon Sep 17 00:00:00 2001 From: Anders Carlsson Date: Tue, 15 Sep 2009 05:28:24 +0000 Subject: [PATCH] Only reuse an already existing ImplicitCastExpr if the cast kinds are the same. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@81841 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/Sema.cpp | 12 ++++++++---- lib/Sema/SemaExprCXX.cpp | 12 +++++++++--- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp index 474ea16e57..5a31296781 100644 --- a/lib/Sema/Sema.cpp +++ b/lib/Sema/Sema.cpp @@ -230,10 +230,14 @@ void Sema::ImpCastExprToType(Expr *&Expr, QualType Ty, } if (ImplicitCastExpr *ImpCast = dyn_cast(Expr)) { - ImpCast->setType(Ty); - ImpCast->setLvalueCast(isLvalue); - } else - Expr = new (Context) ImplicitCastExpr(Ty, Kind, Expr, isLvalue); + if (ImpCast->getCastKind() == Kind) { + ImpCast->setType(Ty); + ImpCast->setLvalueCast(isLvalue); + return; + } + } + + Expr = new (Context) ImplicitCastExpr(Ty, Kind, Expr, isLvalue); } void Sema::DeleteExpr(ExprTy *E) { diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp index a6bf82b590..bd58109193 100644 --- a/lib/Sema/SemaExprCXX.cpp +++ b/lib/Sema/SemaExprCXX.cpp @@ -991,9 +991,15 @@ Sema::PerformImplicitConversion(Expr *&From, QualType ToType, if (CastArg.isInvalid()) return true; - From = new (Context) ImplicitCastExpr(ToType.getNonReferenceType(), - CastKind, CastArg.takeAs(), - ToType->isLValueReferenceType()); + QualType CastArgType = ((Expr *)CastArg.get())->getType(); + From = + new (Context) ImplicitCastExpr(CastArgType, CastKind, + CastArg.takeAs(), + CastArgType->isLValueReferenceType()); + if (PerformImplicitConversion(From, ToType.getNonReferenceType(), + ICS.UserDefined.After, "converting")) + return true; + return false; }