[clang] 03a9526 - [CGExprAgg] Fix infinite loop in `findPeephole`
Ehud Katz via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 16 03:28:17 PDT 2020
Author: Ehud Katz
Date: 2020-04-16T13:26:23+03:00
New Revision: 03a9526fe5adae909f1d5fd2736703e69fc46e09
URL: https://github.com/llvm/llvm-project/commit/03a9526fe5adae909f1d5fd2736703e69fc46e09
DIFF: https://github.com/llvm/llvm-project/commit/03a9526fe5adae909f1d5fd2736703e69fc46e09.diff
LOG: [CGExprAgg] Fix infinite loop in `findPeephole`
Simplify the function using IgnoreParenNoopCasts.
Fix PR45476
Differential Revision: https://reviews.llvm.org/D78098
Added:
clang/test/CodeGen/pr45476.cpp
Modified:
clang/lib/CodeGen/CGExprAgg.cpp
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp
index fa2d228b7eeb..90d4f7e4e096 100644
--- a/clang/lib/CodeGen/CGExprAgg.cpp
+++ b/clang/lib/CodeGen/CGExprAgg.cpp
@@ -677,17 +677,13 @@ AggExprEmitter::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) {
/// 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;
+static Expr *findPeephole(Expr *op, CastKind kind, const ASTContext &ctx) {
+ op = op->IgnoreParenNoopCasts(ctx);
+ if (auto castE = dyn_cast<CastExpr>(op)) {
+ if (castE->getCastKind() == kind)
+ return castE->getSubExpr();
}
+ return nullptr;
}
void AggExprEmitter::VisitCastExpr(CastExpr *E) {
@@ -776,7 +772,8 @@ void AggExprEmitter::VisitCastExpr(CastExpr *E) {
(isToAtomic ? CK_AtomicToNonAtomic : CK_NonAtomicToAtomic);
// These two cases are reverses of each other; try to peephole them.
- if (Expr *op = findPeephole(E->getSubExpr(), peepholeTarget)) {
+ if (Expr *op =
+ findPeephole(E->getSubExpr(), peepholeTarget, CGF.getContext())) {
assert(CGF.getContext().hasSameUnqualifiedType(op->getType(),
E->getType()) &&
"peephole significantly changed types?");
diff --git a/clang/test/CodeGen/pr45476.cpp b/clang/test/CodeGen/pr45476.cpp
new file mode 100644
index 000000000000..61f3f3649986
--- /dev/null
+++ b/clang/test/CodeGen/pr45476.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -emit-llvm %s -o - | FileCheck %s
+// PR45476
+
+// This test used to get into an infinite loop,
+// which, in turn, caused clang to never finish execution.
+
+struct s3 {
+ char a, b, c;
+};
+
+_Atomic struct s3 a;
+
+extern "C" void foo() {
+ // CHECK-LABEL: @foo
+ // CHECK: store atomic i32
+
+ a = s3{1, 2, 3};
+}
+
More information about the cfe-commits
mailing list