D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 21584 - dmd -O causes incorrect output
Summary: dmd -O causes incorrect output
Status: RESOLVED WORKSFORME
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Linux
: P1 major
Assignee: No Owner
URL:
Keywords: backend
Depends on:
Blocks:
 
Reported: 2021-01-26 05:51 UTC by Saurabh Das
Modified: 2022-04-13 12:26 UTC (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Saurabh Das 2021-01-26 05:51:25 UTC
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.

Forum discussion: https://forum.dlang.org/post/dpwzsxjksoqjzjvrwehw@forum.dlang.org

Thanks,
Saurabh
Comment 1 Dennis 2022-04-13 12:26:43 UTC
While I could reproduce it with dmd-2.095, it works on dmd-2.097.1 and master.