]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR fortran/86470 - ICE with OpenMP, class(*) allocatable
authorHarald Anlauf <anlauf@gmx.de>
Thu, 28 Jan 2021 09:13:46 +0000 (10:13 +0100)
committerHarald Anlauf <anlauf@gmx.de>
Thu, 28 Jan 2021 20:30:48 +0000 (21:30 +0100)
gfc_call_malloc should malloc an area of size 1 if no size given.

gcc/fortran/ChangeLog:

PR fortran/86470
* trans.c (gfc_call_malloc): Allocate area of size 1 if passed
size is NULL (as documented).

gcc/testsuite/ChangeLog:

PR fortran/86470
* gfortran.dg/gomp/pr86470.f90: New test.

(cherry picked from commit 33a7a93218b1393d0135e3c4a9ad9ced87808f5e)

gcc/fortran/trans.c
gcc/testsuite/gfortran.dg/gomp/pr86470.f90 [new file with mode: 0644]

index a1239ec2b538d5d9adc779c5cf294474c00206d7..4c197a0fbc108bbb593560d4a0772269ee2e86f0 100644 (file)
@@ -644,6 +644,9 @@ gfc_call_malloc (stmtblock_t * block, tree type, tree size)
   /* Call malloc.  */
   gfc_start_block (&block2);
 
+  if (size == NULL_TREE)
+    size = build_int_cst (size_type_node, 1);
+
   size = fold_convert (size_type_node, size);
   size = fold_build2_loc (input_location, MAX_EXPR, size_type_node, size,
                          build_int_cst (size_type_node, 1));
diff --git a/gcc/testsuite/gfortran.dg/gomp/pr86470.f90 b/gcc/testsuite/gfortran.dg/gomp/pr86470.f90
new file mode 100644 (file)
index 0000000..7e04437
--- /dev/null
@@ -0,0 +1,12 @@
+! { dg-do compile }
+! PR fortran/86470 - ICE with OpenMP, class(*)
+
+program p
+  implicit none
+  class(*), allocatable :: val
+!$OMP PARALLEL private(val)
+  allocate(integer::val)
+  val = 1
+  deallocate(val)
+!$OMP END PARALLEL
+end