diff options
author | Anders Carlsson <andersca@mac.com> | 2009-09-15 05:28:24 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2009-09-15 05:28:24 +0000 |
commit | 4c5fad3f73957420b0410f7370cbd63b09f32a1c (patch) | |
tree | 0aaf05f4f38f9ca7c0af9da85cd43749d2e7ae57 | |
parent | c0a2fd8f092722c8f78b566ac4506a21437040e9 (diff) |
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
-rw-r--r-- | lib/Sema/Sema.cpp | 12 | ||||
-rw-r--r-- | 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<ImplicitCastExpr>(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<Expr>(), - ToType->isLValueReferenceType()); + QualType CastArgType = ((Expr *)CastArg.get())->getType(); + From = + new (Context) ImplicitCastExpr(CastArgType, CastKind, + CastArg.takeAs<Expr>(), + CastArgType->isLValueReferenceType()); + if (PerformImplicitConversion(From, ToType.getNonReferenceType(), + ICS.UserDefined.After, "converting")) + return true; + return false; } |