Thread overview
dmd -O causes incorrect output
Jan 25, 2021
Saurabh Das
Jan 25, 2021
H. S. Teoh
Jan 25, 2021
Saurabh Das
Jan 25, 2021
H. S. Teoh
Jan 26, 2021
Saurabh Das
January 25, 2021
I'm seeing what appears to be a bug with the -O flag in dmd. Here is a reduced test case:

struct SomeStruct
{
    long value;
}
bool isNumberOne(int i)
{
	SomeStruct l;
	if(i == 1)
		l = SomeStruct(10);
	return (l == SomeStruct(10));
}
void main()
{
    if (!isNumberOne(1))
        assert(false);
}

See: https://run.dlang.io/is/zlrDvy

rdmd test.d    # Runs fine
rdmd -O test.d # Assert trips

The assert trips when run with "rdmd -O test.d" and it does not trip when run with "rdmd test.d".

This bug is observed in all compiler versions from dmd-2.060 through to dmd-2.095! Please shed some light on the issue – any help would be greatly appreciated.

Thanks,
Saurabh

January 25, 2021
On Mon, Jan 25, 2021 at 06:07:46PM +0000, Saurabh Das via Digitalmars-d-learn wrote:
> I'm seeing what appears to be a bug with the -O flag in dmd.
[...]
> The assert trips when run with "rdmd -O test.d" and it does not trip when run with "rdmd test.d".

It's probably a bug. File a bug on bugzilla: https://issues.dlang.org


> This bug is observed in all compiler versions from dmd-2.060 through to dmd-2.095! Please shed some light on the issue – any help would be greatly appreciated.
[...]

DMD's backend is known to have obscure bugs that crop up every so often. If this issue is being a showstopper, consider switching to LDC or GDC instead.  (You might want to try the same code with LDC/GDC anyway, just to see whether they have the same problem. My guess is they don't.)


T

-- 
People demand freedom of speech to make up for the freedom of thought which they avoid. -- Soren Aabye Kierkegaard (1813-1855)
January 25, 2021
On Monday, 25 January 2021 at 18:19:24 UTC, H. S. Teoh wrote:
> On Mon, Jan 25, 2021 at 06:07:46PM +0000, Saurabh Das via Digitalmars-d-learn wrote:
>> [...]
> [...]
>> [...]
>
> It's probably a bug. File a bug on bugzilla: https://issues.dlang.org
>
>
>> [...]
> [...]
>
> DMD's backend is known to have obscure bugs that crop up every so often. If this issue is being a showstopper, consider switching to LDC or GDC instead.  (You might want to try the same code with LDC/GDC anyway, just to see whether they have the same problem. My guess is they don't.)
>
>
> T

LDMD2 seems to not suffer from this issue.
January 25, 2021
On Mon, Jan 25, 2021 at 06:45:43PM +0000, Saurabh Das via Digitalmars-d-learn wrote:
> On Monday, 25 January 2021 at 18:19:24 UTC, H. S. Teoh wrote:
[...]
> > It's probably a bug. File a bug on bugzilla: https://issues.dlang.org
[...]
> > DMD's backend is known to have obscure bugs that crop up every so often.  If this issue is being a showstopper, consider switching to LDC or GDC instead.  (You might want to try the same code with LDC/GDC anyway, just to see whether they have the same problem. My guess is they don't.)
[...]
> LDMD2 seems to not suffer from this issue.

No surprise there. I recommend using LDC (ldmd2) instead.

Still file the bug, though, so that somebody will fix it eventually.


T

-- 
There is no gravity. The earth sucks.
January 26, 2021
On Monday, 25 January 2021 at 19:18:47 UTC, H. S. Teoh wrote:
> On Mon, Jan 25, 2021 at 06:45:43PM +0000, Saurabh Das via Digitalmars-d-learn wrote:
>> On Monday, 25 January 2021 at 18:19:24 UTC, H. S. Teoh wrote:
> [...]
>> > It's probably a bug. File a bug on bugzilla: https://issues.dlang.org
> [...]
>> > DMD's backend is known to have obscure bugs that crop up every so often.  If this issue is being a showstopper, consider switching to LDC or GDC instead.  (You might want to try the same code with LDC/GDC anyway, just to see whether they have the same problem. My guess is they don't.)
> [...]
>> LDMD2 seems to not suffer from this issue.
>
> No surprise there. I recommend using LDC (ldmd2) instead.
>
> Still file the bug, though, so that somebody will fix it eventually.
>
>
> T

Thanks for the inputs. I'll fill a bug report about it.