]> granicus.if.org Git - llvm/commitdiff
[x86/SLH] Fix a bug where we would harden tail calls twice -- once as
authorChandler Carruth <chandlerc@gmail.com>
Mon, 23 Jul 2018 07:56:15 +0000 (07:56 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Mon, 23 Jul 2018 07:56:15 +0000 (07:56 +0000)
a call, and then again as a return.

Also added a comment to try and explain better why we would be doing
what we're doing when hardening the (non-call) returns.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@337673 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/X86/X86SpeculativeLoadHardening.cpp
test/CodeGen/X86/speculative-load-hardening-indirect.ll

index c068507095a7d596a6bc87b520494b90c900e70c..3d2bbd3e55c981115309c4fd11971a4f37473442 100644 (file)
@@ -525,7 +525,11 @@ bool X86SpeculativeLoadHardeningPass::runOnMachineFunction(
         continue;
 
       MachineInstr &MI = MBB.back();
-      if (!MI.isReturn())
+
+      // We only care about returns that are not also calls. For calls, that
+      // happen to also be returns (tail calls) we will have already handled
+      // them as calls.
+      if (!MI.isReturn() || MI.isCall())
         continue;
 
       hardenReturnInstr(MI);
index b067c10a254c404ecf01dfec4d3f1ce62a07372b..33741ff7b759d1d2a2b148d652f74f7dc23bac90 100644 (file)
@@ -37,9 +37,6 @@ define i32 @test_indirect_tail_call(i32 ()** %ptr) nounwind {
 ; X64-NEXT:    movq %rsp, %rax
 ; X64-NEXT:    movq $-1, %rcx
 ; X64-NEXT:    sarq $63, %rax
-; X64-NEXT:    movq %rax, %rcx
-; X64-NEXT:    shlq $47, %rcx
-; X64-NEXT:    orq %rcx, %rsp
 ; X64-NEXT:    shlq $47, %rax
 ; X64-NEXT:    orq %rax, %rsp
 ; X64-NEXT:    jmpq *(%rdi) # TAILCALL
@@ -77,9 +74,6 @@ define i32 @test_indirect_tail_call_global() nounwind {
 ; X64-NEXT:    movq %rsp, %rax
 ; X64-NEXT:    movq $-1, %rcx
 ; X64-NEXT:    sarq $63, %rax
-; X64-NEXT:    movq %rax, %rcx
-; X64-NEXT:    shlq $47, %rcx
-; X64-NEXT:    orq %rcx, %rsp
 ; X64-NEXT:    shlq $47, %rax
 ; X64-NEXT:    orq %rax, %rsp
 ; X64-NEXT:    jmpq *{{.*}}(%rip) # TAILCALL