]> granicus.if.org Git - clang/commitdiff
Only reuse an already existing ImplicitCastExpr if the cast kinds are the same.
authorAnders Carlsson <andersca@mac.com>
Tue, 15 Sep 2009 05:28:24 +0000 (05:28 +0000)
committerAnders Carlsson <andersca@mac.com>
Tue, 15 Sep 2009 05:28:24 +0000 (05:28 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@81841 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/Sema.cpp
lib/Sema/SemaExprCXX.cpp

index 474ea16e57f9fbb145fc2fcd7195ef4e52c80e48..5a31296781fc912244dd14164628c4de3b23f89e 100644 (file)
@@ -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) {
index a6bf82b590ba2829283364e2012e7266688c9f36..bd581091932b0a84e6a13e16d74977fd1f09bd60 100644 (file)
@@ -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;
     }