This is an archive of the discontinued LLVM Phabricator instance.

Fix a crash when the default of a switch is removed
ClosedPublic

Authored by andrew.w.kaylor on May 28 2019, 5:13 PM.

Details

Summary

This patch fixes a problem that occurs in LowerSwitch when a switch statement has a PHI node as its condition, and the PHI node only has two incoming blocks, and one of those incoming blocks is through an unreachable default in the switch statement. When this condition occurs, LowerSwitch holds a pointer to the condition value, but removes the switch block as a predecessor of the PHI block, causing the PHI node to be replaced. LowerSwitch then tries to use its stale pointer to the original condition value, causing a crash.

Diff Detail

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptMay 28 2019, 5:13 PM
karka added a comment.May 29 2019, 1:58 PM

The fix LGTM (with the minor comment about the testcase).

test/Transforms/LowerSwitch/condition-phi-unreachable-default.ll
2

I think that it make sense to always check that the output is sane with FileCheck even if the testcase only should demonstrate that the code don't crash. Do you mind adding "-S | FileCheck %s" (instead of -disable-output) to the command line and add a few checks?

Updated test case

karka accepted this revision.May 29 2019, 2:50 PM

LGTM. I set this "ready to land", but maybe you should wait a bit before landing this to see if anyone else have comments.

This revision is now accepted and ready to land.May 29 2019, 2:50 PM
This revision was automatically updated to reflect the committed changes.