From aa967bf7571ad28b5cf7d2b3cbe986b8feceaee5 Mon Sep 17 00:00:00 2001 From: gitoleg Date: Mon, 23 Sep 2024 11:11:00 +0300 Subject: [PATCH 1/3] [CIR][CodeGen][BugFix] don't place alloca before the label --- .../CIR/Dialect/Builder/CIRBaseBuilder.h | 8 ++++---- clang/test/CIR/CodeGen/goto.cpp | 20 ++++++++++++++++++- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h b/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h index ed7d13588ec2..bd4c60bb1a61 100644 --- a/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h +++ b/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h @@ -538,14 +538,14 @@ class CIRBaseBuilderTy : public mlir::OpBuilder { // ---------------------- // OpBuilder::InsertPoint getBestAllocaInsertPoint(mlir::Block *block) { - auto lastAlloca = + auto last = std::find_if(block->rbegin(), block->rend(), [](mlir::Operation &op) { - return mlir::isa(&op); + return mlir::isa(&op); }); - if (lastAlloca != block->rend()) + if (last != block->rend()) return OpBuilder::InsertPoint(block, - ++mlir::Block::iterator(&*lastAlloca)); + ++mlir::Block::iterator(&*last)); return OpBuilder::InsertPoint(block, block->begin()); }; diff --git a/clang/test/CIR/CodeGen/goto.cpp b/clang/test/CIR/CodeGen/goto.cpp index 06870feba910..ec5fc90af263 100644 --- a/clang/test/CIR/CodeGen/goto.cpp +++ b/clang/test/CIR/CodeGen/goto.cpp @@ -271,4 +271,22 @@ void flatLoopWithNoTerminatorInFront(int* ptr) { // CHECK: ^bb[[#RETURN]]: // CHECK: cir.return // CHECK: } -// CHECK:} \ No newline at end of file +// CHECK:} + + +struct S {}; + +struct S get(); + +void bar(struct S); + +void foo() { + { + label: + bar(get()); + } +} +// NOFLAT: cir.func @_Z3foov() +// NOFLAT: cir.scope { +// NOFLAT: cir.label "label" +// NOFLAT: %0 = cir.alloca !ty_S, !cir.ptr, ["agg.tmp0"] \ No newline at end of file From 17d4a114c4b37098d2732b11bdd3763192c9db9b Mon Sep 17 00:00:00 2001 From: gitoleg Date: Mon, 23 Sep 2024 11:38:34 +0300 Subject: [PATCH 2/3] minor --- clang/test/CIR/CodeGen/goto.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/clang/test/CIR/CodeGen/goto.cpp b/clang/test/CIR/CodeGen/goto.cpp index ec5fc90af263..f00440b9dd44 100644 --- a/clang/test/CIR/CodeGen/goto.cpp +++ b/clang/test/CIR/CodeGen/goto.cpp @@ -273,11 +273,8 @@ void flatLoopWithNoTerminatorInFront(int* ptr) { // CHECK: } // CHECK:} - struct S {}; - struct S get(); - void bar(struct S); void foo() { @@ -286,6 +283,7 @@ void foo() { bar(get()); } } + // NOFLAT: cir.func @_Z3foov() // NOFLAT: cir.scope { // NOFLAT: cir.label "label" From 83d5b28a21e66b2882f7a69d2a7df23b388ed094 Mon Sep 17 00:00:00 2001 From: Bruno Cardoso Lopes Date: Mon, 23 Sep 2024 10:16:34 -0700 Subject: [PATCH 3/3] Add EOL --- clang/test/CIR/CodeGen/goto.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/test/CIR/CodeGen/goto.cpp b/clang/test/CIR/CodeGen/goto.cpp index f00440b9dd44..5a8d598d95cd 100644 --- a/clang/test/CIR/CodeGen/goto.cpp +++ b/clang/test/CIR/CodeGen/goto.cpp @@ -287,4 +287,4 @@ void foo() { // NOFLAT: cir.func @_Z3foov() // NOFLAT: cir.scope { // NOFLAT: cir.label "label" -// NOFLAT: %0 = cir.alloca !ty_S, !cir.ptr, ["agg.tmp0"] \ No newline at end of file +// NOFLAT: %0 = cir.alloca !ty_S, !cir.ptr, ["agg.tmp0"]