D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 2665 - ICE(cod4.c) on certain const struct function return types
Summary: ICE(cod4.c) on certain const struct function return types
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Windows
: P2 regression
Assignee: No Owner
URL:
Keywords: ice-on-valid-code
: 3203 (view as issue list)
Depends on:
Blocks:
 
Reported: 2009-02-14 16:31 UTC by Stephan Dilly
Modified: 2017-07-02 13:24 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 Stephan Dilly 2009-02-14 16:31:10 UTC
struct S{
 byte[10] m_a; //byte[9] does not ice
}

S var;

const(S) getVar() //returning just S does not crash
{
 return var;
}

void main()
{
 const(S) foo = getVar();
}

crashes dmd with: Internal error: ..\ztc\cod4.c 357
Comment 1 Sönke Ludwig 2009-02-15 02:13:08 UTC
This is probably related to or a duplicate of #2560.
Comment 2 Don 2009-08-19 07:27:24 UTC
*** Issue 3203 has been marked as a duplicate of this issue. ***
Comment 3 HOSOKAWA Kenchi 2009-08-20 07:45:11 UTC
(In reply to comment #0)

here is (probably) another case of this problem.

struct A {}

struct B {
	const A a;
}

B f() {
	return B(A());
}

Internal error: ..\ztc\cod4.c 354 @ DMD2.031



"const(struct)" is the common component for the issues related to ICE(cod4.c) 35#.
Here is a list of problematic code:
In the function "cdeq" which generates code for an assignment

 sz = tysize[tyml];
 assert((int)sz > 0); <- failed this assertion.

where tyml is a type of lvalue, sz represents # of bytes to transfer.

This issue is apparently due to bypass of type-size{tysize} registration for const(struct), besides registration for struct itself is done.
Comment 4 Don 2009-08-26 00:56:09 UTC
(In reply to comment #3)
> "const(struct)" is the common component for the issues related to ICE(cod4.c)
> 35#.
> Here is a list of problematic code:
> In the function "cdeq" which generates code for an assignment
> 
>  sz = tysize[tyml];
>  assert((int)sz > 0); <- failed this assertion.
> 
> where tyml is a type of lvalue, sz represents # of bytes to transfer.
> 
> This issue is apparently due to bypass of type-size{tysize} registration for
> const(struct), besides registration for struct itself is done.

A variation of that test case is interesting:
struct A {}
struct B {
    const A a;
}

void f() {
    //A a;    // ---- if you uncomment this, it doesn't ICE!
    B b = B(A());
}
Comparing the intermediate code using elem_print(e); shows that there's a difference between the two cases by the start of codelem().
 But there's no difference in the code generated by DeclarationExp::toElem() in e2ir.c. Somewhere between the two, an optimisation/rewriting step is performed in the correct case, but not in the ICE case. I haven't yet worked out where it happens.
Comment 5 Don 2009-08-31 02:18:24 UTC
Like 2560, this is a regression between 2.022 and 2.023. It's clearly the same bug.
Comment 6 Walter Bright 2009-09-03 13:35:07 UTC
Fixed dmd 2.032