[PATCH] D35979: [X86] Fix a crash in FEntryInserter Pass.

Manoj Gupta via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 28 00:34:39 PDT 2017


manojgupta created this revision.

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.


https://reviews.llvm.org/D35979

Files:
  lib/CodeGen/FEntryInserter.cpp
  test/CodeGen/X86/fentry-insertion.ll


Index: test/CodeGen/X86/fentry-insertion.ll
===================================================================
--- test/CodeGen/X86/fentry-insertion.ll
+++ test/CodeGen/X86/fentry-insertion.ll
@@ -12,5 +12,21 @@
 ; CHECK: retq
 }
 
-attributes #0 = { "fentry-call"="true" }
+; Function Attrs: inlinehint minsize noredzone nounwind optsize sspstrong
+define void @test2() #1 {
+entry:
+  br label %bb1
+bb1:
+  call void @address_taken(i64 ptrtoint (i8* blockaddress(@test2, %bb1) to i64), i32 512)
+  ret void
 
+; CHECK-LABEL: @test2
+; CHECK: callq __fentry__
+; CHECK-NOT: mcount
+; CHECK: retq
+}
+
+; Function Attrs: minsize noredzone optsize
+declare void @address_taken(i64, i32) local_unnamed_addr
+attributes #0 = { "fentry-call"="true" }
+attributes #1 = { inlinehint minsize noredzone nounwind optsize sspstrong "fentry-call"="true" }
Index: lib/CodeGen/FEntryInserter.cpp
===================================================================
--- lib/CodeGen/FEntryInserter.cpp
+++ lib/CodeGen/FEntryInserter.cpp
@@ -41,10 +41,9 @@
     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;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D35979.108595.patch
Type: text/x-patch
Size: 1357 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170728/6317b198/attachment.bin>


More information about the llvm-commits mailing list