Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Issue 22617 - CTFE rejects modification of copied static array #13575

Open
wants to merge 1 commit into
base: stable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 11 additions & 7 deletions src/dmd/dinterpret.d
Original file line number Diff line number Diff line change
Expand Up @@ -2502,15 +2502,19 @@ public:
ale.ownedByCtfe = OwnedBy.ctfe;
result = ale;
}
else if ((cast(TypeNext)e.type).next.mod & (MODFlags.const_ | MODFlags.immutable_))
{
// If it's immutable, we don't need to dup it
result = e;
}
else
{
*pue = copyLiteral(e);
result = pue.exp();
auto elemType = (cast(TypeNext)e.type).next;
if (elemType.mod & (MODFlags.const_ | MODFlags.immutable_) && elemType.hasPointers())
{
// If it's immutable and contains indirections, we don't need to dup it
result = e;
Comment on lines +2510 to +2511
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That doesn't seem right. The following example still fails with this patch:

int countWins(const uint*[2] arr)
{
	const(uint)*[2] copy = arr;
	copy[0] = null;
	return 0;
}

enum force = countWins([null, null]);

}
else
{
*pue = copyLiteral(e);
result = pue.exp();
}
}
}

Expand Down
10 changes: 10 additions & 0 deletions test/compilable/test22617.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// https://issues.dlang.org/show_bug.cgi?id=22617

int countWins(const uint[2] arr)
{
uint[2] copy = arr;
copy[0] = 0;
return 0;
}

enum force = countWins([4, 8]);