D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 2560 - ICE(cod4.c) on invoking method that takes ref const struct parameter
Summary: ICE(cod4.c) on invoking method that takes ref const struct parameter
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
: 2561 2847 2969 (view as issue list)
Depends on:
Blocks:
 
Reported: 2009-01-06 23:26 UTC by Koroskin Denis
Modified: 2015-06-09 01:21 UTC (History)
6 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Koroskin Denis 2009-01-06 23:26:27 UTC
module bug;

struct S
{
    static S opCall()
    {
        S s;
        return s;
    }
}

void foo(ref const(S) s)
{
}

void bar()
{
    foo(S());
}

Output:
Internal error: ..\ztc\cod4.c 357

Note that this is a regression since DMD2.022
Comment 1 Sönke Ludwig 2009-01-07 04:16:32 UTC
*** Bug 2561 has been marked as a duplicate of this bug. ***
Comment 2 Stephan Dilly 2009-01-07 09:39:28 UTC
Wow this one really sucks. For me this makes nearly every D2 using project unbuildable since D2.023 ;(
Comment 3 dransic 2009-01-07 16:48:27 UTC
Though I'm not sure why, I guess this is related:

struct Foo { 
    int x, y, z; 
    this(int dummy) {}
}

invariant(Foo) createFoo() {
    return cast(invariant) Foo(0);
}

void main() {
    auto foo = createFoo;
}

causes the same compilation error without the -inline option. Compiles OK if I remove z, the constructor, or 'invariant' in the return type of createFoo.
Comment 4 Sönke Ludwig 2009-03-08 04:17:23 UTC
OK, it seems that the crash does not happen with DMD 2.026 anymore. Output is instead analogous to the second case in #2561. The test case in #2665 still crashes though. And another similar code snippet, too:

---
struct S { int x; }
const(S) f(){ return S(0); }
void g(){ int a = f().x; }
---
Comment 5 Don 2009-08-31 02:22:44 UTC
*** Issue 2847 has been marked as a duplicate of this issue. ***
Comment 6 Don 2009-08-31 02:25:02 UTC
*** Issue 2969 has been marked as a duplicate of this issue. ***
Comment 7 HOSOKAWA Kenchi 2009-08-31 02:41:10 UTC
(In reply to comment #5)
> *** Issue 2847 has been marked as a duplicate of this issue. ***

However I agree these issues are duplicate of this, don't forget specialty of real.
In Issue 2847, only real causes ICE, besides float and double do not.
Both const(struct) and const(real) may be behind assertion failure at cod4.c 35#.
Bugs about real have harmful effects on numeric computing, so that this point must be important for you.
Comment 8 Don 2009-08-31 02:52:15 UTC
(In reply to comment #7)
> (In reply to comment #5)
> > *** Issue 2847 has been marked as a duplicate of this issue. ***
> 
> However I agree these issues are duplicate of this, don't forget specialty of
> real.
> In Issue 2847, only real causes ICE, besides float and double do not.
> Both const(struct) and const(real) may be behind assertion failure at cod4.c
> 35#.
> Bugs about real have harmful effects on numeric computing, so that this point
> must be important for you.

The reason why it doesn't fail for float and double is that they have sizes of 4=int.sizeof and 8=long.sizeof, and get inlined at an earlier stage in the backend. So structs with size 1,2,4, and 8 are immune from the ICE. Real is size 10, so it ICEs. It's nothing to do with floating point at all.
Comment 9 HOSOKAWA Kenchi 2009-08-31 03:03:17 UTC
(In reply to comment #8)
> The reason why it doesn't fail for float and double is that they have sizes of
> 4=int.sizeof and 8=long.sizeof, and get inlined at an earlier stage in the
> backend. So structs with size 1,2,4, and 8 are immune from the ICE. Real is
> size 10, so it ICEs. It's nothing to do with floating point at all.

I am reassured by your good analysis. thank you.
Comment 10 Walter Bright 2009-09-03 13:34:17 UTC
Fixed dmd 2.032