diff options
author | Andrew Kaylor <andrew.kaylor@intel.com> | 2019-06-03 17:54:15 +0000 |
---|---|---|
committer | Andrew Kaylor <andrew.kaylor@intel.com> | 2019-06-03 17:54:15 +0000 |
commit | 4172dbab5dd3dffa8717e090e1912fce598d1a77 (patch) | |
tree | 1315f7d375e077678980496efacafe428cde3475 /llvm/lib/Transforms/Utils/LowerSwitch.cpp | |
parent | 83645d214d4d506945efa120a19e88d0ad4f0163 (diff) | |
download | bcm5719-llvm-4172dbab5dd3dffa8717e090e1912fce598d1a77.tar.gz bcm5719-llvm-4172dbab5dd3dffa8717e090e1912fce598d1a77.zip |
Fix a crash when the default of a switch is removed
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.
Differential Revision: https://reviews.llvm.org/D62560
llvm-svn: 362427
Diffstat (limited to 'llvm/lib/Transforms/Utils/LowerSwitch.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/LowerSwitch.cpp | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Utils/LowerSwitch.cpp b/llvm/lib/Transforms/Utils/LowerSwitch.cpp index 680b5d31a42..8062fe49908 100644 --- a/llvm/lib/Transforms/Utils/LowerSwitch.cpp +++ b/llvm/lib/Transforms/Utils/LowerSwitch.cpp @@ -584,6 +584,11 @@ void LowerSwitch::processSwitchInst(SwitchInst *SI, PopSucc->removePredecessor(OrigBlock); return; } + + // If the condition was a PHI node with the switch block as a predecessor + // removing predecessors may have caused the condition to be erased. + // Getting the condition value again here protects against that. + Val = SI->getCondition(); } // Create a new, empty default block so that the new hierarchy of |