Skip to content

Commit 9678f11

Browse files
nikictru
authored andcommitted
[StackColoring] Handle fixed object index
This is a followup to llvm#66988. The implementation there did not account for the possibility of the catch object frame index referrring to a fixed object, which is the case on win64. (cherry picked from commit aa70f4d)
1 parent 49e9ee1 commit 9678f11

File tree

2 files changed

+148
-66
lines changed

2 files changed

+148
-66
lines changed

llvm/lib/CodeGen/StackColoring.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,8 @@ unsigned StackColoring::collectMarkers(unsigned NumSlot) {
709709
if (WinEHFuncInfo *EHInfo = MF->getWinEHFuncInfo())
710710
for (WinEHTryBlockMapEntry &TBME : EHInfo->TryBlockMap)
711711
for (WinEHHandlerType &H : TBME.HandlerArray)
712-
if (H.CatchObj.FrameIndex != std::numeric_limits<int>::max())
712+
if (H.CatchObj.FrameIndex != std::numeric_limits<int>::max() &&
713+
H.CatchObj.FrameIndex >= 0)
713714
ConservativeSlots.set(H.CatchObj.FrameIndex);
714715

715716
LLVM_DEBUG(dumpBV("Conservative slots", ConservativeSlots));

llvm/test/CodeGen/X86/stack-coloring-wineh.ll

Lines changed: 146 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,155 @@
11
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 3
2-
; RUN: llc -mtriple=i686-windows-msvc < %s | FileCheck %s
2+
; RUN: llc -mtriple=i686-windows-msvc < %s | FileCheck %s --check-prefix=I686
3+
; RUN: llc -mtriple=x86_64-windows-msvc < %s | FileCheck %s --check-prefix=X86_64
34

45
@type_info = external global ptr
56

67
; Make sure %a1 and %a2 don't share the same stack offset.
78
define void @pr66984(ptr %arg) personality ptr @__CxxFrameHandler3 {
8-
; CHECK-LABEL: pr66984:
9-
; CHECK: # %bb.0: # %bb
10-
; CHECK-NEXT: pushl %ebp
11-
; CHECK-NEXT: movl %esp, %ebp
12-
; CHECK-NEXT: pushl %ebx
13-
; CHECK-NEXT: pushl %edi
14-
; CHECK-NEXT: pushl %esi
15-
; CHECK-NEXT: subl $24, %esp
16-
; CHECK-NEXT: movl %esp, -28(%ebp)
17-
; CHECK-NEXT: movl $-1, -16(%ebp)
18-
; CHECK-NEXT: leal -24(%ebp), %eax
19-
; CHECK-NEXT: movl $___ehhandler$pr66984, -20(%ebp)
20-
; CHECK-NEXT: movl %fs:0, %ecx
21-
; CHECK-NEXT: movl %ecx, -24(%ebp)
22-
; CHECK-NEXT: movl %eax, %fs:0
23-
; CHECK-NEXT: movl $1, -16(%ebp)
24-
; CHECK-NEXT: calll _throw
25-
; CHECK-NEXT: # %bb.1: # %bb14
26-
; CHECK-NEXT: LBB0_3: # Block address taken
27-
; CHECK-NEXT: # %bb17
28-
; CHECK-NEXT: addl $12, %ebp
29-
; CHECK-NEXT: jmp LBB0_4
30-
; CHECK-NEXT: LBB0_4: # %exit
31-
; CHECK-NEXT: $ehgcr_0_4:
32-
; CHECK-NEXT: movl -24(%ebp), %eax
33-
; CHECK-NEXT: movl %eax, %fs:0
34-
; CHECK-NEXT: addl $24, %esp
35-
; CHECK-NEXT: popl %esi
36-
; CHECK-NEXT: popl %edi
37-
; CHECK-NEXT: popl %ebx
38-
; CHECK-NEXT: popl %ebp
39-
; CHECK-NEXT: retl
40-
; CHECK-NEXT: .def "?catch$2@?0?pr66984@4HA";
41-
; CHECK-NEXT: .scl 3;
42-
; CHECK-NEXT: .type 32;
43-
; CHECK-NEXT: .endef
44-
; CHECK-NEXT: .p2align 4, 0x90
45-
; CHECK-NEXT: "?catch$2@?0?pr66984@4HA":
46-
; CHECK-NEXT: LBB0_2: # %bb17
47-
; CHECK-NEXT: pushl %ebp
48-
; CHECK-NEXT: addl $12, %ebp
49-
; CHECK-NEXT: movl %esp, -28(%ebp)
50-
; CHECK-NEXT: movl -36(%ebp), %ecx
51-
; CHECK-NEXT: movl $2, -16(%ebp)
52-
; CHECK-NEXT: calll _cleanup
53-
; CHECK-NEXT: movl $LBB0_3, %eax
54-
; CHECK-NEXT: popl %ebp
55-
; CHECK-NEXT: retl # CATCHRET
56-
; CHECK-NEXT: .def "?dtor$5@?0?pr66984@4HA";
57-
; CHECK-NEXT: .scl 3;
58-
; CHECK-NEXT: .type 32;
59-
; CHECK-NEXT: .endef
60-
; CHECK-NEXT: .p2align 4, 0x90
61-
; CHECK-NEXT: "?dtor$5@?0?pr66984@4HA":
62-
; CHECK-NEXT: LBB0_5: # %bb8
63-
; CHECK-NEXT: pushl %ebp
64-
; CHECK-NEXT: addl $12, %ebp
65-
; CHECK-NEXT: movl 8(%ebp), %eax
66-
; CHECK-NEXT: movl %eax, -32(%ebp)
67-
; CHECK-NEXT: leal -32(%ebp), %ecx
68-
; CHECK-NEXT: calll _foo
69-
; CHECK-NEXT: popl %ebp
70-
; CHECK-NEXT: retl # CLEANUPRET
71-
; CHECK-NEXT: Lfunc_end0:
9+
; I686-LABEL: pr66984:
10+
; I686: # %bb.0: # %bb
11+
; I686-NEXT: pushl %ebp
12+
; I686-NEXT: movl %esp, %ebp
13+
; I686-NEXT: pushl %ebx
14+
; I686-NEXT: pushl %edi
15+
; I686-NEXT: pushl %esi
16+
; I686-NEXT: subl $24, %esp
17+
; I686-NEXT: movl %esp, -28(%ebp)
18+
; I686-NEXT: movl $-1, -16(%ebp)
19+
; I686-NEXT: leal -24(%ebp), %eax
20+
; I686-NEXT: movl $___ehhandler$pr66984, -20(%ebp)
21+
; I686-NEXT: movl %fs:0, %ecx
22+
; I686-NEXT: movl %ecx, -24(%ebp)
23+
; I686-NEXT: movl %eax, %fs:0
24+
; I686-NEXT: movl $1, -16(%ebp)
25+
; I686-NEXT: calll _throw
26+
; I686-NEXT: # %bb.1: # %bb14
27+
; I686-NEXT: LBB0_3: # Block address taken
28+
; I686-NEXT: # %bb17
29+
; I686-NEXT: addl $12, %ebp
30+
; I686-NEXT: jmp LBB0_4
31+
; I686-NEXT: LBB0_4: # %exit
32+
; I686-NEXT: $ehgcr_0_4:
33+
; I686-NEXT: movl -24(%ebp), %eax
34+
; I686-NEXT: movl %eax, %fs:0
35+
; I686-NEXT: addl $24, %esp
36+
; I686-NEXT: popl %esi
37+
; I686-NEXT: popl %edi
38+
; I686-NEXT: popl %ebx
39+
; I686-NEXT: popl %ebp
40+
; I686-NEXT: retl
41+
; I686-NEXT: .def "?catch$2@?0?pr66984@4HA";
42+
; I686-NEXT: .scl 3;
43+
; I686-NEXT: .type 32;
44+
; I686-NEXT: .endef
45+
; I686-NEXT: .p2align 4, 0x90
46+
; I686-NEXT: "?catch$2@?0?pr66984@4HA":
47+
; I686-NEXT: LBB0_2: # %bb17
48+
; I686-NEXT: pushl %ebp
49+
; I686-NEXT: addl $12, %ebp
50+
; I686-NEXT: movl %esp, -28(%ebp)
51+
; I686-NEXT: movl -36(%ebp), %ecx
52+
; I686-NEXT: movl $2, -16(%ebp)
53+
; I686-NEXT: calll _cleanup
54+
; I686-NEXT: movl $LBB0_3, %eax
55+
; I686-NEXT: popl %ebp
56+
; I686-NEXT: retl # CATCHRET
57+
; I686-NEXT: .def "?dtor$5@?0?pr66984@4HA";
58+
; I686-NEXT: .scl 3;
59+
; I686-NEXT: .type 32;
60+
; I686-NEXT: .endef
61+
; I686-NEXT: .p2align 4, 0x90
62+
; I686-NEXT: "?dtor$5@?0?pr66984@4HA":
63+
; I686-NEXT: LBB0_5: # %bb8
64+
; I686-NEXT: pushl %ebp
65+
; I686-NEXT: addl $12, %ebp
66+
; I686-NEXT: movl 8(%ebp), %eax
67+
; I686-NEXT: movl %eax, -32(%ebp)
68+
; I686-NEXT: leal -32(%ebp), %ecx
69+
; I686-NEXT: calll _foo
70+
; I686-NEXT: popl %ebp
71+
; I686-NEXT: retl # CLEANUPRET
72+
; I686-NEXT: Lfunc_end0:
73+
;
74+
; X86_64-LABEL: pr66984:
75+
; X86_64: # %bb.0: # %bb
76+
; X86_64-NEXT: pushq %rbp
77+
; X86_64-NEXT: .seh_pushreg %rbp
78+
; X86_64-NEXT: subq $64, %rsp
79+
; X86_64-NEXT: .seh_stackalloc 64
80+
; X86_64-NEXT: leaq {{[0-9]+}}(%rsp), %rbp
81+
; X86_64-NEXT: .seh_setframe %rbp, 64
82+
; X86_64-NEXT: .seh_endprologue
83+
; X86_64-NEXT: movq $-2, -16(%rbp)
84+
; X86_64-NEXT: movq %rcx, {{[-0-9]+}}(%r{{[sb]}}p) # 8-byte Spill
85+
; X86_64-NEXT: .Ltmp0:
86+
; X86_64-NEXT: callq throw
87+
; X86_64-NEXT: .Ltmp1:
88+
; X86_64-NEXT: # %bb.1: # %bb14
89+
; X86_64-NEXT: .LBB0_3: # Block address taken
90+
; X86_64-NEXT: # %exit
91+
; X86_64-NEXT: $ehgcr_0_3:
92+
; X86_64-NEXT: nop
93+
; X86_64-NEXT: addq $64, %rsp
94+
; X86_64-NEXT: popq %rbp
95+
; X86_64-NEXT: retq
96+
; X86_64-NEXT: .seh_handlerdata
97+
; X86_64-NEXT: .long ($cppxdata$pr66984)@IMGREL
98+
; X86_64-NEXT: .text
99+
; X86_64-NEXT: .seh_endproc
100+
; X86_64-NEXT: .def "?catch$2@?0?pr66984@4HA";
101+
; X86_64-NEXT: .scl 3;
102+
; X86_64-NEXT: .type 32;
103+
; X86_64-NEXT: .endef
104+
; X86_64-NEXT: .p2align 4, 0x90
105+
; X86_64-NEXT: "?catch$2@?0?pr66984@4HA":
106+
; X86_64-NEXT: .seh_proc "?catch$2@?0?pr66984@4HA"
107+
; X86_64-NEXT: .seh_handler __CxxFrameHandler3, @unwind, @except
108+
; X86_64-NEXT: .LBB0_2: # %bb17
109+
; X86_64-NEXT: movq %rdx, {{[0-9]+}}(%rsp)
110+
; X86_64-NEXT: pushq %rbp
111+
; X86_64-NEXT: .seh_pushreg %rbp
112+
; X86_64-NEXT: subq $32, %rsp
113+
; X86_64-NEXT: .seh_stackalloc 32
114+
; X86_64-NEXT: leaq 64(%rdx), %rbp
115+
; X86_64-NEXT: .seh_endprologue
116+
; X86_64-NEXT: movq -8(%rbp), %rcx
117+
; X86_64-NEXT: callq cleanup
118+
; X86_64-NEXT: leaq .LBB0_3(%rip), %rax
119+
; X86_64-NEXT: addq $32, %rsp
120+
; X86_64-NEXT: popq %rbp
121+
; X86_64-NEXT: retq # CATCHRET
122+
; X86_64-NEXT: .seh_handlerdata
123+
; X86_64-NEXT: .long ($cppxdata$pr66984)@IMGREL
124+
; X86_64-NEXT: .text
125+
; X86_64-NEXT: .seh_endproc
126+
; X86_64-NEXT: .def "?dtor$4@?0?pr66984@4HA";
127+
; X86_64-NEXT: .scl 3;
128+
; X86_64-NEXT: .type 32;
129+
; X86_64-NEXT: .endef
130+
; X86_64-NEXT: .p2align 4, 0x90
131+
; X86_64-NEXT: "?dtor$4@?0?pr66984@4HA":
132+
; X86_64-NEXT: .seh_proc "?dtor$4@?0?pr66984@4HA"
133+
; X86_64-NEXT: .LBB0_4: # %bb8
134+
; X86_64-NEXT: movq %rdx, {{[0-9]+}}(%rsp)
135+
; X86_64-NEXT: pushq %rbp
136+
; X86_64-NEXT: .seh_pushreg %rbp
137+
; X86_64-NEXT: subq $32, %rsp
138+
; X86_64-NEXT: .seh_stackalloc 32
139+
; X86_64-NEXT: leaq 64(%rdx), %rbp
140+
; X86_64-NEXT: .seh_endprologue
141+
; X86_64-NEXT: movq {{[-0-9]+}}(%r{{[sb]}}p), %rax # 8-byte Reload
142+
; X86_64-NEXT: movq %rax, -32(%rbp)
143+
; X86_64-NEXT: leaq -32(%rbp), %rcx
144+
; X86_64-NEXT: callq foo
145+
; X86_64-NEXT: nop
146+
; X86_64-NEXT: addq $32, %rsp
147+
; X86_64-NEXT: popq %rbp
148+
; X86_64-NEXT: retq # CLEANUPRET
149+
; X86_64-NEXT: .Lfunc_end0:
150+
; X86_64-NEXT: .seh_handlerdata
151+
; X86_64-NEXT: .text
152+
; X86_64-NEXT: .seh_endproc
72153
bb:
73154
%a1 = alloca ptr, align 4
74155
%a2 = alloca ptr, align 4

0 commit comments

Comments
 (0)