Hi, This patch backports the individual fix for PR116373 from the upstream merge in r15-6559-g332cf038fda109 into the releases/gcc-14 branch.
Bootstrapped and regression tested on x86_64-linux-gnu/-m32, and committed to branch. Regards, Iain. --- PR d/116373 gcc/d/ChangeLog: * dmd/expressionsem.d (resolveLoc): Check for null pointer before resolving bounds of slice. gcc/testsuite/ChangeLog: * gdc.dg/pr116373.d: New test. (cherry picked from commit c7dab40d7569c51ac4e62ceea05c7c049da426bb) --- gcc/d/dmd/expressionsem.d | 6 ++++-- gcc/testsuite/gdc.dg/pr116373.d | 8 ++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gdc.dg/pr116373.d diff --git a/gcc/d/dmd/expressionsem.d b/gcc/d/dmd/expressionsem.d index 7ae7f400d16..a6425d31143 100644 --- a/gcc/d/dmd/expressionsem.d +++ b/gcc/d/dmd/expressionsem.d @@ -15331,8 +15331,10 @@ Expression resolveLoc(Expression exp, const ref Loc loc, Scope* sc) Expression visitSlice(SliceExp exp) { exp.e1 = exp.e1.resolveLoc(loc, sc); - exp.lwr = exp.lwr.resolveLoc(loc, sc); - exp.upr = exp.upr.resolveLoc(loc, sc); + if (exp.lwr) + exp.lwr = exp.lwr.resolveLoc(loc, sc); + if (exp.upr) + exp.upr = exp.upr.resolveLoc(loc, sc); return exp; } diff --git a/gcc/testsuite/gdc.dg/pr116373.d b/gcc/testsuite/gdc.dg/pr116373.d new file mode 100644 index 00000000000..b58863bacf2 --- /dev/null +++ b/gcc/testsuite/gdc.dg/pr116373.d @@ -0,0 +1,8 @@ +// { dg-do compile } +int[] x; + +void foo (int[] y = x[]) {} + +void main () { + foo(); +} -- 2.43.0