Because of shrink wrapping, the block to insert epilog may don't have
instructions (Only debug instructions). And the position to insert may
point to MBB.end() that don't have a DebugLoc. This patch fix this
problem.
The test program was copied from the issue:https://github.com/llvm/llvm-project/issues/53662
It's also best practice to check at least one line of output to ensure that what you want to happen, actually happened. That ensures the test doesn't spuriously pass in the future. An example would be if the IR Verifier was tightened to reject the debug-info in this file, it would load and compile this IR and pass the test, but the scenario you're testing wouldn't be covered.
Adding a CHECK line, for example stopping after prologepilog and checking the relevant block has the right contents, would prevent that.