D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 15664 - [REG2.064] incorrect initialisation of member of an immutable struct
Summary: [REG2.064] incorrect initialisation of member of an immutable struct
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 regression
Assignee: No Owner
URL:
Keywords: pull, wrong-code
Depends on:
Blocks:
 
Reported: 2016-02-09 15:13 UTC by Richard Delorme
Modified: 2016-03-11 01:57 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Richard Delorme 2016-02-09 15:13:47 UTC
[code]
import std.stdio;

struct Data
{
	int a[2];
	int b[2][2];
	int c;
};

immutable Data d = {[ 1, 2], [[ 3, 4], [5, 6]], 7};

unittest
{
	assert(d.c == 7);
}

void main()
{
	writeln(d);
}
[/code]

Compiled with dmd x86_64 (version 2.62.2 & 2.70.0) on linux (fedora), it gives the incorrect following output:
immutable(Data)([1, 2], [[3, 4], [5, 6]], 3)
the expected output is:
immutable(Data)([1, 2], [[3, 4], [5, 6]], 7)
Optimization compilation flags does not have any impact on the output.
The -unittest flag triggers the assert.
Comment 1 Kenji Hara 2016-02-11 07:01:47 UTC
This is a codegen regression from 2.094, introduced in:
https://github.com/D-Programming-Language/dmd/pull/2659
Comment 3 github-bugzilla 2016-02-23 14:16:53 UTC
Commits pushed to stable at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/c396fd9941f873c6ed9fd5ac281621dd911d6f7a
fix Issue 15664 - incorrect initialisation of member of an immutable struct

When a struct literal appears in dataseg or TLS variable initialization, its elements `StructLiteralExp.elements[i]` are also painted to the qualifier of constructed struct type. But in `toDtElem`, type identity comparison was used to calculate array dimension, so the qualifier difference had caused wrong code.

https://github.com/D-Programming-Language/dmd/commit/cf670840a444413bc99ce721f19260c35450a766
Merge pull request #5440 from 9rnsr/fix15664

[REG2.064] Issue 15664 - incorrect initialisation of member of an immutable struct
Comment 4 github-bugzilla 2016-02-24 02:55:33 UTC
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/c396fd9941f873c6ed9fd5ac281621dd911d6f7a
fix Issue 15664 - incorrect initialisation of member of an immutable struct

https://github.com/D-Programming-Language/dmd/commit/cf670840a444413bc99ce721f19260c35450a766
Merge pull request #5440 from 9rnsr/fix15664