Bug in DMD?

ryuukk_ ryuukk.dev at gmail.com
Fri Mar 3 01:21:52 UTC 2023


On Friday, 3 March 2023 at 01:11:06 UTC, Vladimir Panteleev wrote:
> On Friday, 3 March 2023 at 01:07:07 UTC, ryuukk_ wrote:
>> I couldn't figure out dustmite, so i started from 0 and 
>> managed to hit something:
>>
>> https://github.com/ryuukk/dmd_bug
>>
>> ``Assertion failed: array index out of bounds, file 
>> game\app.d, line 5``
>>
>> Wich indicates probably TLS problem?
>
> Yeah... `rt.a.stuffs` is a TLS variable. The D runtime manages 
> TLS. `extern(C) main` bypasses D runtime initialization.

I have some questions:

1. why does it work with LDC?
2. why does it work with DMD when build/link in 2 step?
3. why it doesn't work when DMD is invoked once for build/link
4. is this a bug in DMD or my code is wrong?
5. if it's wrong, then why does it compile/no error?


```sh
#!/usr/bin/env bash

set -e

build_dmd() {
	echo "build dmd"
	dmd \
	-debug -g \
	-m64 -vcolumns -betterC -w -i -i=-std -i=-core \
	-Igame \
	-Istuff/ \
	stuff/rt/object.d \
	game/app.d \
	-of=game.exe
}

build_ldc() {
	echo "build ldc"
	ldc2 \
	-d-debug -g \
	-m64 -vcolumns -betterC -w -i -i=-std -i=-core \
	-Igame \
	-Istuff/ \
	stuff/rt/object.d \
	game/app.d \
	-of=game.exe
}

build_dmd_and_link() {
	echo "build dmd and link (2step)"
	dmd \
	-debug -g -c \
	-m64 -vcolumns -betterC -w -i -i=-std -i=-core \
	-Igame \
	-Istuff/ \
	stuff/rt/object.d \
	game/app.d \
	-of=game.obj

	dmd \
	-debug -g  \
	-m64 -vcolumns -betterC -w -i -i=-std -i=-core \
	-Igame \
	-Istuff/ \
	game.obj \
	-of=game.exe
}


build_ldc
./game.exe
rm game.obj game.exe

build_dmd_and_link
./game.exe
rm game.obj game.exe

build_dmd
./game.exe
rm game.obj game.exe
```


More information about the Digitalmars-d-learn mailing list