public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [gomp4.1] Two more array section testcases
@ 2015-10-09  9:14 Jakub Jelinek
  2015-10-09  9:34 ` [gomp4.1] Add negative length check even for pointers Jakub Jelinek
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2015-10-09  9:14 UTC (permalink / raw)
  To: gcc-patches

Hi!

The 4.0 spec required that low-bound in array section must not be negative.
The 4.5 spec removes that restriction, for arrays it is obvious that it is
invalid anyway (pointer arithmetics disallows that), and for pointers it is
meaningful.

After looking what I've implemented, it seems I've applied common sense
rather than strictly reading the standard.  And that is the behavior we want
for OpenMP 4.5, so I've just added new testcases to cover the various cases.

2015-10-09  Jakub Jelinek  <jakub@redhat.com>

	* c-c++-common/gomp/depend-4.c: New test.
	* c-c++-common/gomp/map-2.c: New test.

--- gcc/testsuite/c-c++-common/gomp/depend-4.c.jj	2015-10-09 11:04:54.676862229 +0200
+++ gcc/testsuite/c-c++-common/gomp/depend-4.c	2015-10-09 11:04:46.359979185 +0200
@@ -0,0 +1,26 @@
+/* { dg-do compile } */
+/* { dg-options "-fopenmp" } */
+
+void
+foo (int *p, int (*q)[10], int r[10], int s[10][10])
+{
+  int a[10], b[10][10];
+  #pragma omp task depend (inout: p[-1:2])
+  ;
+  #pragma omp task depend (inout: q[-1:2][2:4])
+  ;
+  #pragma omp task depend (inout: q[-1:2][-2:4]) /* { dg-error "negative low bound in array section in" } */
+  ;
+  #pragma omp task depend (inout: r[-1:2])
+  ;
+  #pragma omp task depend (inout: s[-1:2][2:4])
+  ;
+  #pragma omp task depend (inout: s[-1:2][-2:4]) /* { dg-error "negative low bound in array section in" } */
+  ;
+  #pragma omp task depend (inout: a[-1:2])	 /* { dg-error "negative low bound in array section in" } */
+  ;
+  #pragma omp task depend (inout: b[-1:2][2:4])	 /* { dg-error "negative low bound in array section in" } */
+  ;
+  #pragma omp task depend (inout: b[1:2][-2:4])	 /* { dg-error "negative low bound in array section in" } */
+  ;
+}
--- gcc/testsuite/c-c++-common/gomp/map-2.c.jj	2015-10-09 11:05:40.752214292 +0200
+++ gcc/testsuite/c-c++-common/gomp/map-2.c	2015-10-09 11:07:19.558824818 +0200
@@ -0,0 +1,26 @@
+/* { dg-do compile } */
+/* { dg-options "-fopenmp" } */
+
+void
+foo (int *p, int (*q)[10], int r[10], int s[10][10])
+{
+  int a[10], b[10][10];
+  #pragma omp target map (tofrom: p[-1:2])
+  ;
+  #pragma omp target map (tofrom: q[-1:2][0:10])
+  ;
+  #pragma omp target map (tofrom: q[-1:2][-2:10]) /* { dg-error "negative low bound in array section in" } */
+  ;
+  #pragma omp target map (tofrom: r[-1:2])
+  ;
+  #pragma omp target map (tofrom: s[-1:2][:])
+  ;
+  #pragma omp target map (tofrom: s[-1:2][-2:10]) /* { dg-error "negative low bound in array section in" } */
+  ;
+  #pragma omp target map (tofrom: a[-1:2])	 /* { dg-error "negative low bound in array section in" } */
+  ;
+  #pragma omp target map (tofrom: b[-1:2][0:])	 /* { dg-error "negative low bound in array section in" } */
+  ;
+  #pragma omp target map (tofrom: b[1:2][-2:10]) /* { dg-error "negative low bound in array section in" } */
+  ;
+}

	Jakub

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [gomp4.1] Add negative length check even for pointers
  2015-10-09  9:14 [gomp4.1] Two more array section testcases Jakub Jelinek
@ 2015-10-09  9:34 ` Jakub Jelinek
  0 siblings, 0 replies; 2+ messages in thread
From: Jakub Jelinek @ 2015-10-09  9:34 UTC (permalink / raw)
  To: gcc-patches

On Fri, Oct 09, 2015 at 11:14:33AM +0200, Jakub Jelinek wrote:
> The 4.0 spec required that low-bound in array section must not be negative.
> The 4.5 spec removes that restriction, for arrays it is obvious that it is
> invalid anyway (pointer arithmetics disallows that), and for pointers it is
> meaningful.
> 
> After looking what I've implemented, it seems I've applied common sense
> rather than strictly reading the standard.  And that is the behavior we want
> for OpenMP 4.5, so I've just added new testcases to cover the various cases.

The requirement that length is non-negative stays, for a reason, and
unfortunately it seems it has been only tested for arrays, not for pointers.

Thus I've applied this fix and added further tests.

2015-10-09  Jakub Jelinek  <jakub@redhat.com>

c/
	* c-typeck.c (handle_omp_array_sections_1): Diagnose negative
	length even for pointer based array sections.
cp/
	* semantics.c (handle_omp_array_sections_1): Diagnose negative
	length even for pointer based array sections.
testsuite/
	* c-c++-common/gomp/depend-4.c (main): Add tests for negative
	lengths.
	* c-c++-common/gomp/map-2.c (main): Likewise.

--- gcc/c/c-typeck.c.jj	2015-10-09 10:59:18.000000000 +0200
+++ gcc/c/c-typeck.c	2015-10-09 11:17:17.577429234 +0200
@@ -11889,6 +11889,15 @@ handle_omp_array_sections_1 (tree c, tre
 		    "for pointer type length expression must be specified");
 	  return error_mark_node;
 	}
+      if (length != NULL_TREE
+	  && TREE_CODE (length) == INTEGER_CST
+	  && tree_int_cst_sgn (length) == -1)
+	{
+	  error_at (OMP_CLAUSE_LOCATION (c),
+		    "negative length in array section in %qs clause",
+		    omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
+	  return error_mark_node;
+	}
       /* If there is a pointer type anywhere but in the very first
 	 array-section-subscript, the array section can't be contiguous.  */
       if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
--- gcc/cp/semantics.c.jj	2015-10-09 10:59:18.000000000 +0200
+++ gcc/cp/semantics.c	2015-10-09 11:19:37.057473471 +0200
@@ -4668,6 +4668,15 @@ handle_omp_array_sections_1 (tree c, tre
 		    "for pointer type length expression must be specified");
 	  return error_mark_node;
 	}
+      if (length != NULL_TREE
+	  && TREE_CODE (length) == INTEGER_CST
+	  && tree_int_cst_sgn (length) == -1)
+	{
+	  error_at (OMP_CLAUSE_LOCATION (c),
+		    "negative length in array section in %qs clause",
+		    omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
+	  return error_mark_node;
+	}
       /* If there is a pointer type anywhere but in the very first
 	 array-section-subscript, the array section can't be contiguous.  */
       if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
--- gcc/testsuite/c-c++-common/gomp/depend-4.c.jj	2015-10-09 11:04:46.000000000 +0200
+++ gcc/testsuite/c-c++-common/gomp/depend-4.c	2015-10-09 11:24:34.316305364 +0200
@@ -23,4 +23,22 @@ foo (int *p, int (*q)[10], int r[10], in
   ;
   #pragma omp task depend (inout: b[1:2][-2:4])	 /* { dg-error "negative low bound in array section in" } */
   ;
+  #pragma omp task depend (inout: p[2:-3])	 /* { dg-error "negative length in array section in" } */
+  ;
+  #pragma omp task depend (inout: q[2:-3][:])	 /* { dg-error "negative length in array section in" } */
+  ;
+  #pragma omp task depend (inout: q[2:3][0:-1])	 /* { dg-error "negative length in array section in" } */
+  ;
+  #pragma omp task depend (inout: r[2:-5])	 /* { dg-error "negative length in array section in" } */
+  ;
+  #pragma omp task depend (inout: s[2:-5][:])	 /* { dg-error "negative length in array section in" } */
+  ;
+  #pragma omp task depend (inout: s[2:5][0:-4])	 /* { dg-error "negative length in array section in" } */
+  ;
+  #pragma omp task depend (inout: a[2:-5])	 /* { dg-error "negative length in array section in" } */
+  ;
+  #pragma omp task depend (inout: b[2:-5][0:10]) /* { dg-error "negative length in array section in" } */
+  ;
+  #pragma omp task depend (inout: b[2:5][0:-4]) /* { dg-error "negative length in array section in" } */
+  ;
 }
--- gcc/testsuite/c-c++-common/gomp/map-2.c.jj	2015-10-09 11:07:19.000000000 +0200
+++ gcc/testsuite/c-c++-common/gomp/map-2.c	2015-10-09 11:25:03.097901794 +0200
@@ -23,4 +23,22 @@ foo (int *p, int (*q)[10], int r[10], in
   ;
   #pragma omp target map (tofrom: b[1:2][-2:10]) /* { dg-error "negative low bound in array section in" } */
   ;
+  #pragma omp target map (tofrom: p[2:-3])	 /* { dg-error "negative length in array section in" } */
+  ;
+  #pragma omp target map (tofrom: q[2:-3][:])	 /* { dg-error "negative length in array section in" } */
+  ;
+  #pragma omp target map (tofrom: q[2:3][0:-1])	 /* { dg-error "negative length in array section in" } */
+  ;
+  #pragma omp target map (tofrom: r[2:-5])	 /* { dg-error "negative length in array section in" } */
+  ;
+  #pragma omp target map (tofrom: s[2:-5][:])	 /* { dg-error "negative length in array section in" } */
+  ;
+  #pragma omp target map (tofrom: s[2:5][0:-4])	 /* { dg-error "negative length in array section in" } */
+  ;
+  #pragma omp target map (tofrom: a[2:-5])	 /* { dg-error "negative length in array section in" } */
+  ;
+  #pragma omp target map (tofrom: b[2:-5][0:10]) /* { dg-error "negative length in array section in" } */
+  ;
+  #pragma omp target map (tofrom: b[2:5][0:-4]) /* { dg-error "negative length in array section in" } */
+  ;
 }


	Jakub

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-10-09  9:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-09  9:14 [gomp4.1] Two more array section testcases Jakub Jelinek
2015-10-09  9:34 ` [gomp4.1] Add negative length check even for pointers Jakub Jelinek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).