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..5a8d598d95cd 100644 --- a/clang/test/CIR/CodeGen/goto.cpp +++ b/clang/test/CIR/CodeGen/goto.cpp @@ -271,4 +271,20 @@ 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"]