www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - dmd -O causes incorrect output

reply Saurabh Das <saurabh.das gmail.com> writes:
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




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
Jan 25 2021
parent reply "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
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)
Jan 25 2021
parent reply Saurabh Das <saurabh.das gmail.com> writes:
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.
Jan 25 2021
parent reply "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
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.
Jan 25 2021
parent Saurabh Das <saurabh.das gmail.com> writes:
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.
Jan 25 2021