diff mbox

[committed] Fix -Wunused-but-set-* in OpenMP array sections (PR c++/63249)

Message ID 20140925065525.GJ17454@tucnak.redhat.com
State New
Headers show

Commit Message

Jakub Jelinek Sept. 25, 2014, 6:55 a.m. UTC
Hi!

This patch ensures OpenMP array section low bound and length are considered
used for the purpose of -Wunused-but-set-* warnings.

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

2014-09-25  Jakub Jelinek  <jakub@redhat.com>

	PR c++/63249
	* semantics.c (handle_omp_array_sections_1): Call mark_rvalue_use
	on low_bound and length.

	* g++.dg/gomp/pr63249.C: New test.
	* c-c++-common/gomp/pr63249.c: New test.

2014-09-25  Thomas Schwinge  <thomas@codesourcery.com>

	PR c++/63249
	* c-parser.c (c_parser_omp_variable_list): Call mark_exp_read
	on low_bound and length.


	Jakub
diff mbox

Patch

--- gcc/c/c-parser.c.jj	2014-09-08 22:12:43.000000000 +0200
+++ gcc/c/c-parser.c	2014-09-24 16:13:24.004676260 +0200
@@ -9887,7 +9887,10 @@  c_parser_omp_variable_list (c_parser *pa
 
 		  c_parser_consume_token (parser);
 		  if (!c_parser_next_token_is (parser, CPP_COLON))
-		    low_bound = c_parser_expression (parser).value;
+		    {
+		      low_bound = c_parser_expression (parser).value;
+		      mark_exp_read (low_bound);
+		    }
 		  if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
 		    length = integer_one_node;
 		  else
@@ -9900,7 +9903,10 @@  c_parser_omp_variable_list (c_parser *pa
 			  break;
 			}
 		      if (!c_parser_next_token_is (parser, CPP_CLOSE_SQUARE))
-			length = c_parser_expression (parser).value;
+			{
+			  length = c_parser_expression (parser).value;
+			  mark_exp_read (length);
+			}
 		    }
 		  /* Look for the closing `]'.  */
 		  if (!c_parser_require (parser, CPP_CLOSE_SQUARE,
--- gcc/cp/semantics.c.jj	2014-09-23 17:19:23.000000000 +0200
+++ gcc/cp/semantics.c	2014-09-24 16:21:13.599185729 +0200
@@ -4290,6 +4290,10 @@  handle_omp_array_sections_1 (tree c, tre
 		length);
       return error_mark_node;
     }
+  if (low_bound)
+    low_bound = mark_rvalue_use (low_bound);
+  if (length)
+    length = mark_rvalue_use (length);
   if (low_bound
       && TREE_CODE (low_bound) == INTEGER_CST
       && TYPE_PRECISION (TREE_TYPE (low_bound))
--- gcc/testsuite/g++.dg/gomp/pr63249.C.jj	2014-09-24 16:56:08.394089019 +0200
+++ gcc/testsuite/g++.dg/gomp/pr63249.C	2014-09-24 17:16:41.298607777 +0200
@@ -0,0 +1,35 @@ 
+// PR c++/63249
+// { dg-do compile }
+// { dg-options "-Wall -W -fopenmp" }
+
+template <int N>
+int
+foo (int *v, int A, int B)	// { dg-bogus "set but not used" }
+{
+  int r = 0;
+  int a = 2;			// { dg-bogus "set but not used" }
+  int b = 4;			// { dg-bogus "set but not used" }
+#pragma omp target map(to: v[a:b])
+  r |= v[3];
+#pragma omp target map(to: v[A:B])
+  r |= v[3];
+  return r;
+}
+
+template <typename T>
+int
+bar (T *v, T A, T B)		// { dg-bogus "set but not used" }
+{
+  T r = 0, a = 2, b = 4;	// { dg-bogus "set but not used" }
+#pragma omp target map(to: v[a:b])
+  r |= v[3];
+#pragma omp target map(to: v[A:B])
+  r |= v[3];
+  return r;
+}
+
+int
+baz (int *v, int A, int B)
+{
+  return foo<0> (v, A, B) + bar (v, A, B);
+}
--- gcc/testsuite/c-c++-common/gomp/pr63249.c.jj	2014-09-24 16:55:42.635220164 +0200
+++ gcc/testsuite/c-c++-common/gomp/pr63249.c	2014-09-24 17:16:00.631823157 +0200
@@ -0,0 +1,16 @@ 
+/* PR c++/63249 */
+/* { dg-do compile } */
+/* { dg-options "-Wall -W -fopenmp" } */
+
+int
+foo (int *v, int A, int B)	/* { dg-bogus "set but not used" } */
+{
+  int r = 0;
+  int a = 2;			/* { dg-bogus "set but not used" } */
+  int b = 4;			/* { dg-bogus "set but not used" } */
+#pragma omp target map(to: v[a:b])
+  r |= v[3];
+#pragma omp target map(to: v[A:B])
+  r |= v[3];
+  return r;
+}