Thread overview
gdc ice
Aug 09, 2023
Adam D Ruppe
Aug 09, 2023
Iain Buclaw
Aug 09, 2023
Adam D Ruppe
Aug 09, 2023
Adam D Ruppe
Aug 09, 2023
Iain Buclaw
August 09, 2023
$ gdc --version
gdc (GCC) 12.2.0
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.



$ gdc gdcbug.d
gdcbug.d: In function ‘D main’:
gdcbug.d:40:23: internal compiler error: in layout_aggregate_type, at d/types.cc:574
   40 |                 throw ArsdException!"Test"(4, "four");
      |                       ^
0x1bb6f56 internal_error(char const*, ...)
        ???:0
0x7a967a fancy_abort(char const*, int, char const*)
        ???:0
0x9bcb03 TypeVisitor::visit(TypeClass*)
        ???:0
0x9bb8c2 build_ctype(Type*)
        ???:0
0x9bc056 TypeVisitor::visit(TypeFunction*)
        ???:0
0x9bb8c2 build_ctype(Type*)
        ???:0
0x99fa34 get_decl_tree(Declaration*)
        ???:0
0x9a7e0c ExprVisitor::visit(VarExp*)
        ???:0
0x9a3b0f build_expr(Expression*, bool, bool)
        ???:0
0x9a5b13 ExprVisitor::visit(CallExp*)
        ???:0
0x9a3b0f build_expr(Expression*, bool, bool)
        ???:0
0x9a3bab build_expr_dtor(Expression*)
        ???:0
0x9b0250 IRVisitor::visit(ThrowStatement*)
        ???:0
0x9b0bc8 IRVisitor::visit(ScopeStatement*)
        ???:0
0x9b08c8 IRVisitor::visit(TryCatchStatement*)
        ???:0
0x9b016f IRVisitor::visit(CompoundStatement*)
        ???:0
0x9b016f IRVisitor::visit(CompoundStatement*)
        ???:0
0x9af85e build_function_body(FuncDeclaration*)
        ???:0
0x9a320a DeclVisitor::visit(FuncDeclaration*)
        ???:0
0x99d7c6 build_decl_tree(Dsymbol*)
        ???:0
Please submit a full bug report, with preprocessed source (by using -freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.






$ cat gdcbug.d
class ArsdExceptionBase : object.Exception {
        package this(string operation, string file = __FILE__, size_t line = __LINE__, Throwable next = null) {
                super(operation, file, line, next);
        }
}

template ArsdException(alias Type, DataTuple...) {
        static if(DataTuple.length)
                alias Parent = ArsdException!(Type, DataTuple[0 .. $-1]);
        else
                alias Parent = ArsdExceptionBase;

        class ArsdException : Parent {
                DataTuple data;

                this(DataTuple data, string file = __FILE__, size_t line = __LINE__) {
                        this.data = data;
                        static if(is(Parent == ArsdExceptionBase))
                                super(null, file, line);
                        else
                                super(data[0 .. $-1], file, line);
                }

                static opCall(R...)(R r, string file = __FILE__, size_t line = __LINE__) {
                        return new ArsdException!(Type, DataTuple, R)(r, file, line);
                }
        }
}

/// This example shows how you can throw and catch the ad-hoc exception types.
void main() {
        // 0 or 1 args works
        try {
                throw ArsdException!"Test"(1);
        } catch(ArsdException!"Test" e) { // catch it without them
        }

        // 2 or more args causes ice
        try {
                throw ArsdException!"Test"(4, "four");
        } catch(ArsdException!("Test", int, string) e) { // catch it and use info by specifying types
                assert(e.data[0] == 4); // and extract arguments like this
                assert(e.data[1] == "four");
        }
}
August 09, 2023

On Wednesday, 9 August 2023 at 11:48:41 UTC, Adam D Ruppe wrote:

>

$ cat gdcbug.d
class ArsdExceptionBase : object.Exception {
package this(string operation, string file = FILE, size_t line = LINE, Throwable next = null) {
super(operation, file, line, next);
}
}

template ArsdException(alias Type, DataTuple...) {
static if(DataTuple.length)
alias Parent = ArsdException!(Type, DataTuple[0 .. $-1]);
else
alias Parent = ArsdExceptionBase;

    class ArsdException : Parent {
            DataTuple data;

            this(DataTuple data, string file = __FILE__, size_t line = __LINE__) {
                    this.data = data;
                    static if(is(Parent == ArsdExceptionBase))
                            super(null, file, line);
                    else
                            super(data[0 .. $-1], file, line);
            }

            static opCall(R...)(R r, string file = __FILE__, size_t line = __LINE__) {
                    return new ArsdException!(Type, DataTuple, R)(r, file, line);
            }
    }

}

/// This example shows how you can throw and catch the ad-hoc exception types.
void main() {
// 0 or 1 args works
try {
throw ArsdException!"Test"(1);
} catch(ArsdException!"Test" e) { // catch it without them
}

    // 2 or more args causes ice
    try {
            throw ArsdException!"Test"(4, "four");
    } catch(ArsdException!("Test", int, string) e) { // catch it and use info by specifying types
            assert(e.data[0] == 4); // and extract arguments like this
            assert(e.data[1] == "four");
    }

}

Can you raise a bug report against gcc.gnu.org/bugzilla?

Only affects gdc-12.x - there's still time to fix before 12.4 is released.

==> gcc-9/gdc
arsd.d:19:38: error: constructor arsd.ArsdExceptionBase.this is not accessible from module arsd
   19 |                                 super(null, file, line);
      |                                      ^
==> gcc-10//gdc
arsd.d:19:38: error: constructor arsd.ArsdExceptionBase.this is not accessible from module arsd
   19 |                                 super(null, file, line);
      |                                      ^
==> gcc-11//gdc
arsd.d:34:43: error: template arsd.ArsdException!"Test".ArsdException.opCall cannot deduce function from argument types !()(int), candidates are:
   34 |                 throw ArsdException!"Test"(1);
      |                                           ^
==> gcc-12/gdc
arsd.d: In function ‘D main’:
arsd.d:40:23: internal compiler error: in layout_aggregate_type, at d/types.cc:574
   40 |                 throw ArsdException!"Test"(4, "four");
      |                       ^
0x7d507f layout_aggregate_type
	../../gcc/d/types.cc:574
...
==> gcc-13/gdc
OK!
==> gcc-mainline/gdc
OK!
August 09, 2023
On Wednesday, 9 August 2023 at 12:44:16 UTC, Iain Buclaw wrote:
> Can you raise a bug report against gcc.gnu.org/bugzilla?

yeah i just got the email approving the account a minute ago.

didn't take as long as i thought it would lol
August 09, 2023
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110959
August 09, 2023
On Wednesday, 9 August 2023 at 12:51:51 UTC, Adam D Ruppe wrote:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110959

Related DMD bug - the backporting of which looks like it'd fix your test case too. https://issues.dlang.org/show_bug.cgi?id=23010