diff mbox series

[committed] Fix ICE with invalid OpenMP linear clauses (PR fortran/84116)

Message ID 20180131204952.GQ2063@tucnak
State New
Headers show
Series [committed] Fix ICE with invalid OpenMP linear clauses (PR fortran/84116) | expand

Commit Message

Jakub Jelinek Jan. 31, 2018, 8:49 p.m. UTC
Hi!

If the gfc_match_omp_variable_list calls fail, they don't modify head,
so *head means referencing NULL.  In that case we don't really need to
free anything, nothing has been allocated, just need to emit a syntax error.

Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk.

2018-01-31  Jakub Jelinek  <jakub@redhat.com>

	PR fortran/84116
	* openmp.c (gfc_match_omp_clauses): If all the linear
	gfc_match_omp_variable_list calls failed, don't gfc_free_omp_namelist
	nor set *head = NULL.  Formatting fixes.

	* gfortran.dg/gomp/pr84116.f90: New test.


	Jakub
diff mbox series

Patch

--- gcc/fortran/openmp.c.jj	2018-01-03 10:20:22.629538350 +0100
+++ gcc/fortran/openmp.c	2018-01-31 18:10:35.455624605 +0100
@@ -1318,23 +1318,21 @@  gfc_match_omp_clauses (gfc_omp_clauses *
 	      else if (gfc_match_omp_variable_list (" val (",
 						    &c->lists[OMP_LIST_LINEAR],
 						    false, NULL, &head)
-		  == MATCH_YES)
+		       == MATCH_YES)
 		linear_op = OMP_LINEAR_VAL;
 	      else if (gfc_match_omp_variable_list (" uval (",
 						    &c->lists[OMP_LIST_LINEAR],
 						    false, NULL, &head)
-		  == MATCH_YES)
+		       == MATCH_YES)
 		linear_op = OMP_LINEAR_UVAL;
 	      else if (gfc_match_omp_variable_list ("",
 						    &c->lists[OMP_LIST_LINEAR],
 						    false, &end_colon, &head)
-		  == MATCH_YES)
+		       == MATCH_YES)
 		linear_op = OMP_LINEAR_DEFAULT;
 	      else
 		{
-		  gfc_free_omp_namelist (*head);
 		  gfc_current_locus = old_loc;
-		  *head = NULL;
 		  break;
 		}
 	      if (linear_op != OMP_LINEAR_DEFAULT)
--- gcc/testsuite/gfortran.dg/gomp/pr84116.f90.jj	2018-01-31 18:12:21.345637463 +0100
+++ gcc/testsuite/gfortran.dg/gomp/pr84116.f90	2018-01-31 18:11:59.401634803 +0100
@@ -0,0 +1,12 @@ 
+! PR fortran/84116
+! { dg-do compile }
+
+program pr84116
+   integer :: i, j
+   !$omp simd linear ((i))	! { dg-error "Syntax error" }
+   do i = 1, 2
+   end do
+   !$omp simd linear ()		! { dg-error "Syntax error" }
+   do j = 1, 2
+   end do
+end