Skip to content

Conversation

the-horo
Copy link
Contributor

…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

…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
```

Signed-off-by: Andrei Horodniceanu <[email protected]>
@the-horo
Copy link
Contributor Author

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

@JohanEngelen
Copy link
Member

lgtm

@kinke
Copy link
Member

kinke commented Aug 18, 2025

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

@the-horo
Copy link
Contributor Author

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
Copy link
Contributor Author

#4970 for logs on the current situation

the-horo added a commit to the-horo/dmd that referenced this pull request Aug 19, 2025
…tions

gdc and ldc2 with llvm-20 optimize away the array declarations leading
to an infinite cycle.

See-Also: ldc-developers/ldc#4969
Signed-off-by: Andrei Horodniceanu <[email protected]>
thewilsonator pushed a commit to dlang/dmd that referenced this pull request Aug 19, 2025
…tions (#21742)

gdc and ldc2 with llvm-20 optimize away the array declarations leading
to an infinite cycle.

See-Also: ldc-developers/ldc#4969

Signed-off-by: Andrei Horodniceanu <[email protected]>
kinke pushed a commit that referenced this pull request Aug 25, 2025
…tions (dlang/dmd!21742)

gdc and ldc2 with llvm-20 optimize away the array declarations leading
to an infinite cycle.

See-Also: #4969

Signed-off-by: Andrei Horodniceanu <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants