Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mlir/include/mlir/Dialect/EmitC/IR/EmitC.td
Original file line number Diff line number Diff line change
Expand Up @@ -1405,6 +1405,7 @@ def EmitC_SwitchOp : EmitC_Op<"switch", [RecursiveMemoryEffects,
func2(v4);
break;
}
}
```
}];

Expand Down
2 changes: 1 addition & 1 deletion mlir/lib/Target/Cpp/TranslateToCpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ static LogicalResult printOperation(CppEmitter &emitter,
if (failed(emitSwitchCase(emitter, os, switchOp.getDefaultRegion())))
return failure();

os.unindent() << "}";
os.unindent() << "}\n}";
return success();
}

Expand Down
28 changes: 28 additions & 0 deletions mlir/test/Target/Cpp/switch.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
// CPP-DEFAULT: func2(v4);
// CPP-DEFAULT: break;
// CPP-DEFAULT: }
// CPP-DEFAULT: }
// CPP-DEFAULT: return;
// CPP-DEFAULT: }

Expand All @@ -40,6 +41,7 @@
// CPP-DECLTOP: func2(v2);
// CPP-DECLTOP: break;
// CPP-DECLTOP: }
// CPP-DECLTOP: }
// CPP-DECLTOP: return;
// CPP-DECLTOP: }
func.func @emitc_switch_ptrdiff_t() {
Expand Down Expand Up @@ -77,6 +79,7 @@ func.func @emitc_switch_ptrdiff_t() {
// CPP-DEFAULT: func2(v4);
// CPP-DEFAULT: break;
// CPP-DEFAULT: }
// CPP-DEFAULT: }
// CPP-DEFAULT: return;
// CPP-DEFAULT: }

Expand All @@ -100,6 +103,7 @@ func.func @emitc_switch_ptrdiff_t() {
// CPP-DECLTOP: func2(v2);
// CPP-DECLTOP: break;
// CPP-DECLTOP: }
// CPP-DECLTOP: }
// CPP-DECLTOP: return;
// CPP-DECLTOP: }
func.func @emitc_switch_ssize_t() {
Expand Down Expand Up @@ -138,6 +142,7 @@ func.func @emitc_switch_ssize_t() {
// CPP-DEFAULT: func2(v4);
// CPP-DEFAULT: break;
// CPP-DEFAULT: }
// CPP-DEFAULT: }
// CPP-DEFAULT: return;
// CPP-DEFAULT: }

Expand All @@ -161,6 +166,7 @@ func.func @emitc_switch_ssize_t() {
// CPP-DECLTOP: func2(v2);
// CPP-DECLTOP: break;
// CPP-DECLTOP: }
// CPP-DECLTOP: }
// CPP-DECLTOP: return;
// CPP-DECLTOP: }
func.func @emitc_switch_size_t() {
Expand Down Expand Up @@ -199,6 +205,7 @@ func.func @emitc_switch_size_t() {
// CPP-DEFAULT: func2(v4);
// CPP-DEFAULT: break;
// CPP-DEFAULT: }
// CPP-DEFAULT: }
// CPP-DEFAULT: return;
// CPP-DEFAULT: }

Expand All @@ -222,6 +229,7 @@ func.func @emitc_switch_size_t() {
// CPP-DECLTOP: func2(v2);
// CPP-DECLTOP: break;
// CPP-DECLTOP: }
// CPP-DECLTOP: }
// CPP-DECLTOP: return;
// CPP-DECLTOP: }
func.func @emitc_switch_index() {
Expand Down Expand Up @@ -260,6 +268,7 @@ func.func @emitc_switch_index() {
// CPP-DEFAULT: func2(v4);
// CPP-DEFAULT: break;
// CPP-DEFAULT: }
// CPP-DEFAULT: }
// CPP-DEFAULT: return;
// CPP-DEFAULT: }

Expand All @@ -283,6 +292,7 @@ func.func @emitc_switch_index() {
// CPP-DECLTOP: func2(v2);
// CPP-DECLTOP: break;
// CPP-DECLTOP: }
// CPP-DECLTOP: }
// CPP-DECLTOP: return;
// CPP-DECLTOP: }
func.func @emitc_switch_opaque() {
Expand Down Expand Up @@ -322,6 +332,7 @@ func.func @emitc_switch_opaque() {
// CPP-DEFAULT: func2(v4);
// CPP-DEFAULT: break;
// CPP-DEFAULT: }
// CPP-DEFAULT: }
// CPP-DEFAULT: return;
// CPP-DEFAULT: }

Expand All @@ -345,6 +356,7 @@ func.func @emitc_switch_opaque() {
// CPP-DECLTOP: func2(v2);
// CPP-DECLTOP: break;
// CPP-DECLTOP: }
// CPP-DECLTOP: }
// CPP-DECLTOP: return;
// CPP-DECLTOP: }
func.func @emitc_switch_i1() {
Expand Down Expand Up @@ -383,6 +395,7 @@ func.func @emitc_switch_i1() {
// CPP-DEFAULT: func2(v4);
// CPP-DEFAULT: break;
// CPP-DEFAULT: }
// CPP-DEFAULT: }
// CPP-DEFAULT: return;
// CPP-DEFAULT: }

Expand All @@ -406,6 +419,7 @@ func.func @emitc_switch_i1() {
// CPP-DECLTOP: func2(v2);
// CPP-DECLTOP: break;
// CPP-DECLTOP: }
// CPP-DECLTOP: }
// CPP-DECLTOP: return;
// CPP-DECLTOP: }
func.func @emitc_switch_i8() {
Expand Down Expand Up @@ -444,6 +458,7 @@ func.func @emitc_switch_i8() {
// CPP-DEFAULT: func2(v4);
// CPP-DEFAULT: break;
// CPP-DEFAULT: }
// CPP-DEFAULT: }
// CPP-DEFAULT: return;
// CPP-DEFAULT: }

Expand All @@ -467,6 +482,7 @@ func.func @emitc_switch_i8() {
// CPP-DECLTOP: func2(v2);
// CPP-DECLTOP: break;
// CPP-DECLTOP: }
// CPP-DECLTOP: }
// CPP-DECLTOP: return;
// CPP-DECLTOP: }
func.func @emitc_switch_ui8() {
Expand Down Expand Up @@ -505,6 +521,7 @@ func.func @emitc_switch_ui8() {
// CPP-DEFAULT: func2(v4);
// CPP-DEFAULT: break;
// CPP-DEFAULT: }
// CPP-DEFAULT: }
// CPP-DEFAULT: return;
// CPP-DEFAULT: }

Expand All @@ -528,6 +545,7 @@ func.func @emitc_switch_ui8() {
// CPP-DECLTOP: func2(v2);
// CPP-DECLTOP: break;
// CPP-DECLTOP: }
// CPP-DECLTOP: }
// CPP-DECLTOP: return;
// CPP-DECLTOP: }
func.func @emitc_switch_i16() {
Expand Down Expand Up @@ -566,6 +584,7 @@ func.func @emitc_switch_i16() {
// CPP-DEFAULT: func2(v4);
// CPP-DEFAULT: break;
// CPP-DEFAULT: }
// CPP-DEFAULT: }
// CPP-DEFAULT: return;
// CPP-DEFAULT: }

Expand All @@ -589,6 +608,7 @@ func.func @emitc_switch_i16() {
// CPP-DECLTOP: func2(v2);
// CPP-DECLTOP: break;
// CPP-DECLTOP: }
// CPP-DECLTOP: }
// CPP-DECLTOP: return;
// CPP-DECLTOP: }
func.func @emitc_switch_ui16() {
Expand Down Expand Up @@ -627,6 +647,7 @@ func.func @emitc_switch_ui16() {
// CPP-DEFAULT: func2(v4);
// CPP-DEFAULT: break;
// CPP-DEFAULT: }
// CPP-DEFAULT: }
// CPP-DEFAULT: return;
// CPP-DEFAULT: }

Expand All @@ -650,6 +671,7 @@ func.func @emitc_switch_ui16() {
// CPP-DECLTOP: func2(v2);
// CPP-DECLTOP: break;
// CPP-DECLTOP: }
// CPP-DECLTOP: }
// CPP-DECLTOP: return;
// CPP-DECLTOP: }
func.func @emitc_switch_i32() {
Expand Down Expand Up @@ -688,6 +710,7 @@ func.func @emitc_switch_i32() {
// CPP-DEFAULT: func2(v4);
// CPP-DEFAULT: break;
// CPP-DEFAULT: }
// CPP-DEFAULT: }
// CPP-DEFAULT: return;
// CPP-DEFAULT: }

Expand All @@ -711,6 +734,7 @@ func.func @emitc_switch_i32() {
// CPP-DECLTOP: func2(v2);
// CPP-DECLTOP: break;
// CPP-DECLTOP: }
// CPP-DECLTOP: }
// CPP-DECLTOP: return;
// CPP-DECLTOP: }
func.func @emitc_switch_ui32() {
Expand Down Expand Up @@ -749,6 +773,7 @@ func.func @emitc_switch_ui32() {
// CPP-DEFAULT: func2(v4);
// CPP-DEFAULT: break;
// CPP-DEFAULT: }
// CPP-DEFAULT: }
// CPP-DEFAULT: return;
// CPP-DEFAULT: }

Expand All @@ -772,6 +797,7 @@ func.func @emitc_switch_ui32() {
// CPP-DECLTOP: func2(v2);
// CPP-DECLTOP: break;
// CPP-DECLTOP: }
// CPP-DECLTOP: }
// CPP-DECLTOP: return;
// CPP-DECLTOP: }
func.func @emitc_switch_i64() {
Expand Down Expand Up @@ -810,6 +836,7 @@ func.func @emitc_switch_i64() {
// CPP-DEFAULT: func2(v4);
// CPP-DEFAULT: break;
// CPP-DEFAULT: }
// CPP-DEFAULT: }
// CPP-DEFAULT: return;
// CPP-DEFAULT: }

Expand All @@ -833,6 +860,7 @@ func.func @emitc_switch_i64() {
// CPP-DECLTOP: func2(v2);
// CPP-DECLTOP: break;
// CPP-DECLTOP: }
// CPP-DECLTOP: }
// CPP-DECLTOP: return;
// CPP-DECLTOP: }
func.func @emitc_switch_ui64() {
Expand Down