[PATCH] Fix driver handling of multiple -ftree-parallelize-loops=<n> options (PR driver/69805)

Jakub Jelinek jakub@redhat.com
Tue Feb 16 15:24:00 GMT 2016


Hi!

As mentioned in the PR, %{ftree-parallelize-loops=*} expands to
all -ftree-parallelize-loops= options, not just the last one.
So greater_than_spec_func is actually called say for
-ftree-parallelize-loops=0 -ftree-parallelize-loops=2 with
- ftree-parallelize-loops=0 - ftree-parallelize-loops=2 1
(each whitespace separated sequence separate arg), but it asserts
it sees just 3 arguments.
Passing the - and ftree-parallelize-loops= stuff looks weird,
and we have %* that substitutes just the variable part of the option,
so in addition to fixing the case of multiple options I've also changed
%:gt() behaviour, so that it now gets just the numbers and compares the
last two of them.  So for the above options it would be called with
0 2 1
and would compare
2 > 1
and return "", or for
-ftree-parallelize-loops=2 -ftree-parallelize-loops=0 -ftree-parallelize-loops=1
would be
2 0 1 1
and compare
1 > 1
and return NULL. %:gt() is not used anywhere else, and has been introduced
only in GCC 6.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2016-02-16  Jakub Jelinek  <jakub@redhat.com>

	PR driver/69805
	* gcc.c (LINK_COMMAND_SPEC, GOMP_SELF_SPECS): Use
	:%* in %:gt() argument.
	(greater_than_spec_func): Adjust for expecting only numbers,
	if there are more than two numbers, compare the last two.

	* testsuite/libgomp.c/pr69805.c: New test.

--- gcc/gcc.c.jj	2016-02-15 22:22:51.000000000 +0100
+++ gcc/gcc.c	2016-02-16 09:35:03.579849080 +0100
@@ -1019,7 +1019,7 @@ proper position among the other output f
     %{s} %{t} %{u*} %{z} %{Z} %{!nostdlib:%{!nostartfiles:%S}} \
     %{static:} %{L*} %(mfwrap) %(link_libgcc) " \
     VTABLE_VERIFICATION_SPEC " " SANITIZER_EARLY_SPEC " %o " CHKP_SPEC " \
-    %{fopenacc|fopenmp|%:gt(%{ftree-parallelize-loops=*} 1):\
+    %{fopenacc|fopenmp|%:gt(%{ftree-parallelize-loops=*:%*} 1):\
 	%:include(libgomp.spec)%(link_gomp)}\
     %{fcilkplus:%:include(libcilkrts.spec)%(link_cilkrts)}\
     %{fgnu-tm:%:include(libitm.spec)%(link_itm)}\
@@ -1183,7 +1183,7 @@ static const char *const multilib_defaul
    for targets that use different start files and suchlike.  */
 #ifndef GOMP_SELF_SPECS
 #define GOMP_SELF_SPECS \
-  "%{fopenacc|fopenmp|%:gt(%{ftree-parallelize-loops=*} 1): " \
+  "%{fopenacc|fopenmp|%:gt(%{ftree-parallelize-loops=*:%*} 1): " \
   "-pthread}"
 #endif
 
@@ -9764,7 +9764,7 @@ replace_extension_spec_func (int argc, c
   return result;
 }
 
-/* Returns "" if the n in ARGV[1] == -opt=<n> is greater than ARGV[2].
+/* Returns "" if ARGV[ARGC - 2] is greater than ARGV[ARGC-1].
    Otherwise, return NULL.  */
 
 static const char *
@@ -9775,29 +9775,13 @@ greater_than_spec_func (int argc, const
   if (argc == 1)
     return NULL;
 
-  gcc_assert (argc == 3);
-  gcc_assert (argv[0][0] == '-');
-  gcc_assert (argv[0][1] == '\0');
-
-  /* Point p to <n> in in -opt=<n>.  */
-  const char *p = argv[1];
-  while (true)
-    {
-      char c = *p;
-      if (c == '\0')
-	gcc_unreachable ();
+  gcc_assert (argc >= 2);
 
-      ++p;
-
-      if (c == '=')
-	break;
-    }
-
-  long arg = strtol (p, &converted, 10);
-  gcc_assert (converted != p);
+  long arg = strtol (argv[argc - 2], &converted, 10);
+  gcc_assert (converted != argv[argc - 2]);
 
-  long lim = strtol (argv[2], &converted, 10);
-  gcc_assert (converted != argv[2]);
+  long lim = strtol (argv[argc - 1], &converted, 10);
+  gcc_assert (converted != argv[argc - 1]);
 
   if (arg > lim)
     return "";
--- libgomp/testsuite/libgomp.c/pr69805.c.jj	2016-02-16 09:54:46.928527601 +0100
+++ libgomp/testsuite/libgomp.c/pr69805.c	2016-02-16 09:55:29.453941023 +0100
@@ -0,0 +1,9 @@
+/* PR driver/69805 */
+/* { dg-do link } */
+/* { dg-options "-ftree-parallelize-loops=1 -O2 -ftree-parallelize-loops=2" } */
+
+int
+main ()
+{
+  return 0;
+}

	Jakub



More information about the Gcc-patches mailing list