Skip to content

Commit c8defb3

Browse files
committed
[AutoBump] Merge with fixes of be96bd7 (Jan 14)
2 parents 1f0a0e4 + be96bd7 commit c8defb3

File tree

6 files changed

+36
-10
lines changed

6 files changed

+36
-10
lines changed

mlir/lib/Target/Cpp/TranslateToCpp.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ struct CppEmitter {
122122
LogicalResult emitAttribute(Location loc, Attribute attr);
123123

124124
/// Emits operation 'op' with/without training semicolon or returns failure.
125+
///
126+
/// For operations that should never be followed by a semicolon, like ForOp,
127+
/// the `trailingSemicolon` argument is ignored and a semicolon is not
128+
/// emitted.
125129
LogicalResult emitOperation(Operation &op, bool trailingSemicolon);
126130

127131
/// Emits a reference to type 'type' or returns failure.
@@ -1762,7 +1766,7 @@ LogicalResult CppEmitter::emitOperation(Operation &op, bool trailingSemicolon) {
17621766
return success();
17631767

17641768
if (isa<cf::CondBranchOp, emitc::DeclareFuncOp, emitc::ForOp, emitc::IfOp,
1765-
emitc::SwitchOp, emitc::VerbatimOp>(op)) {
1769+
emitc::IncludeOp, emitc::SwitchOp, emitc::VerbatimOp>(op)) {
17661770
trailingSemicolon = false;
17671771
}
17681772

mlir/test/Target/Cpp/declare_func.mlir

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
// RUN: mlir-translate -mlir-to-cpp %s | FileCheck %s
1+
// RUN: mlir-translate -mlir-to-cpp %s | FileCheck --match-full-lines %s
22

33
// CHECK: int32_t bar(int32_t [[V1:[^ ]*]]);
44
emitc.declare_func @bar
5-
// CHECK: int32_t bar(int32_t [[V1:[^ ]*]]) {
5+
// CHECK: int32_t bar(int32_t [[V1:[^ ]*]]) {
6+
// CHECK-NEXT: return [[V1]];
7+
// CHECK-NEXT: }
68
emitc.func @bar(%arg0: i32) -> i32 {
79
emitc.return %arg0 : i32
810
}

mlir/test/Target/Cpp/for.mlir

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// RUN: mlir-translate -mlir-to-cpp %s | FileCheck %s -check-prefix=CPP-DEFAULT
2-
// RUN: mlir-translate -mlir-to-cpp -declare-variables-at-top %s | FileCheck %s -check-prefix=CPP-DECLTOP
1+
// RUN: mlir-translate -mlir-to-cpp %s | FileCheck --match-full-lines %s -check-prefix=CPP-DEFAULT
2+
// RUN: mlir-translate -mlir-to-cpp -declare-variables-at-top %s | FileCheck --match-full-lines %s -check-prefix=CPP-DECLTOP
33

44
func.func @test_for(%arg0 : !emitc.size_t, %arg1 : !emitc.size_t, %arg2 : !emitc.size_t) {
55
%lb = emitc.expression : !emitc.size_t {
@@ -160,5 +160,5 @@ func.func @test_for_yield_2() {
160160
return
161161
}
162162
// CPP-DEFAULT: void test_for_yield_2() {
163-
// CPP-DEFAULT: {{.*}}= M_PI
163+
// CPP-DEFAULT: {{.*}}= M_PI;
164164
// CPP-DEFAULT: for (size_t [[IN:.*]] = 0; [[IN]] < 10; [[IN]] += 1) {

mlir/test/Target/Cpp/if.mlir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// RUN: mlir-translate -mlir-to-cpp %s | FileCheck %s -check-prefix=CPP-DEFAULT
2-
// RUN: mlir-translate -mlir-to-cpp -declare-variables-at-top %s | FileCheck %s -check-prefix=CPP-DECLTOP
1+
// RUN: mlir-translate -mlir-to-cpp %s | FileCheck --match-full-lines %s -check-prefix=CPP-DEFAULT
2+
// RUN: mlir-translate -mlir-to-cpp -declare-variables-at-top %s | FileCheck --match-full-lines %s -check-prefix=CPP-DECLTOP
33

44
func.func @test_if(%arg0: i1, %arg1: f32) {
55
emitc.if %arg0 {
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// RUN: mlir-translate -mlir-to-cpp %s | FileCheck --match-full-lines %s
2+
// RUN: mlir-translate -mlir-to-cpp -declare-variables-at-top %s | FileCheck --match-full-lines %s
3+
4+
func.func @no_extra_semicolon(%arg0: i1) {
5+
emitc.if %arg0 {
6+
emitc.include "myheader.h"
7+
emitc.if %arg0 {
8+
}
9+
emitc.verbatim "return;"
10+
}
11+
return
12+
}
13+
// CHECK: void no_extra_semicolon(bool [[V0:[^ ]*]]) {
14+
// CHECK-NEXT: if ([[V0]]) {
15+
// CHECK-NEXT: #include "myheader.h"
16+
// CHECK-NEXT: if ([[V0]]) {
17+
// CHECK-NEXT: }
18+
// CHECK-NEXT: return;
19+
// CHECK-NEXT: }
20+
// CHECK-NEXT: return;

mlir/test/Target/Cpp/switch.mlir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// RUN: mlir-translate -mlir-to-cpp %s | FileCheck %s -check-prefix=CPP-DEFAULT
2-
// RUN: mlir-translate -mlir-to-cpp -declare-variables-at-top %s | FileCheck %s -check-prefix=CPP-DECLTOP
1+
// RUN: mlir-translate -mlir-to-cpp %s | FileCheck --match-full-lines %s -check-prefix=CPP-DEFAULT
2+
// RUN: mlir-translate -mlir-to-cpp -declare-variables-at-top %s | FileCheck --match-full-lines %s -check-prefix=CPP-DECLTOP
33

44
// CPP-DEFAULT-LABEL: void emitc_switch_ptrdiff_t() {
55
// CPP-DEFAULT: ptrdiff_t v1 = 1;

0 commit comments

Comments
 (0)