[Issue 18794] New: Compiling with -O causes runtime segfault
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Apr 24 18:25:19 UTC 2018
https://issues.dlang.org/show_bug.cgi?id=18794
Issue ID: 18794
Summary: Compiling with -O causes runtime segfault
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: major
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: hsteoh at quickfur.ath.cx
Reduced code:
------------
void func() {}
struct S
{
size_t[] impl;
this(int v)
{
impl = [0];
}
bool method(int v)
{
int wordIdx = v >> 6;
int bitIdx = v & 0b00111111;
func();
if (wordIdx >= impl.length)
return false;
return (impl[0] & (1UL << bitIdx)) != 0;
}
}
void main()
{
auto s = S(0);
s.method(0);
}
------------
Compile command: dmd -O -run test.d
Output:
------------
Error: program killed by signal 11
------------
Compiling without -O fixes the problem. Commenting out the call to func() also
makes the problem go away. Also, the details of method() seem quite important;
changing the return statement in various ways seems to make the problem go
away, though I'm not 100% certain the current form is minimal. Eliding the
ctor call also makes the problem go away, though I didn't explore all possible
combinations.
In the original call, wordIdx is used to index the impl array, but the problem
seems to persist even when impl[0] is hardcoded. However, removing the test
`wordIdx >= impl.length` seems to mask the problem. So there's something about
it that's triggering the wrong code.
--
More information about the Digitalmars-d-bugs
mailing list