Skip to content

Commit 1a1698b

Browse files
authored
[CIR] Handle NullStmt (#134889)
The handling for NullStmt was going to an error saying the statement handling wasn't implemented. It doesn't need any implementation. It is sufficient for emitSimpleStmt to just return success for that statement class. This change does that.
1 parent a6853cd commit 1a1698b

File tree

2 files changed

+66
-6
lines changed

2 files changed

+66
-6
lines changed

clang/lib/CIR/CodeGen/CIRGenStmt.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,14 @@ mlir::LogicalResult CIRGenFunction::emitStmt(const Stmt *s,
5757
return mlir::success();
5858

5959
switch (s->getStmtClass()) {
60+
case Stmt::NoStmtClass:
61+
case Stmt::CXXCatchStmtClass:
62+
case Stmt::SEHExceptStmtClass:
63+
case Stmt::SEHFinallyStmtClass:
64+
case Stmt::MSDependentExistsStmtClass:
65+
llvm_unreachable("invalid statement class to emit generically");
6066
case Stmt::BreakStmtClass:
67+
case Stmt::NullStmtClass:
6168
case Stmt::CompoundStmtClass:
6269
case Stmt::ContinueStmtClass:
6370
case Stmt::DeclStmtClass:
@@ -116,12 +123,6 @@ mlir::LogicalResult CIRGenFunction::emitStmt(const Stmt *s,
116123
return emitOpenACCAtomicConstruct(cast<OpenACCAtomicConstruct>(*s));
117124
case Stmt::OMPScopeDirectiveClass:
118125
case Stmt::OMPErrorDirectiveClass:
119-
case Stmt::NoStmtClass:
120-
case Stmt::CXXCatchStmtClass:
121-
case Stmt::SEHExceptStmtClass:
122-
case Stmt::SEHFinallyStmtClass:
123-
case Stmt::MSDependentExistsStmtClass:
124-
case Stmt::NullStmtClass:
125126
case Stmt::LabelStmtClass:
126127
case Stmt::AttributedStmtClass:
127128
case Stmt::GotoStmtClass:
@@ -245,6 +246,11 @@ mlir::LogicalResult CIRGenFunction::emitSimpleStmt(const Stmt *s,
245246
break;
246247
case Stmt::ContinueStmtClass:
247248
return emitContinueStmt(cast<ContinueStmt>(*s));
249+
250+
// NullStmt doesn't need any handling, but we need to say we handled it.
251+
case Stmt::NullStmtClass:
252+
break;
253+
248254
case Stmt::BreakStmtClass:
249255
return emitBreakStmt(cast<BreakStmt>(*s));
250256
case Stmt::ReturnStmtClass:

clang/test/CIR/CodeGen/basic.c

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,57 @@ int f3(void) {
9090
// OGCG-NEXT: store i32 3, ptr %[[I_PTR]], align 4
9191
// OGCG-NEXT: %[[I:.*]] = load i32, ptr %[[I_PTR]], align 4
9292
// OGCG-NEXT: ret i32 %[[I]]
93+
94+
// Verify null statement handling.
95+
void f4(void) {
96+
;
97+
}
98+
99+
// CIR: cir.func @f4()
100+
// CIR-NEXT: cir.return
101+
102+
// LLVM: define void @f4()
103+
// LLVM-NEXT: ret void
104+
105+
// OGCG: define{{.*}} void @f4()
106+
// OGCG-NEXT: entry:
107+
// OGCG-NEXT: ret void
108+
109+
// Verify null statement as for-loop body.
110+
void f5(void) {
111+
for (;;)
112+
;
113+
}
114+
115+
// CIR: cir.func @f5()
116+
// CIR-NEXT: cir.scope {
117+
// CIR-NEXT: cir.for : cond {
118+
// CIR-NEXT: %0 = cir.const #true
119+
// CIR-NEXT: cir.condition(%0)
120+
// CIR-NEXT: } body {
121+
// CIR-NEXT: cir.yield
122+
// CIR-NEXT: } step {
123+
// CIR-NEXT: cir.yield
124+
// CIR-NEXT: }
125+
// CIR-NEXT: }
126+
// CIR-NEXT: cir.return
127+
// CIR-NEXT: }
128+
129+
// LLVM: define void @f5()
130+
// LLVM: br label %[[SCOPE:.*]]
131+
// LLVM: [[SCOPE]]:
132+
// LLVM: br label %[[LOOP:.*]]
133+
// LLVM: [[LOOP]]:
134+
// LLVM: br i1 true, label %[[LOOP_STEP:.*]], label %[[LOOP_EXIT:.*]]
135+
// LLVM: [[LOOP_STEP]]:
136+
// LLVM: br label %[[LOOP_BODY:.*]]
137+
// LLVM: [[LOOP_BODY]]:
138+
// LLVM: br label %[[LOOP]]
139+
// LLVM: [[LOOP_EXIT]]:
140+
// LLVM: ret void
141+
142+
// OGCG: define{{.*}} void @f5()
143+
// OGCG: entry:
144+
// OGCG: br label %[[LOOP:.*]]
145+
// OGCG: [[LOOP]]:
146+
// OGCG: br label %[[LOOP]]

0 commit comments

Comments
 (0)