diff options
| author | 2025-12-13 17:04:33 +0100 | |
|---|---|---|
| committer | 2025-12-13 17:04:33 +0100 | |
| commit | fc7048a0c4c4b9647f032edfba74f7d7a62335e1 (patch) | |
| tree | 43f65798319af86372907370641ca7a4e55245ab /c/c.c | |
| parent | 0266cfecae0832afd0dc6f97ae5a60214afd8f26 (diff) | |
c: case/default labels only create new blocks when necessary
Diffstat (limited to 'c/c.c')
| -rw-r--r-- | c/c.c | 18 |
1 files changed, 11 insertions, 7 deletions
@@ -3816,21 +3816,25 @@ stmt(struct comp *cm, struct function *fn) warn(&ex.span, "overflow converting case value to switch condition type"); } expect(cm, ':', NULL); - begin = newblk(fn); - EMITS putbranch(fn, begin); - useblk(fn, begin); + if (!fn->curblk || (fn->curblk->phi.n > 0 || fn->curblk->ins.n > 0)) { + begin = newblk(fn); + EMITS putbranch(fn, begin); + useblk(fn, begin); + } if (cm->switchstmt) vpush(&cm->switchstmt->cases, ((struct swcase) {ex.i, fn->curblk, ex.span})); } else if (tk.t == TKWdefault) { /* default ':' */ if (!cm->switchstmt) error(&tk.span, "'default' outside of switch statement"); expect(cm, ':', NULL); - begin = newblk(fn); - EMITS putbranch(fn, begin); - useblk(fn, begin); + if (!fn->curblk || (fn->curblk->phi.n > 0 || fn->curblk->ins.n > 0)) { + begin = newblk(fn); + EMITS putbranch(fn, begin); + useblk(fn, begin); + } if (cm->switchstmt) { if (cm->switchstmt->bdefault) error(&tk.span, "multiple 'default' labels in one switch"); - cm->switchstmt->bdefault = begin; + cm->switchstmt->bdefault = fn->curblk; } } else if (tk.t == TKIDENT && match(cm, NULL, ':')) { /* <label> ':' */ |