D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 15450 - ICE during CTFE of legit function
Summary: ICE during CTFE of legit function
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 major
Assignee: No Owner
URL:
Keywords: ice, pull
Depends on:
Blocks:
 
Reported: 2015-12-15 23:00 UTC by Andrei Alexandrescu
Modified: 2016-03-19 20:21 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 Andrei Alexandrescu 2015-12-15 23:00:22 UTC
Repro below fails with:

dmd: interpret.c:1034: Expression* interpret(FuncDeclaration*, InterState*, Expressions*, Expression*): Assertion `!e || (e->op != TOKcontinue && e->op != TOKbreak)' failed.

====================

struct BigO
{
    struct Atom
    {
        int id;
        double exp;
        double logExp;
    }

    private Atom[][] terms;

    int opCmp(const BigO rhs) const
    {
        int result = 0;
    bigone:
        foreach (ref l; terms)
        {
            foreach (ref r; rhs.terms)
            {
                if (l == r) continue bigone;
                if (smaller(l, r))
                {
                    if (result == 1) return 0;
                    if (result == 0) result = -1;
                    continue bigone;
                }
                if (smaller(r, l))
                {
                    if (result == -1) return 0;
                    if (result == 0) result = 1;
                    continue bigone;
                }
            }
            // Not comparable
            return 0;
        }
        return result;
    }

    private static bool smaller(const(Atom)[] lhs, const(Atom)[] rhs)
    {
        return 0;
    }
}

static immutable
    linear = BigO([ [ BigO.Atom(0, 1, 0) ] ]);

static assert(linear >= linear);
Comment 1 Andrei Alexandrescu 2015-12-15 23:01:37 UTC
Shorter repro. It's the labeled continue that's the problem:

struct BigO
{
    struct Atom
    {
        int id;
        double exp;
        double logExp;
    }

    private Atom[][] terms;

    int opCmp(const BigO rhs) const
    {
        int result = 0;
    bigone:
        foreach (ref l; terms)
        {
            foreach (ref r; rhs.terms)
            {
                continue bigone;
            }
        }
        return result;
    }
}

static immutable
    linear = BigO([ [ BigO.Atom(0, 1, 0) ] ]);

static assert(linear >= linear);
Comment 2 ag0aep6g 2015-12-15 23:21:51 UTC
2.069.2 gives "Error: cannot interpret <continue> at compile time", which is at least not an ICE.

git head (6cd7173) gives "core.exception.AssertError@dinterpret.d(1008): Assertion failure", making this a diagnostic regression.

Further reduced test case:
----
static assert({
    bigone: foreach (l; [0]) continue bigone;
    return true;
}());
----
Comment 3 Andrei Alexandrescu 2015-12-15 23:53:38 UTC
Nice, thanks. Hmmm, I was running v2.068.2. So should we qualify this as silently fixed?
Comment 4 Andrei Alexandrescu 2015-12-15 23:54:53 UTC
Oh wait, the HEAD doesn't work either (albeit with a different diagnostic). So this bug stands. Thanks!
Comment 5 Kenji Hara 2015-12-16 14:11:28 UTC
(In reply to ag0aep6g from comment #2)
> 2.069.2 gives "Error: cannot interpret <continue> at compile time", which is
> at least not an ICE.
> 
> git head (6cd7173) gives "core.exception.AssertError@dinterpret.d(1008):
> Assertion failure", making this a diagnostic regression.

From 2.069.0, released dmd binary is compiled with -release, so all of internal asserts won't hit.

Note that, ICE also happens with 2.068, like:

Assertion failure: '!e || (e->op != TOKcontinue && e->op != TOKbreak)' on line 1034 in file 'interpret.c'

abnormal program termination


Therefore, this is not a regression from 2.069.
Comment 7 github-bugzilla 2016-01-08 18:27:20 UTC
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/7d477b5be6e174a529fbeffceb61593624201897
Reboot #5312: fix Issue 15450 - ICE during CTFE of legit function

https://github.com/D-Programming-Language/dmd/commit/a540e39b75fc02b91fe448f52e242db5765723e3
Merge pull request #5336 from WalterBright/reboot5313

Reboot #5312: fix Issue 15450 - ICE during CTFE of legit function
Comment 8 github-bugzilla 2016-03-19 20:21:36 UTC
Commits pushed to stable at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/7d477b5be6e174a529fbeffceb61593624201897
Reboot #5312: fix Issue 15450 - ICE during CTFE of legit function

https://github.com/D-Programming-Language/dmd/commit/a540e39b75fc02b91fe448f52e242db5765723e3
Merge pull request #5336 from WalterBright/reboot5313