@@ -256,6 +256,9 @@ mlir::LogicalResult CIRGenFunction::emitSimpleStmt(const Stmt *s,
256256 // NullStmt doesn't need any handling, but we need to say we handled it.
257257 case Stmt::NullStmtClass:
258258 break ;
259+
260+ case Stmt::LabelStmtClass:
261+ return emitLabelStmt (cast<LabelStmt>(*s));
259262 case Stmt::CaseStmtClass:
260263 case Stmt::DefaultStmtClass:
261264 // If we reached here, we must not handling a switch case in the top level.
@@ -272,6 +275,17 @@ mlir::LogicalResult CIRGenFunction::emitSimpleStmt(const Stmt *s,
272275 return mlir::success ();
273276}
274277
278+ mlir::LogicalResult CIRGenFunction::emitLabelStmt (const clang::LabelStmt &s) {
279+
280+ if (emitLabel (s.getDecl ()).failed ())
281+ return mlir::failure ();
282+
283+ // IsEHa: not implemented.
284+ assert (!(getContext ().getLangOpts ().EHAsynch && s.isSideEntry ()));
285+
286+ return emitStmt (s.getSubStmt (), /* useCurrentScope*/ true );
287+ }
288+
275289// Add a terminating yield on a body region if no other terminators are used.
276290static void terminateBody (CIRGenBuilderTy &builder, mlir::Region &r,
277291 mlir::Location loc) {
@@ -429,6 +443,32 @@ CIRGenFunction::emitContinueStmt(const clang::ContinueStmt &s) {
429443 return mlir::success ();
430444}
431445
446+ mlir::LogicalResult CIRGenFunction::emitLabel (const clang::LabelDecl *d) {
447+ // Create a new block to tag with a label and add a branch from
448+ // the current one to it. If the block is empty just call attach it
449+ // to this label.
450+ mlir::Block *currBlock = builder.getBlock ();
451+ mlir::Block *labelBlock = currBlock;
452+
453+ if (!currBlock->empty ()) {
454+ {
455+ mlir::OpBuilder::InsertionGuard guard (builder);
456+ labelBlock = builder.createBlock (builder.getBlock ()->getParent ());
457+ }
458+ builder.create <cir::BrOp>(getLoc (d->getSourceRange ()), labelBlock);
459+ }
460+
461+ builder.setInsertionPointToEnd (labelBlock);
462+ builder.create <cir::LabelOp>(getLoc (d->getSourceRange ()), d->getName ());
463+ builder.setInsertionPointToEnd (labelBlock);
464+
465+ // FIXME: emit debug info for labels, incrementProfileCounter
466+ assert (!cir::MissingFeatures::ehstackBranches ());
467+ assert (!cir::MissingFeatures::incrementProfileCounter ());
468+ assert (!cir::MissingFeatures::generateDebugInfo ());
469+ return mlir::success ();
470+ }
471+
432472mlir::LogicalResult CIRGenFunction::emitBreakStmt (const clang::BreakStmt &s) {
433473 builder.createBreak (getLoc (s.getBreakLoc ()));
434474
0 commit comments