diff options
author | Dean Michael Berris <dberris@google.com> | 2016-12-19 09:20:38 +0000 |
---|---|---|
committer | Dean Michael Berris <dberris@google.com> | 2016-12-19 09:20:38 +0000 |
commit | 03b8be575e36f847387e314cfab75c2ae54e831f (patch) | |
tree | a80da5a149a05859b80e011ce10021f5c29acaa0 /llvm/lib/CodeGen/XRayInstrumentation.cpp | |
parent | ff8d61369b181ede3c313c85feb39e0a402d0e38 (diff) | |
download | bcm5719-llvm-03b8be575e36f847387e314cfab75c2ae54e831f.tar.gz bcm5719-llvm-03b8be575e36f847387e314cfab75c2ae54e831f.zip |
[XRay] Fix assertion failure on empty machine basic blocks (PR 31424)
The original version of the code in XRayInstrumentation.cpp assumed that
functions may not have empty machine basic blocks (or that the first one
couldn't be). This change addresses that by special-casing that specific
situation.
We provide two .mir test-cases to make sure we're handling this
appropriately.
Fixes llvm.org/PR31424.
Reviewers: chandlerc
Subscribers: varno, llvm-commits
Differential Revision: https://reviews.llvm.org/D27913
llvm-svn: 290091
Diffstat (limited to 'llvm/lib/CodeGen/XRayInstrumentation.cpp')
-rw-r--r-- | llvm/lib/CodeGen/XRayInstrumentation.cpp | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/llvm/lib/CodeGen/XRayInstrumentation.cpp b/llvm/lib/CodeGen/XRayInstrumentation.cpp index 570b2edc005..63bd762eeb2 100644 --- a/llvm/lib/CodeGen/XRayInstrumentation.cpp +++ b/llvm/lib/CodeGen/XRayInstrumentation.cpp @@ -129,7 +129,15 @@ bool XRayInstrumentation::runOnMachineFunction(MachineFunction &MF) { return false; // Function is too small. } - auto &FirstMBB = *MF.begin(); + // We look for the first non-empty MachineBasicBlock, so that we can insert + // the function instrumentation in the appropriate place. + auto MBI = + find_if(MF, [&](const MachineBasicBlock &MBB) { return !MBB.empty(); }); + if (MBI == MF.end()) + return false; // The function is empty. + + auto *TII = MF.getSubtarget().getInstrInfo(); + auto &FirstMBB = *MBI; auto &FirstMI = *FirstMBB.begin(); if (!MF.getSubtarget().isXRaySupported()) { @@ -142,7 +150,6 @@ bool XRayInstrumentation::runOnMachineFunction(MachineFunction &MF) { // First, insert an PATCHABLE_FUNCTION_ENTER as the first instruction of the // MachineFunction. - auto *TII = MF.getSubtarget().getInstrInfo(); BuildMI(FirstMBB, FirstMI, FirstMI.getDebugLoc(), TII->get(TargetOpcode::PATCHABLE_FUNCTION_ENTER)); |