PR fortran/102520 - [10/11/12 Regression] ICE in expand_constructor, at fortran/array.c:1802
Commit Message
Dear Fortranners,
Gerhard's testcase triggers a NULL pointer dereference during the
attempt to expand an invalid constructor. The simple and obvious
solution is to catch that case.
Regtested on x86_64-pc-linux-gnu. OK for all affected branches?
Thanks,
Harald
Comments
Hi Harald,
> Gerhard's testcase triggers a NULL pointer dereference during the
> attempt to expand an invalid constructor. The simple and obvious
> solution is to catch that case.
>
> Regtested on x86_64-pc-linux-gnu. OK for all affected branches?
OK.
Thanks for the patch!
Best regards
Thomas
Fortran: fix error recovery for invalid constructor
gcc/fortran/ChangeLog:
PR fortran/102520
* array.c (expand_constructor): Do not dereference NULL pointer.
gcc/testsuite/ChangeLog:
PR fortran/102520
* gfortran.dg/pr102520.f90: New test.
@@ -1798,6 +1805,9 @@ expand_constructor (gfc_constructor_base base)
e = c->expr;
+ if (e == NULL)
+ return false;
+
if (empty_constructor)
empty_ts = e->ts;
new file mode 100644
@@ -0,0 +1,12 @@
+! { dg-do compile }
+! PR fortran/102520 - ICE in expand_constructor, at fortran/array.c:1802
+
+program p
+ type t
+ end type
+ type(t), parameter :: a(4) = shape(1) ! { dg-error "Incompatible" }
+ type(t), parameter :: b(2,2) = reshape(a,[2,2]) ! { dg-error "Incompatible" }
+ type(t), parameter :: c(2,2) = transpose(b) ! { dg-error "Unclassifiable" }
+end
+
+! { dg-error "Different shape for array assignment" " " { target *-*-* } 7 }