On Fri, Jan 10, 2025 at 05:19:34PM +0000, Paul Richard Thomas wrote:
> 
> As of today, Gerhard Steinmetz has no fewer than 33 regressions to his name
> out of a total of 54 for fortran and libgfortran. It's time that some of
> these bugs are swatted, I think :-)
> 

This patch fixes PR71844.  As the error message indicates,
the source-expr in 'allocate(x, source=null())' cannot
be null().

diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc
index dab0c3af601..538917fe56a 100644
--- a/gcc/fortran/resolve.cc
+++ b/gcc/fortran/resolve.cc
@@ -8965,6 +8965,13 @@ resolve_allocate_expr (gfc_expr *e, gfc_code *code, bool 
*array_alloc_wo_spec)
   gfc_component *c;
   bool t;
 
+  /* source-expr in either SOURCE= or MODE= cannot be NULL().  */
+  if (code->expr3 && code->expr3->expr_type == EXPR_NULL)
+    {
+      gfc_error ("Source-expr at %L cannot be NULL()", &code->expr3->where);
+      goto failure;
+    }
+
   /* Mark the utmost array component as being in allocate to allow DIMEN_STAR
      checking of coarrays.  */
   for (ref = e->ref; ref; ref = ref->next)
diff --git a/gcc/testsuite/gfortran.dg/pr71844.f90 
b/gcc/testsuite/gfortran.dg/pr71844.f90
new file mode 100644
index 00000000000..af990f32fbb
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr71844.f90
@@ -0,0 +1,10 @@
+!
+! { dg-do compile }
+!
+program p
+   class(*), allocatable :: x, y
+   character(:), allocatable :: z
+   allocate (x, source=null())   ! { dg-error "cannot be NULL" }
+   allocate (y, mold=null())     ! { dg-error "cannot be NULL" }
+   allocate (character(*) :: z)  ! { dg-error "Incompatible allocate-object" }
+end



-- 
Steve

Reply via email to