Skip to content
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

[CIR][CodeGen] Handle the case of 'case' after label statement after 'case' #879

Merged
merged 2 commits into from
Sep 25, 2024

Conversation

ChuanqiXu9
Copy link
Member

Motivation example:

extern "C" void action1();
extern "C" void action2();

extern "C" void case_follow_label(int v) {
  switch (v) {
    case 1:
    label:
    case 2:
      action1();
      break;
    default:
      action2();
      goto label;
  }
}

When we compile it, we will meet:

  case Stmt::CaseStmtClass:
  case Stmt::DefaultStmtClass:
    assert(0 &&
           "Should not get here, currently handled directly from SwitchStmt");
    break;

in buildStmt. The cause is clear. We call buildStmt when we build the label stmt.

To solve this, I think we should be able to build case stmt in buildStmt. But the new problem is, we need to pass the information like caseAttr and condType. So I tried to add such informations in CIRGenFunction as data member.

@ChuanqiXu9 ChuanqiXu9 requested review from gitoleg, bcardosolopes and lanza and removed request for bcardosolopes and lanza September 24, 2024 09:57
@bcardosolopes bcardosolopes changed the title [CIR] [CodeGen] handle the case of 'case' after label statement after 'case' [CIR][CodeGen] Handle the case of 'case' after label statement after 'case' Sep 24, 2024
@bcardosolopes
Copy link
Member

Similar to #528

Copy link
Member

@bcardosolopes bcardosolopes left a comment

Choose a reason for hiding this comment

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

It's really great to see improvements here, thanks a bunch! Comments inline

Copy link
Member

@bcardosolopes bcardosolopes left a comment

Choose a reason for hiding this comment

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

Awesome, LGTM

@bcardosolopes bcardosolopes merged commit 8710834 into llvm:main Sep 25, 2024
6 checks passed
Hugobros3 pushed a commit to shady-gang/clangir that referenced this pull request Oct 2, 2024
…'case' (llvm#879)

Motivation example:

```
extern "C" void action1();
extern "C" void action2();

extern "C" void case_follow_label(int v) {
  switch (v) {
    case 1:
    label:
    case 2:
      action1();
      break;
    default:
      action2();
      goto label;
  }
}
```

When we compile it, we will meet:

```
  case Stmt::CaseStmtClass:
  case Stmt::DefaultStmtClass:
    assert(0 &&
           "Should not get here, currently handled directly from SwitchStmt");
    break;
```

in `buildStmt`. The cause is clear. We call `buildStmt` when we build
the label stmt.

To solve this, I think we should be able to build case stmt in
buildStmt. But the new problem is, we need to pass the information like
caseAttr and condType. So I tried to add such informations in
CIRGenFunction as data member.
smeenai pushed a commit to smeenai/clangir that referenced this pull request Oct 9, 2024
…'case' (llvm#879)

Motivation example:

```
extern "C" void action1();
extern "C" void action2();

extern "C" void case_follow_label(int v) {
  switch (v) {
    case 1:
    label:
    case 2:
      action1();
      break;
    default:
      action2();
      goto label;
  }
}
```

When we compile it, we will meet:

```
  case Stmt::CaseStmtClass:
  case Stmt::DefaultStmtClass:
    assert(0 &&
           "Should not get here, currently handled directly from SwitchStmt");
    break;
```

in `buildStmt`. The cause is clear. We call `buildStmt` when we build
the label stmt.

To solve this, I think we should be able to build case stmt in
buildStmt. But the new problem is, we need to pass the information like
caseAttr and condType. So I tried to add such informations in
CIRGenFunction as data member.
smeenai pushed a commit to smeenai/clangir that referenced this pull request Oct 9, 2024
…'case' (llvm#879)

Motivation example:

```
extern "C" void action1();
extern "C" void action2();

extern "C" void case_follow_label(int v) {
  switch (v) {
    case 1:
    label:
    case 2:
      action1();
      break;
    default:
      action2();
      goto label;
  }
}
```

When we compile it, we will meet:

```
  case Stmt::CaseStmtClass:
  case Stmt::DefaultStmtClass:
    assert(0 &&
           "Should not get here, currently handled directly from SwitchStmt");
    break;
```

in `buildStmt`. The cause is clear. We call `buildStmt` when we build
the label stmt.

To solve this, I think we should be able to build case stmt in
buildStmt. But the new problem is, we need to pass the information like
caseAttr and condType. So I tried to add such informations in
CIRGenFunction as data member.
smeenai pushed a commit to smeenai/clangir that referenced this pull request Oct 9, 2024
…'case' (llvm#879)

Motivation example:

```
extern "C" void action1();
extern "C" void action2();

extern "C" void case_follow_label(int v) {
  switch (v) {
    case 1:
    label:
    case 2:
      action1();
      break;
    default:
      action2();
      goto label;
  }
}
```

When we compile it, we will meet:

```
  case Stmt::CaseStmtClass:
  case Stmt::DefaultStmtClass:
    assert(0 &&
           "Should not get here, currently handled directly from SwitchStmt");
    break;
```

in `buildStmt`. The cause is clear. We call `buildStmt` when we build
the label stmt.

To solve this, I think we should be able to build case stmt in
buildStmt. But the new problem is, we need to pass the information like
caseAttr and condType. So I tried to add such informations in
CIRGenFunction as data member.
keryell pushed a commit to keryell/clangir that referenced this pull request Oct 19, 2024
…'case' (llvm#879)

Motivation example:

```
extern "C" void action1();
extern "C" void action2();

extern "C" void case_follow_label(int v) {
  switch (v) {
    case 1:
    label:
    case 2:
      action1();
      break;
    default:
      action2();
      goto label;
  }
}
```

When we compile it, we will meet:

```
  case Stmt::CaseStmtClass:
  case Stmt::DefaultStmtClass:
    assert(0 &&
           "Should not get here, currently handled directly from SwitchStmt");
    break;
```

in `buildStmt`. The cause is clear. We call `buildStmt` when we build
the label stmt.

To solve this, I think we should be able to build case stmt in
buildStmt. But the new problem is, we need to pass the information like
caseAttr and condType. So I tried to add such informations in
CIRGenFunction as data member.
lanza pushed a commit that referenced this pull request Nov 5, 2024
…'case' (#879)

Motivation example:

```
extern "C" void action1();
extern "C" void action2();

extern "C" void case_follow_label(int v) {
  switch (v) {
    case 1:
    label:
    case 2:
      action1();
      break;
    default:
      action2();
      goto label;
  }
}
```

When we compile it, we will meet:

```
  case Stmt::CaseStmtClass:
  case Stmt::DefaultStmtClass:
    assert(0 &&
           "Should not get here, currently handled directly from SwitchStmt");
    break;
```

in `buildStmt`. The cause is clear. We call `buildStmt` when we build
the label stmt.

To solve this, I think we should be able to build case stmt in
buildStmt. But the new problem is, we need to pass the information like
caseAttr and condType. So I tried to add such informations in
CIRGenFunction as data member.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants