From: Iain Buclaw Date: Tue, 17 Nov 2020 09:48:41 +0000 (+0100) Subject: d: Fix a couple of ICEs found in the dmd front-end (PR97842) X-Git-Tag: releases/gcc-10.3.0~622 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7e6dbe4e571a375330beb4266813006dc474b716;p=thirdparty%2Fgcc.git d: Fix a couple of ICEs found in the dmd front-end (PR97842) - Segmentation fault on incomplete static if. - Segmentation fault resolving typeof() expression when gagging is on. gcc/d/ChangeLog: PR d/97842 * dmd/cond.c (StaticIfCondition::include): Return error if condition expression is unset. * dmd/mtype.c (TypeTypeof::resolve): Return error if scope is unset. gcc/testsuite/ChangeLog: PR d/97842 * gdc.test/fail_compilation/fail18970.d: New test. * gdc.test/fail_compilation/imports/test21164a.d: New test. * gdc.test/fail_compilation/imports/test21164b.d: New test. * gdc.test/fail_compilation/imports/test21164c.d: New test. * gdc.test/fail_compilation/imports/test21164d.d: New test. * gdc.test/fail_compilation/test21164.d: New test. (cherry picked from commit 27d8c3516b67c0f5a8fe8970d0558ee3b97e8281) --- diff --git a/gcc/d/dmd/cond.c b/gcc/d/dmd/cond.c index 1267199d4e16..b021f62c29b1 100644 --- a/gcc/d/dmd/cond.c +++ b/gcc/d/dmd/cond.c @@ -717,6 +717,10 @@ int StaticIfCondition::include(Scope *sc, ScopeDsymbol *sds) sc->sds = sds; // sds gets any addMember() bool errors = false; + + if (!exp) + goto Lerror; + bool result = evalStaticCondition(sc, exp, exp, errors); sc->pop(); diff --git a/gcc/d/dmd/mtype.c b/gcc/d/dmd/mtype.c index 3fb16e000ef7..c11772a7740a 100644 --- a/gcc/d/dmd/mtype.c +++ b/gcc/d/dmd/mtype.c @@ -7319,6 +7319,12 @@ void TypeTypeof::resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsymbol //printf("TypeTypeof::resolve(sc = %p, idents = '%s')\n", sc, toChars()); //static int nest; if (++nest == 50) *(char*)0=0; + if (sc == NULL) + { + *pt = Type::terror; + error(loc, "Invalid scope."); + return; + } if (inuse) { inuse = 2; diff --git a/gcc/testsuite/gdc.test/fail_compilation/fail18970.d b/gcc/testsuite/gdc.test/fail_compilation/fail18970.d new file mode 100644 index 000000000000..846a5782d7d1 --- /dev/null +++ b/gcc/testsuite/gdc.test/fail_compilation/fail18970.d @@ -0,0 +1,37 @@ +/* +TEST_OUTPUT: +--- +fail_compilation/fail18970.d(22): Error: no property `y` for type `fail18970.S` +fail_compilation/fail18970.d(29): Error: no property `yyy` for type `fail18970.S2` +--- +*/ + +// https://issues.dlang.org/show_bug.cgi?id=18970 + +struct S +{ + auto opDispatch(string name)(int) + { + alias T = typeof(x); + static assert(!is(T.U)); + return 0; + } +} +void f() +{ + S().y(1); +} + +struct S2 +{ + this(int) + { + this.yyy; + } + + auto opDispatch(string name)() + { + alias T = typeof(x); + static if(is(T.U)) {} + } +} diff --git a/gcc/testsuite/gdc.test/fail_compilation/imports/test21164a.d b/gcc/testsuite/gdc.test/fail_compilation/imports/test21164a.d new file mode 100644 index 000000000000..e5fcd43595ea --- /dev/null +++ b/gcc/testsuite/gdc.test/fail_compilation/imports/test21164a.d @@ -0,0 +1,9 @@ +struct D(E) +{ + void G() { + import imports.test21164d; + I; + } + +} + diff --git a/gcc/testsuite/gdc.test/fail_compilation/imports/test21164b.d b/gcc/testsuite/gdc.test/fail_compilation/imports/test21164b.d new file mode 100644 index 000000000000..ece5476654e0 --- /dev/null +++ b/gcc/testsuite/gdc.test/fail_compilation/imports/test21164b.d @@ -0,0 +1,4 @@ +import imports.test21164c; +enum N = O(); +alias Q = R!(N, S); + diff --git a/gcc/testsuite/gdc.test/fail_compilation/imports/test21164c.d b/gcc/testsuite/gdc.test/fail_compilation/imports/test21164c.d new file mode 100644 index 000000000000..21a252f5036b --- /dev/null +++ b/gcc/testsuite/gdc.test/fail_compilation/imports/test21164c.d @@ -0,0 +1,10 @@ +enum S = 1; + +struct O +{ +} + +struct R(O U, int W) +{ +} + diff --git a/gcc/testsuite/gdc.test/fail_compilation/imports/test21164d.d b/gcc/testsuite/gdc.test/fail_compilation/imports/test21164d.d new file mode 100644 index 000000000000..08f83ea91f7d --- /dev/null +++ b/gcc/testsuite/gdc.test/fail_compilation/imports/test21164d.d @@ -0,0 +1,9 @@ +auto AB() +{ +static if} + +auto I() +{ +AB; +} + diff --git a/gcc/testsuite/gdc.test/fail_compilation/test21164.d b/gcc/testsuite/gdc.test/fail_compilation/test21164.d new file mode 100644 index 000000000000..f42c4bc9d15c --- /dev/null +++ b/gcc/testsuite/gdc.test/fail_compilation/test21164.d @@ -0,0 +1,13 @@ +/* +TEST_OUTPUT: +--- +fail_compilation/imports/test21164d.d(3): Error: (expression) expected following `static if` +fail_compilation/imports/test21164d.d(3): Error: found `}` instead of statement +fail_compilation/test21164.d(11): Error: template instance `test21164a.D!(R!(O(), 1))` error instantiating +--- +*/ +import imports.test21164a; +import imports.test21164b; +auto GB(D!Q) +{ +}