Skip to content

[mlir][emitc] Fix the error with closing bracket in CppEmitter in switchOp #110269

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 10, 2024

Conversation

EtoAndruwa
Copy link
Contributor

While working with emitc::SwitchOp, it was identified that mlir-translate emits invalid C code for switch.
This commit fixes the issue with the closing bracket in CppEmitter within printOperation for emitc::SwitchOp.

@llvmbot
Copy link
Member

llvmbot commented Sep 27, 2024

@llvm/pr-subscribers-mlir-emitc

Author: Andrey Timonin (EtoAndruwa)

Changes

While working with emitc::SwitchOp, it was identified that mlir-translate emits invalid C code for switch.
This commit fixes the issue with the closing bracket in CppEmitter within printOperation for emitc::SwitchOp.


Full diff: https://github.com/llvm/llvm-project/pull/110269.diff

3 Files Affected:

  • (modified) mlir/include/mlir/Dialect/EmitC/IR/EmitC.td (+1)
  • (modified) mlir/lib/Target/Cpp/TranslateToCpp.cpp (+1-1)
  • (modified) mlir/test/Target/Cpp/switch.mlir (+28)
diff --git a/mlir/include/mlir/Dialect/EmitC/IR/EmitC.td b/mlir/include/mlir/Dialect/EmitC/IR/EmitC.td
index 2c1ac27cfb8ff8..7c84ab4dd39eb7 100644
--- a/mlir/include/mlir/Dialect/EmitC/IR/EmitC.td
+++ b/mlir/include/mlir/Dialect/EmitC/IR/EmitC.td
@@ -1405,6 +1405,7 @@ def EmitC_SwitchOp : EmitC_Op<"switch", [RecursiveMemoryEffects,
       func2(v4);
       break;
     }
+    }
     ```
   }];
 
diff --git a/mlir/lib/Target/Cpp/TranslateToCpp.cpp b/mlir/lib/Target/Cpp/TranslateToCpp.cpp
index 30657d8fccb154..d26adec500a113 100644
--- a/mlir/lib/Target/Cpp/TranslateToCpp.cpp
+++ b/mlir/lib/Target/Cpp/TranslateToCpp.cpp
@@ -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();
 }
 
diff --git a/mlir/test/Target/Cpp/switch.mlir b/mlir/test/Target/Cpp/switch.mlir
index f9b8600606ec2b..3339c026179492 100644
--- a/mlir/test/Target/Cpp/switch.mlir
+++ b/mlir/test/Target/Cpp/switch.mlir
@@ -17,6 +17,7 @@
 // CPP-DEFAULT:           func2(v4);
 // CPP-DEFAULT:           break;
 // CPP-DEFAULT:         }
+// CPP-DEFAULT:         }
 // CPP-DEFAULT:         return;
 // CPP-DEFAULT:       }
 
@@ -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() {
@@ -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:       }
 
@@ -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() {
@@ -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:       }
 
@@ -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() {
@@ -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:       }
 
@@ -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() {
@@ -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:       }
 
@@ -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() {
@@ -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:       }
 
@@ -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() {
@@ -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:       }
 
@@ -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() {
@@ -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:       }
 
@@ -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() {
@@ -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:       }
 
@@ -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() {
@@ -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:       }
 
@@ -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() {
@@ -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:       }
 
@@ -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() {
@@ -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:       }
 
@@ -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() {
@@ -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:       }
 
@@ -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() {
@@ -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:       }
 
@@ -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() {

@llvmbot
Copy link
Member

llvmbot commented Sep 27, 2024

@llvm/pr-subscribers-mlir

Author: Andrey Timonin (EtoAndruwa)

Changes

While working with emitc::SwitchOp, it was identified that mlir-translate emits invalid C code for switch.
This commit fixes the issue with the closing bracket in CppEmitter within printOperation for emitc::SwitchOp.


Full diff: https://github.com/llvm/llvm-project/pull/110269.diff

3 Files Affected:

  • (modified) mlir/include/mlir/Dialect/EmitC/IR/EmitC.td (+1)
  • (modified) mlir/lib/Target/Cpp/TranslateToCpp.cpp (+1-1)
  • (modified) mlir/test/Target/Cpp/switch.mlir (+28)
diff --git a/mlir/include/mlir/Dialect/EmitC/IR/EmitC.td b/mlir/include/mlir/Dialect/EmitC/IR/EmitC.td
index 2c1ac27cfb8ff8..7c84ab4dd39eb7 100644
--- a/mlir/include/mlir/Dialect/EmitC/IR/EmitC.td
+++ b/mlir/include/mlir/Dialect/EmitC/IR/EmitC.td
@@ -1405,6 +1405,7 @@ def EmitC_SwitchOp : EmitC_Op<"switch", [RecursiveMemoryEffects,
       func2(v4);
       break;
     }
+    }
     ```
   }];
 
diff --git a/mlir/lib/Target/Cpp/TranslateToCpp.cpp b/mlir/lib/Target/Cpp/TranslateToCpp.cpp
index 30657d8fccb154..d26adec500a113 100644
--- a/mlir/lib/Target/Cpp/TranslateToCpp.cpp
+++ b/mlir/lib/Target/Cpp/TranslateToCpp.cpp
@@ -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();
 }
 
diff --git a/mlir/test/Target/Cpp/switch.mlir b/mlir/test/Target/Cpp/switch.mlir
index f9b8600606ec2b..3339c026179492 100644
--- a/mlir/test/Target/Cpp/switch.mlir
+++ b/mlir/test/Target/Cpp/switch.mlir
@@ -17,6 +17,7 @@
 // CPP-DEFAULT:           func2(v4);
 // CPP-DEFAULT:           break;
 // CPP-DEFAULT:         }
+// CPP-DEFAULT:         }
 // CPP-DEFAULT:         return;
 // CPP-DEFAULT:       }
 
@@ -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() {
@@ -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:       }
 
@@ -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() {
@@ -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:       }
 
@@ -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() {
@@ -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:       }
 
@@ -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() {
@@ -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:       }
 
@@ -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() {
@@ -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:       }
 
@@ -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() {
@@ -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:       }
 
@@ -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() {
@@ -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:       }
 
@@ -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() {
@@ -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:       }
 
@@ -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() {
@@ -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:       }
 
@@ -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() {
@@ -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:       }
 
@@ -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() {
@@ -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:       }
 
@@ -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() {
@@ -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:       }
 
@@ -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() {
@@ -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:       }
 
@@ -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() {

@EtoAndruwa EtoAndruwa changed the title [mlir][emitc]: fix error with closing bracket in CppEmitter in switchOp [mlir][emitc] Fix error with closing bracket in CppEmitter in switchOp Sep 27, 2024
@EtoAndruwa EtoAndruwa changed the title [mlir][emitc] Fix error with closing bracket in CppEmitter in switchOp [mlir][emitc] Fix the error with closing bracket in CppEmitter in switchOp Sep 27, 2024
Copy link
Contributor

@simon-camp simon-camp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this.
Maybe we should use the raw_indented_ostream::DelimitedScope RAII helper to prevent such errors.

@EtoAndruwa
Copy link
Contributor Author

Thanks for fixing this. Maybe we should use the raw_indented_ostream::DelimitedScope RAII helper to prevent such errors.

Hi, @simon-camp! Thanks for the fast response. Should I try refactoring it using raw_indented_ostream::DelimitedScope, or will we fix it as is?

@simon-camp
Copy link
Contributor

I'd merge this fix as is. Switching to DelimitedScope can be done later as an NFC if anyone wants to do the refactoring.

Copy link
Member

@marbre marbre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix.

@EtoAndruwa
Copy link
Contributor Author

I will make some changes inside my git config for the merge. Sorry for that.

…tchOp

This commit fixed error with closing bracket in CppEmitter within printOperation for emitc::SwitchOp.
@EtoAndruwa
Copy link
Contributor Author

Hello, @marbre! Can you please merge this?

@EtoAndruwa EtoAndruwa requested a review from marbre October 10, 2024 10:33
@marbre marbre merged commit a1c9dd7 into llvm:main Oct 10, 2024
8 checks passed
@marbre
Copy link
Member

marbre commented Oct 10, 2024

Hello, @marbre! Can you please merge this?

Excuse the delay. Thanks for fixing this.

DanielCChen pushed a commit to DanielCChen/llvm-project that referenced this pull request Oct 16, 2024
…tchOp (llvm#110269)

While working with `emitc::SwitchOp`, it was identified that
`mlir-translate` emits **invalid C code** for switch.
This commit fixes the issue with the closing bracket in `CppEmitter`
within `printOperation` for `emitc::SwitchOp`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants