This is an archive of the discontinued LLVM Phabricator instance.

[CodeGen] Fix a crash on valid when constant folding 'default:' statement in switch
ClosedPublic

Authored by erik.pilkington on Jul 19 2016, 3:15 PM.

Details

Summary

The following valid code crashes Clang in CodeGen:

void other_test() {
  switch(0) {
  case 0:
    do {
    default:;
    } while(0);
  }
}

The problem is that when we constant fold the switch into the case 0: case, the default: attempts to find the enclosing switch it is attached to, which does not exist. The solution is to ignore the default and emit it's child statement. (Which is the exact same solution as in the case statement, in EmitCaseStmt just above this)

Fixes PR28609.

Diff Detail

Repository
rL LLVM

Event Timeline

erik.pilkington retitled this revision from to [CodeGen] Fix a crash on valid when constant folding 'default:' statement in switch.
erik.pilkington updated this object.
erik.pilkington added reviewers: rsmith, manmanren.
erik.pilkington added a subscriber: cfe-commits.
manmanren accepted this revision.Jul 21 2016, 1:57 PM
manmanren edited edge metadata.

LGTM.

Manman

This revision is now accepted and ready to land.Jul 21 2016, 1:57 PM
This revision was automatically updated to reflect the committed changes.