Skip to content
Open
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
4 changes: 3 additions & 1 deletion clang/include/clang/CIR/Dialect/IR/CIROps.td
Original file line number Diff line number Diff line change
Expand Up @@ -1216,7 +1216,8 @@ def CIR_SwitchOp : CIR_Op<"switch", [

let arguments = (ins
CIR_IntType:$condition,
UnitAttr:$allEnumCasesCovered
UnitAttr:$allEnumCasesCovered,
UnitAttr:$handling_enum
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
UnitAttr:$handling_enum
UnitAttr:$is_enum

Copy link
Member

Choose a reason for hiding this comment

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

Another nit here: stick to one of the styles, the previous arg is using camelCase, the new one isn't.

);

let regions = (region AnyRegion:$body);
Expand All @@ -1230,6 +1231,7 @@ def CIR_SwitchOp : CIR_Op<"switch", [
let assemblyFormat = [{
`(` $condition `:` qualified(type($condition)) `)`
(`allEnumCasesCovered` $allEnumCasesCovered^)?
(`handling_enum` $handling_enum^)?
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
(`handling_enum` $handling_enum^)?
(`enum` $is_enum^)?

$body
attr-dict
}];
Expand Down
1 change: 1 addition & 0 deletions clang/lib/CIR/CodeGen/CIRGenStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1106,6 +1106,7 @@ mlir::LogicalResult CIRGenFunction::emitSwitchStmt(const clang::SwitchStmt &s) {
terminateBody(builder, caseOp.getCaseRegion(), caseOp.getLoc());
terminateBody(builder, swop.getBody(), swop.getLoc());

swop.setHandlingEnum(s.getCond()->IgnoreParenImpCasts()->getType()->isEnumeralType());
Copy link
Member

Choose a reason for hiding this comment

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

Assuming s.isAllEnumCasesCovered() implies this is an enum, the type should be isEnumeralType everytime that returns true? Might be worth adding an assert here in case somehow they differ

swop.setAllEnumCasesCovered(s.isAllEnumCasesCovered());

return res;
Expand Down
4 changes: 2 additions & 2 deletions clang/test/CIR/CodeGen/switch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1282,7 +1282,7 @@ void testSwitchCoverAllCase(M m) {
break;
}
}
// CIR: cir.switch(%[[ARG:.*]] : !s32i) allEnumCasesCovered {
// CIR: cir.switch(%[[ARG:.*]] : !s32i) allEnumCasesCovered handling_enum {
Copy link
Member

Choose a reason for hiding this comment

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

it feels a bit off that this reads as "all enum cases are covered and this is also an enum", should the first just be allCasesCovered as part of this change?

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe this is not rebased on on master where there are already all_enum_cases_covered.
Cannot we make this single enum attribute since all_enum_cases_covered already implies it is handling enum?


void testSwitchNotCoverAllCase(M m) {
switch (m) {
Expand All @@ -1291,4 +1291,4 @@ void testSwitchNotCoverAllCase(M m) {
break;
}
}
// CIR: cir.switch(%[[ARG:.*]] : !s32i) {
// CIR: cir.switch(%[[ARG:.*]] : !s32i) handling_enum {
Loading