Skip to content

Commit d6fd2da

Browse files
Apply requested reviews
1 parent 89404b5 commit d6fd2da

File tree

5 files changed

+59
-8
lines changed

5 files changed

+59
-8
lines changed

clang/include/clang/CIR/Dialect/IR/CIROps.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1064,7 +1064,8 @@ def CIR_BrOp : CIR_Op<"br",[
10641064
// LabelOp
10651065
//===----------------------------------------------------------------------===//
10661066

1067-
// The LabelOp has AlwaysSpeculatable trait in order to not to be swept by canonicalizer
1067+
// The LabelOp has AlwaysSpeculatable trait in order to not to be swept
1068+
// by canonicalizer
10681069
def CIR_LabelOp : CIR_Op<"label", [AlwaysSpeculatable]> {
10691070
let description = [{
10701071
An identifier which may be referred by cir.goto operation

clang/lib/CIR/CodeGen/CIRGenFunction.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1125,7 +1125,7 @@ class CIRGenFunction : public CIRGenTypeCache {
11251125

11261126
mlir::Value emitOpOnBoolExpr(mlir::Location loc, const clang::Expr *cond);
11271127

1128-
mlir::LogicalResult emitLabel(const clang::LabelDecl *d);
1128+
mlir::LogicalResult emitLabel(const clang::LabelDecl &d);
11291129
mlir::LogicalResult emitLabelStmt(const clang::LabelStmt &s);
11301130

11311131
mlir::LogicalResult emitIfStmt(const clang::IfStmt &s);

clang/lib/CIR/CodeGen/CIRGenStmt.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -277,11 +277,11 @@ mlir::LogicalResult CIRGenFunction::emitSimpleStmt(const Stmt *s,
277277

278278
mlir::LogicalResult CIRGenFunction::emitLabelStmt(const clang::LabelStmt &s) {
279279

280-
if (emitLabel(s.getDecl()).failed())
280+
if (emitLabel(*s.getDecl()).failed())
281281
return mlir::failure();
282282

283-
// IsEHa: not implemented.
284-
assert(!(getContext().getLangOpts().EHAsynch && s.isSideEntry()));
283+
if (getContext().getLangOpts().EHAsynch && s.isSideEntry())
284+
getCIRGenModule().errorNYI(s.getSourceRange(), "IsEHa: not implemented.");
285285

286286
return emitStmt(s.getSubStmt(), /*useCurrentScope*/ true);
287287
}
@@ -443,7 +443,7 @@ CIRGenFunction::emitContinueStmt(const clang::ContinueStmt &s) {
443443
return mlir::success();
444444
}
445445

446-
mlir::LogicalResult CIRGenFunction::emitLabel(const clang::LabelDecl *d) {
446+
mlir::LogicalResult CIRGenFunction::emitLabel(const clang::LabelDecl &d) {
447447
// Create a new block to tag with a label and add a branch from
448448
// the current one to it. If the block is empty just call attach it
449449
// to this label.
@@ -455,11 +455,11 @@ mlir::LogicalResult CIRGenFunction::emitLabel(const clang::LabelDecl *d) {
455455
mlir::OpBuilder::InsertionGuard guard(builder);
456456
labelBlock = builder.createBlock(builder.getBlock()->getParent());
457457
}
458-
builder.create<cir::BrOp>(getLoc(d->getSourceRange()), labelBlock);
458+
builder.create<cir::BrOp>(getLoc(d.getSourceRange()), labelBlock);
459459
}
460460

461461
builder.setInsertionPointToEnd(labelBlock);
462-
builder.create<cir::LabelOp>(getLoc(d->getSourceRange()), d->getName());
462+
builder.create<cir::LabelOp>(getLoc(d.getSourceRange()), d.getName());
463463
builder.setInsertionPointToEnd(labelBlock);
464464

465465
// FIXME: emit debug info for labels, incrementProfileCounter

clang/test/CIR/CodeGen/label.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ void label() {
1212
// CIR: cir.label "labelA"
1313
// CIR: cir.return
1414

15+
// Note: We are not lowering to LLVM IR via CIR at this stage because that
16+
// process depends on the GotoSolver.
17+
1518
// OGCG: define dso_local void @label
1619
// OGCG: br label %labelA
1720
// OGCG: labelA:
@@ -63,3 +66,38 @@ void label_in_if(int cond) {
6366
// OGCG: br label %if.end
6467
// OGCG: if.end:
6568
// OGCG: ret void
69+
70+
void after_return() {
71+
return;
72+
label:
73+
}
74+
75+
// CIR: cir.func no_proto dso_local @after_return
76+
// CIR: cir.br ^bb1
77+
// CIR: ^bb1: // 2 preds: ^bb0, ^bb2
78+
// CIR: cir.return
79+
// CIR: ^bb2: // no predecessors
80+
// CIR: cir.label "label"
81+
// CIR: cir.br ^bb1
82+
83+
// OGCG: define dso_local void @after_return
84+
// OGCG: br label %label
85+
// OGCG: label:
86+
// OGCG: ret void
87+
88+
89+
void after_unreachable() {
90+
__builtin_unreachable();
91+
label:
92+
}
93+
94+
// CIR: cir.func no_proto dso_local @after_unreachable
95+
// CIR: cir.unreachable
96+
// CIR: ^bb1:
97+
// CIR: cir.label "label"
98+
// CIR: cir.return
99+
100+
// OGCG: define dso_local void @after_unreachable
101+
// OGCG: unreachable
102+
// OGCG: label:
103+
// OGCG: ret void
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: cir-opt %s -verify-diagnostics -split-input-file
2+
3+
!s32i = !cir.int<s, 32>
4+
5+
module {
6+
// expected-error@+3 {{must be the first operation in a block}}
7+
cir.func @error(){
8+
%0 = cir.const #cir.int<0> : !s32i
9+
cir.label "label"
10+
cir.return
11+
}
12+
}

0 commit comments

Comments
 (0)