[clang] [llvm] [X86][CodeGen] security check cookie execute only when needed (PR #95904)

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 27 03:24:48 PDT 2024


================
@@ -114,250 +25,93 @@ return:    ; preds = %entry
 declare void @escape(ptr)
 
 define void @test_vla(i32 %n) nounwind ssp {
-; MSVC-X86-LABEL: test_vla:
-; MSVC-X86:       # %bb.0:
-; MSVC-X86-NEXT:    pushl %ebp
-; MSVC-X86-NEXT:    movl %esp, %ebp
-; MSVC-X86-NEXT:    pushl %eax
-; MSVC-X86-NEXT:    movl 8(%ebp), %eax
-; MSVC-X86-NEXT:    movl ___security_cookie, %ecx
-; MSVC-X86-NEXT:    xorl %ebp, %ecx
-; MSVC-X86-NEXT:    movl %ecx, -4(%ebp)
-; MSVC-X86-NEXT:    shll $2, %eax
-; MSVC-X86-NEXT:    calll __chkstk
-; MSVC-X86-NEXT:    movl %esp, %eax
-; MSVC-X86-NEXT:    pushl %eax
-; MSVC-X86-NEXT:    calll _escape
-; MSVC-X86-NEXT:    addl $4, %esp
-; MSVC-X86-NEXT:    movl -4(%ebp), %ecx
-; MSVC-X86-NEXT:    xorl %ebp, %ecx
-; MSVC-X86-NEXT:    calll @__security_check_cookie at 4
-; MSVC-X86-NEXT:    movl %ebp, %esp
-; MSVC-X86-NEXT:    popl %ebp
-; MSVC-X86-NEXT:    retl
-;
-; MSVC-X64-LABEL: test_vla:
-; MSVC-X64:       # %bb.0:
-; MSVC-X64-NEXT:    pushq %rbp
-; MSVC-X64-NEXT:    subq $16, %rsp
-; MSVC-X64-NEXT:    leaq {{[0-9]+}}(%rsp), %rbp
-; MSVC-X64-NEXT:    movq __security_cookie(%rip), %rax
-; MSVC-X64-NEXT:    xorq %rbp, %rax
-; MSVC-X64-NEXT:    movq %rax, -8(%rbp)
-; MSVC-X64-NEXT:    movl %ecx, %eax
-; MSVC-X64-NEXT:    leaq 15(,%rax,4), %rax
-; MSVC-X64-NEXT:    andq $-16, %rax
-; MSVC-X64-NEXT:    callq __chkstk
-; MSVC-X64-NEXT:    subq %rax, %rsp
-; MSVC-X64-NEXT:    movq %rsp, %rcx
-; MSVC-X64-NEXT:    subq $32, %rsp
-; MSVC-X64-NEXT:    callq escape
-; MSVC-X64-NEXT:    addq $32, %rsp
-; MSVC-X64-NEXT:    movq -8(%rbp), %rcx
-; MSVC-X64-NEXT:    xorq %rbp, %rcx
-; MSVC-X64-NEXT:    subq $32, %rsp
-; MSVC-X64-NEXT:    callq __security_check_cookie
-; MSVC-X64-NEXT:    movq %rbp, %rsp
-; MSVC-X64-NEXT:    popq %rbp
-; MSVC-X64-NEXT:    retq
-;
-; MSVC-X86-O0-LABEL: test_vla:
-; MSVC-X86-O0:       # %bb.0:
-; MSVC-X86-O0-NEXT:    pushl %ebp
-; MSVC-X86-O0-NEXT:    movl %esp, %ebp
-; MSVC-X86-O0-NEXT:    pushl %eax
-; MSVC-X86-O0-NEXT:    movl 8(%ebp), %eax
-; MSVC-X86-O0-NEXT:    movl ___security_cookie, %ecx
-; MSVC-X86-O0-NEXT:    xorl %ebp, %ecx
-; MSVC-X86-O0-NEXT:    movl %ecx, -4(%ebp)
-; MSVC-X86-O0-NEXT:    shll $2, %eax
-; MSVC-X86-O0-NEXT:    calll __chkstk
-; MSVC-X86-O0-NEXT:    movl %esp, %eax
-; MSVC-X86-O0-NEXT:    subl $4, %esp
-; MSVC-X86-O0-NEXT:    movl %eax, (%esp)
-; MSVC-X86-O0-NEXT:    calll _escape
-; MSVC-X86-O0-NEXT:    addl $4, %esp
-; MSVC-X86-O0-NEXT:    movl -4(%ebp), %ecx
-; MSVC-X86-O0-NEXT:    xorl %ebp, %ecx
-; MSVC-X86-O0-NEXT:    calll @__security_check_cookie at 4
-; MSVC-X86-O0-NEXT:    movl %ebp, %esp
-; MSVC-X86-O0-NEXT:    popl %ebp
-; MSVC-X86-O0-NEXT:    retl
-;
-; MSVC-X64-O0-LABEL: test_vla:
-; MSVC-X64-O0:       # %bb.0:
-; MSVC-X64-O0-NEXT:    pushq %rbp
-; MSVC-X64-O0-NEXT:    subq $16, %rsp
-; MSVC-X64-O0-NEXT:    leaq {{[0-9]+}}(%rsp), %rbp
-; MSVC-X64-O0-NEXT:    movq __security_cookie(%rip), %rax
-; MSVC-X64-O0-NEXT:    xorq %rbp, %rax
-; MSVC-X64-O0-NEXT:    movq %rax, -8(%rbp)
-; MSVC-X64-O0-NEXT:    movl %ecx, %eax
-; MSVC-X64-O0-NEXT:    # kill: def $rax killed $eax
-; MSVC-X64-O0-NEXT:    leaq 15(,%rax,4), %rax
-; MSVC-X64-O0-NEXT:    andq $-16, %rax
-; MSVC-X64-O0-NEXT:    callq __chkstk
-; MSVC-X64-O0-NEXT:    subq %rax, %rsp
-; MSVC-X64-O0-NEXT:    movq %rsp, %rcx
-; MSVC-X64-O0-NEXT:    subq $32, %rsp
-; MSVC-X64-O0-NEXT:    callq escape
-; MSVC-X64-O0-NEXT:    addq $32, %rsp
-; MSVC-X64-O0-NEXT:    movq -8(%rbp), %rcx
-; MSVC-X64-O0-NEXT:    xorq %rbp, %rcx
-; MSVC-X64-O0-NEXT:    subq $32, %rsp
-; MSVC-X64-O0-NEXT:    callq __security_check_cookie
-; MSVC-X64-O0-NEXT:    movq %rbp, %rsp
-; MSVC-X64-O0-NEXT:    popq %rbp
-; MSVC-X64-O0-NEXT:    retq
   %vla = alloca i32, i32 %n
   call void @escape(ptr %vla)
   ret void
 }
 
+; MSVC-X86-LABEL: _test_vla:
+; MSVC-X86: pushl %ebp
+; MSVC-X86: movl %esp, %ebp
+; MSVC-X86: movl ___security_cookie, %[[REG1:[^ ]*]]
+; MSVC-X86: xorl %ebp, %[[REG1]]
+; MSVC-X86: movl %[[REG1]], [[SLOT:-[0-9]*]](%ebp)
+; MSVC-X86: calll __chkstk
+; MSVC-X86: pushl
+; MSVC-X86: calll _escape
+; MSVC-X86: movl [[SLOT]](%ebp), %ecx
+; MSVC-X86: xorl %ebp, %ecx
+; MSVC-X86: calll @__security_check_cookie at 4
+; MSVC-X86: movl %ebp, %esp
+; MSVC-X86: popl %ebp
+; MSVC-X86: retl
+
+; MSVC-X64-LABEL: test_vla:
+; MSVC-X64: pushq %rbp
+; MSVC-X64: subq $16, %rsp
+; MSVC-X64: leaq 16(%rsp), %rbp
+; MSVC-X64: movq __security_cookie(%rip), %[[REG1:[^ ]*]]
+; MSVC-X64: xorq %rbp, %[[REG1]]
+; MSVC-X64: movq %[[REG1]], [[SLOT:-[0-9]*]](%rbp)
+; MSVC-X64: callq __chkstk
+; MSVC-X64: callq escape
+; MSVC-X64: movq [[SLOT]](%rbp), %rcx
+; MSVC-X64: xorq %rbp, %rcx
+; MSVC-X64: callq __security_check_cookie
+; MSVC-X64: retq
----------------
RKSimon wrote:

These look to have been manually re-added instead of using the update_llc_test_checks script

https://github.com/llvm/llvm-project/pull/95904


More information about the llvm-commits mailing list