[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 10:32:05 PDT 2017


manojgupta updated this revision to Diff 108677.
manojgupta removed a reviewer: dblaikie.
manojgupta added a comment.

Linux kernel is still WIP.

Added back the DebugLoc from first instruction. I am not sure though if reusing
debug location from an unrelated instruction is ok.


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,19 @@
 ; CHECK: retq
 }
 
-attributes #0 = { "fentry-call"="true" }
+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
+}
+
+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,11 +41,15 @@
     return false;
 
   auto &FirstMBB = *MF.begin();
-  auto &FirstMI = *FirstMBB.begin();
-
   auto *TII = MF.getSubtarget().getInstrInfo();
-  BuildMI(FirstMBB, FirstMI, FirstMI.getDebugLoc(),
-          TII->get(TargetOpcode::FENTRY_CALL));
+  if (FirstMBB.empty()) {
+    BuildMI(FirstMBB, FirstMBB.begin(), DebugLoc(),
+            TII->get(TargetOpcode::FENTRY_CALL));
+  } else {
+    auto &FirstMI = *FirstMBB.begin();
+    BuildMI(FirstMBB, FirstMI, FirstMI.getDebugLoc(),
+            TII->get(TargetOpcode::FENTRY_CALL));
+  }
   return true;
 }
 


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


More information about the llvm-commits mailing list