ekatz created this revision.
ekatz added reviewers: craig.topper, rjmccall, rsmith.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fix PR45476


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D78098

Files:
  clang/lib/CodeGen/CGExprAgg.cpp


Index: clang/lib/CodeGen/CGExprAgg.cpp
===================================================================
--- clang/lib/CodeGen/CGExprAgg.cpp
+++ clang/lib/CodeGen/CGExprAgg.cpp
@@ -678,16 +678,16 @@
 /// Attempt to look through various unimportant expressions to find a
 /// cast of the given kind.
 static Expr *findPeephole(Expr *op, CastKind kind) {
-  while (true) {
-    op = op->IgnoreParens();
-    if (CastExpr *castE = dyn_cast<CastExpr>(op)) {
-      if (castE->getCastKind() == kind)
-        return castE->getSubExpr();
-      if (castE->getCastKind() == CK_NoOp)
-        continue;
-    }
-    return nullptr;
+  while (CastExpr *castE = dyn_cast<CastExpr>(op->IgnoreParens())) {
+    if (castE->getCastKind() == kind)
+      return castE->getSubExpr();
+
+    if (castE->getCastKind() != CK_NoOp || castE == op)
+      break;
+
+    op = castE;
   }
+  return nullptr;
 }
 
 void AggExprEmitter::VisitCastExpr(CastExpr *E) {


Index: clang/lib/CodeGen/CGExprAgg.cpp
===================================================================
--- clang/lib/CodeGen/CGExprAgg.cpp
+++ clang/lib/CodeGen/CGExprAgg.cpp
@@ -678,16 +678,16 @@
 /// Attempt to look through various unimportant expressions to find a
 /// cast of the given kind.
 static Expr *findPeephole(Expr *op, CastKind kind) {
-  while (true) {
-    op = op->IgnoreParens();
-    if (CastExpr *castE = dyn_cast<CastExpr>(op)) {
-      if (castE->getCastKind() == kind)
-        return castE->getSubExpr();
-      if (castE->getCastKind() == CK_NoOp)
-        continue;
-    }
-    return nullptr;
+  while (CastExpr *castE = dyn_cast<CastExpr>(op->IgnoreParens())) {
+    if (castE->getCastKind() == kind)
+      return castE->getSubExpr();
+
+    if (castE->getCastKind() != CK_NoOp || castE == op)
+      break;
+
+    op = castE;
   }
+  return nullptr;
 }
 
 void AggExprEmitter::VisitCastExpr(CastExpr *E) {
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to