ldc icon indicating copy to clipboard operation
ldc copied to clipboard

[druntime-test] memoryerror_stackoverflow.d: Prevent hangs with >=llv…

Open the-horo opened this issue 4 months ago • 5 comments

…m-20

Since llvm-20, the stack variables are optimized away leading to an infinite loop. The affected assembly became:

Disassembly of section .text._D25memoryerror_stackoverflow1fFKG1024hZv:

0000000000000000 <_D25memoryerror_stackoverflow1fFKG1024hZv>:
   0:	e9 00 00 00 00       	jmp    5 <_D25memoryerror_stackoverflow1fFKG1024hZv+0x5>

Disassembly of section .text._D25memoryerror_stackoverflow1gFKG1024hZv:

0000000000000000 <_D25memoryerror_stackoverflow1gFKG1024hZv>:
   0:	e9 00 00 00 00       	jmp    5 <_D25memoryerror_stackoverflow1gFKG1024hZv+0x5>

Compared to the llvm-19 optimized version:

Disassembly of section .text._D25memoryerror_stackoverflow1fFKG1024hZv:

0000000000000000 <_D25memoryerror_stackoverflow1fFKG1024hZv>:
   0:	53                   	push   %rbx
   1:	48 81 ec 00 04 00 00 	sub    $0x400,%rsp
   8:	48 89 fe             	mov    %rdi,%rsi
   b:	48 89 e3             	mov    %rsp,%rbx
   e:	ba 00 04 00 00       	mov    $0x400,%edx
  13:	48 89 df             	mov    %rbx,%rdi
  16:	e8 00 00 00 00       	call   1b <_D25memoryerror_stackoverflow1fFKG1024hZv+0x1b>
  1b:	48 89 df             	mov    %rbx,%rdi
  1e:	e8 00 00 00 00       	call   23 <_D25memoryerror_stackoverflow1fFKG1024hZv+0x23>
  23:	48 81 c4 00 04 00 00 	add    $0x400,%rsp
  2a:	5b                   	pop    %rbx
  2b:	c3                   	ret

Disassembly of section .text._D25memoryerror_stackoverflow1gFKG1024hZv:

0000000000000000 <_D25memoryerror_stackoverflow1gFKG1024hZv>:
   0:	53                   	push   %rbx
   1:	48 81 ec 00 04 00 00 	sub    $0x400,%rsp
   8:	48 89 fe             	mov    %rdi,%rsi
   b:	48 89 e3             	mov    %rsp,%rbx
   e:	ba 00 04 00 00       	mov    $0x400,%edx
  13:	48 89 df             	mov    %rbx,%rdi
  16:	e8 00 00 00 00       	call   1b <_D25memoryerror_stackoverflow1gFKG1024hZv+0x1b>
  1b:	48 89 df             	mov    %rbx,%rdi
  1e:	e8 00 00 00 00       	call   23 <_D25memoryerror_stackoverflow1gFKG1024hZv+0x23>
  23:	48 81 c4 00 04 00 00 	add    $0x400,%rsp
  2a:	5b                   	pop    %rbx
  2b:	c3                   	ret

the-horo avatar Aug 16 '25 10:08 the-horo

I'm also fine backporting these upstream but I wanted to get a review from here first

the-horo avatar Aug 16 '25 10:08 the-horo

lgtm

JohanEngelen avatar Aug 18 '25 09:08 JohanEngelen

How come this doesn't show up as a CI problem?

kinke avatar Aug 18 '25 11:08 kinke

How come this doesn't show up as a CI problem?

It's an amazing question that I have no idea how to answer. It wouldn't be the first time CI would work while a real system would fail but this specific issue does seem weird. The release artifacts do optimize the code as expected so it does leave a question mark over how those exact artifacts managed to pass the test.

Is it ever possible that the test is not running in CI? This seems like the most plausible explanation

the-horo avatar Aug 18 '25 12:08 the-horo

#4970 for logs on the current situation

the-horo avatar Aug 18 '25 12:08 the-horo

This has landed from upstream now.

kinke avatar Dec 19 '25 10:12 kinke