D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 13711 - Optimizer bug (yet another one, with test case)
Summary: Optimizer bug (yet another one, with test case)
Status: RESOLVED WORKSFORME
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Linux
: P1 normal
Assignee: No Owner
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2014-11-11 08:47 UTC by Marco Leise
Modified: 2020-08-10 05:20 UTC (History)
2 users (show)

See Also:


Attachments
test case source code (2.62 KB, text/plain)
2014-11-11 08:47 UTC, Marco Leise
Details
.tga for test case (482.15 KB, image/x-tga)
2014-11-11 08:48 UTC, Marco Leise
Details

Note You need to log in before you can comment on or make changes to this issue.
Description Marco Leise 2014-11-11 08:47:04 UTC
Created attachment 1452 [details]
test case source code

I get a segmentation fault with -O -release for the read of *src in the following partial function:

--------8<--------
ubyte* src = …;
uint c;
final switch (pixelSize)
{
	case 16:
		foreach (w; 0 .. count)
		{
			c = *src & 0b000_11111;
			c |= (*src++ & 0b111_00000) << (8-5);
			src++;
			c |= (*src & 0b0_00000_11) << (8+3);
			c |= (*src & 0b0_11111_00) << (16-2);
			src++;                          // *** problematic instruction
			(dst++).color = 0xFF000000 | (c << 3);
		}
		break;
	case 24:
		foreach (w; 0 .. count)
		{
			c = 0xFF000000 | *(src++) | (*(src++) << 8) | (*(src++) << 16);
			(dst++).color = c;
		}
		break;
	case 32:
		foreach (w; 0 .. count)
		{
			c = 0xFF000000 | *(src++) | (*(src++) << 8) | (*(src++) << 16);
			src++;
			(dst++).color = c;
		}
		break;
}
-------->8--------

If I change the location of the problematic instruction from:

	c |= (*src & 0b0_11111_00) << (16-2);
	src++;

to:

	c |= (*src++ & 0b0_11111_00) << (16-2);

I get no crash and the function completes. I was also able to fix it with a function call right before the snippet, so it is likely to be affected by CPU register allocation(?)

When I created a test case and removed some files the crash with the -O -release switches disappeared but could be  reproduced again with `dmd -O -release -inline main.d && ./main`. The test case requires the .tga file to work.
Comment 1 Marco Leise 2014-11-11 08:48:18 UTC
Created attachment 1453 [details]
.tga for test case
Comment 2 Nemanja Boric 2017-01-13 16:56:34 UTC
Looks like this is fixed. Perhaps it's related to https://issues.dlang.org/show_bug.cgi?id=16225?
Comment 3 Marco Leise 2017-04-06 21:29:53 UTC
I reopened this issue, because I just downloaded the test case again and executed `dmd-2.073 -O -release -inline main.d && ./main`. It still crashes with following message:

  Parsing '640x480-16bit-RLE.tga'
  zsh: segmentation fault  ./main
Comment 4 Walter Bright 2020-08-10 05:20:13 UTC
Compiling it for 64 bit Linux, the latest dmd, and with:

 dmd main
 dmd main -O
 dmd main -O -release -inline

I get the following output each time:

 Parsing '640x480-16bit-RLE.tga'
 640x480: 68175

No seg faults.