Bug creation and email sending has been disabled, file new bugs at gcc.gnu.org/bugzilla
Bug 242 - [ICE] (const_hash_1) varasm.c:2912: Segmentation fault
Summary: [ICE] (const_hash_1) varasm.c:2912: Segmentation fault
Status: RESOLVED FIXED
Alias: None
Product: GDC
Classification: Unclassified
Component: gdc (show other bugs)
Version: development
Hardware: All All
: --- normal
Assignee: Iain Buclaw
URL:
Depends on:
Blocks:
 
Reported: 2016-10-02 17:03 CEST by Iain Buclaw
Modified: 2016-10-03 20:15 CEST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Iain Buclaw 2016-10-02 17:03:27 CEST
Test case.
---
struct Thing
{
    enum Instance = Thing();
    void iter() { }
}

void test()
{
    return Thing.Instance.iter;
}
---

Does not happen if the return statement is removed.
---
struct Thing
{
    enum Instance = Thing();
    void iter() { }
}
void test()
{
    Thing.Instance.iter;
}
---
Comment 1 Iain Buclaw 2016-10-02 17:48:21 CEST
In the bad code, the frontend gives us a CallExp for:

   Instance.iter()

In the good code, the frontend gives us a CallExp for:

   Thing().iter()

Regardless of this slight difference between what should be identical code, the ICE in the deep backend is because DECL_INITIAL was never generated where one was expected.

There is a comment relating to debug emission in VarDeclaration::toObjFile.

   CONST_DECL was initially intended for enumerals and may be used for scalars in general but not for aggregates.

This is still true as far as debugging is concerned, although for simple aggregates (without pointers) they are represented just fine in gdb as of 7.11, but we should probably generate an initializer anyway on the basis that it might be used.
Comment 2 Iain Buclaw 2016-10-02 18:53:07 CEST
There is a second consideration.

---
struct Thing
{
    enum Instance = Thing();
    int a = 42;

    void iter()
    {
        this.a = 24;
    }
}

auto test()
{
    return Thing.Instance.iter;
}
---

This should not try to overwrite read-only data.  If taking the address of a CONST_DECL, it should either be that DECL_INITIAL is used directly, or internally rewrite the decl as a normal VAR_DECL.