[X86] Fix a crash in FEntryInserter Pass.

Summary:
FEntryInserter pass unconditionally derefs the first Instruction
in the first Basic Block. The pass crashes when the first
BasicBlock is empty. Fix the crash by not dereferencing the basic
Block iterator. This fixes an issue observed when building Linux kernel
4.4 with clang.

Fixes PR33971.

Reviewers: hfinkel, niravd, dblaikie

Reviewed By: niravd

Subscribers: davide, llvm-commits

Differential Revision: https://reviews.llvm.org/D35979

llvm-svn: 309694
This commit is contained in:
Manoj Gupta
2017-08-01 15:39:12 +00:00
parent 2462a713ae
commit 7ebbe655ed
2 changed files with 16 additions and 4 deletions

View File

@@ -41,10 +41,8 @@ bool FEntryInserter::runOnMachineFunction(MachineFunction &MF) {
return false;
auto &FirstMBB = *MF.begin();
auto &FirstMI = *FirstMBB.begin();
auto *TII = MF.getSubtarget().getInstrInfo();
BuildMI(FirstMBB, FirstMI, FirstMI.getDebugLoc(),
BuildMI(FirstMBB, FirstMBB.begin(), DebugLoc(),
TII->get(TargetOpcode::FENTRY_CALL));
return true;
}