D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 17845 - [ICE] backend\cgcod.c 1677
Summary: [ICE] backend\cgcod.c 1677
Status: RESOLVED WORKSFORME
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 critical
Assignee: No Owner
URL:
Keywords: ice
Depends on:
Blocks:
 
Reported: 2017-09-21 07:51 UTC by MrSmith33
Modified: 2020-03-21 03:56 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 MrSmith33 2017-09-21 07:51:02 UTC
---
void main()
{
	struct Row
	{
		@Column!Row((ref Row r, scope SinkT s){ s("test"); })
		uint fileSize;
	}
	auto formatters = parseRowInfo!Row;
}


alias SinkT = void delegate(const(char)[]);
alias Formatter(Row) = void delegate(ref Row row, scope SinkT sink);

struct Column(Row)
{
	Formatter!Row formatter;
}

Formatter!Row[] parseRowInfo(Row)()
{
	import std.traits;
	Formatter!Row[] formatters;
	static foreach(member; getSymbolsByUDA!(Row, Column!Row))
	{
		formatters ~= getUDAs!(member, Column!Row)[0].formatter;
	}
	return formatters;
}

---

This is reduced case. I was trying to make this work without static in foreach, but adding static crashed the compiler.

Win10 DMD 2.076

Doesn't crash on dpaste though.
Comment 1 MrSmith33 2017-09-21 08:14:58 UTC
This crashes with the same error

---
void main()
{
	struct Row
	{
		@Column!Row((ref Row r, scope SinkT s){ s("test"); })
		uint fileSize;
	}
	auto formatters = parseRowInfo!Row;
}


alias SinkT = void delegate(const(char)[]);
alias Formatter(Row) = void delegate(ref Row row, scope SinkT sink);

struct Column(Row)
{
	Formatter!Row formatter;
}

Formatter!Row[] parseRowInfo(Row)()
{
	import std.traits;
	Formatter!Row[] formatters;
	alias symbols = getSymbolsByUDA!(Row, Column!Row);
	foreach(i; 0..symbols.length)
	{
		formatters ~= getUDAs!(symbols, Column!Row)[0].formatter;
	}
	return formatters;
}
---
Comment 2 MrSmith33 2017-09-21 09:13:38 UTC
Looks like the problem is with the use of delegate. When switching to function it works.

---
void main()
{
	struct Row
	{
		@Column!Row((ref Row r, scope SinkT s){ s("test"); })
		uint fileSize;
	}
	auto formatters = parseRowInfo!Row;
}


alias SinkT = void delegate(const(char)[]);

// Internal error: ddmd\backend\cgcod.c 1677 when function -> delegate
alias Formatter(Row) = void function(ref Row row, scope SinkT sink);

struct Column(Row)
{
	Formatter!Row formatter;
}

Formatter!Row[] parseRowInfo(Row)()
{
	import std.traits;
	Formatter!Row[] formatters;
	Row r;
	foreach(string memberName; __traits(allMembers, Row))
	{
		foreach(attr; __traits(getAttributes, __traits(getMember, r, memberName)))
		{
			static if (is(typeof(attr) == Column!Row))
			{
				formatters ~= attr.formatter;
			}
		}
	}
	return formatters;
}
---
Comment 3 basile-z 2019-05-31 10:34:35 UTC
All platform were affected, it was fixed since 2.072.2 : https://run.dlang.io/is/ppM9hz