driver: Also prune joined switches with negation
authorH.J. Lu <hongjiu.lu@intel.com>
Sat, 23 Feb 2019 19:39:35 +0000 (19:39 +0000)
committerH.J. Lu <hjl@gcc.gnu.org>
Sat, 23 Feb 2019 19:39:35 +0000 (11:39 -0800)
When -march=native is passed to host_detect_local_cpu to the backend,
it overrides all command lines after it.  That means

$ gcc -march=native -march=skylake-avx512

is the treated as

$ gcc -march=skylake-avx512 -march=native

Prune joined switches with Negative and RejectNegative to allow
-march=skylake-avx512 to override previous -march=native on command-line.

gcc/

PR driver/69471
* opts-common.c (prune_options): Also prune joined switches
with Negative and RejectNegative.
* config/i386/i386.opt (march=): Add Negative(march=).
(mtune=): Add Negative(mtune=).
* doc/options.texi: Document Negative used together with Joined
and RejectNegative.

gcc/testsuite/

PR driver/69471
* gcc.dg/pr69471-1.c: New test.
* gcc.dg/pr69471-2.c: Likewise.
* gcc.target/i386/pr69471-3.c: Likewise.

From-SVN: r269164

gcc/ChangeLog
gcc/config/i386/i386.opt
gcc/doc/options.texi
gcc/opts-common.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr69471-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr69471-2.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/pr69471-3.c [new file with mode: 0644]

index 77e2e8316a42a3f69c2bdf34a842ad30e7eb6c2a..78d5e9962bbf063e88029b3d3edd09db0b75f95e 100644 (file)
@@ -1,3 +1,13 @@
+2019-02-23  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR driver/69471
+       * opts-common.c (prune_options): Also prune joined switches
+       with Negative and RejectNegative.
+       * config/i386/i386.opt (march=): Add Negative(march=).
+       (mtune=): Add Negative(mtune=).
+       * doc/options.texi: Document Negative used together with Joined
+       and RejectNegative.
+
 2019-02-22  Martin Sebor  <msebor@redhat.com>
 
        * doc/extend.texi (Other Builtins): Add
index 9b93241f7903108d1e275e0c428db5dfa817c67a..b7998ee736327c31e9077a9ab2ee6f8ccde8066f 100644 (file)
@@ -253,7 +253,7 @@ EnumValue
 Enum(ix86_align_data) String(cacheline) Value(ix86_align_data_type_cacheline)
 
 march=
-Target RejectNegative Joined Var(ix86_arch_string)
+Target RejectNegative Negative(march=) Joined Var(ix86_arch_string)
 Generate code for given CPU.
 
 masm=
@@ -510,7 +510,7 @@ Target Report Mask(TLS_DIRECT_SEG_REFS)
 Use direct references against %gs when accessing tls data.
 
 mtune=
-Target RejectNegative Joined Var(ix86_tune_string)
+Target RejectNegative Negative(mtune=) Joined Var(ix86_tune_string)
 Schedule code for given CPU.
 
 mtune-ctrl=
index 0081243acab8032d2b68348b32ec1013e507f3bb..1c83d24148818133f0854020c0d7f9c8dbba7798 100644 (file)
@@ -220,7 +220,11 @@ property is used.
 The option will turn off another option @var{othername}, which is
 the option name with the leading ``-'' removed.  This chain action will
 propagate through the @code{Negative} property of the option to be
-turned off.
+turned off.  The driver will prune options, removing those that are
+turned off by some later option.  This pruning is not done for options
+with @code{Joined} or @code{JoinedOrMissing} properties, unless the
+options have either @code{RejectNegative} property or the @code{Negative}
+property mentions an option other than itself.
 
 As a consequence, if you have a group of mutually-exclusive
 options, their @code{Negative} properties should form a circular chain.
index ee8898b22ec93c276b4663aaf1f09362864c57e3..edbb3ac9b6d04580afbdcc29c67b4601360108da 100644 (file)
@@ -1015,7 +1015,9 @@ prune_options (struct cl_decoded_option **decoded_options,
            goto keep;
 
          /* Skip joined switches.  */
-         if ((option->flags & CL_JOINED))
+         if ((option->flags & CL_JOINED)
+             && (!option->cl_reject_negative
+                 || (unsigned int) option->neg_index != opt_idx))
            goto keep;
 
          for (j = i + 1; j < old_decoded_options_count; j++)
@@ -1027,8 +1029,11 @@ prune_options (struct cl_decoded_option **decoded_options,
                continue;
              if (cl_options[next_opt_idx].neg_index < 0)
                continue;
-             if ((cl_options[next_opt_idx].flags & CL_JOINED))
-                 continue;
+             if ((cl_options[next_opt_idx].flags & CL_JOINED)
+                 && (!cl_options[next_opt_idx].cl_reject_negative
+                     || ((unsigned int) cl_options[next_opt_idx].neg_index
+                         != next_opt_idx)))
+               continue;
              if (cancel_option (opt_idx, next_opt_idx, next_opt_idx))
                break;
            }
index 958564ac8b002e98cb27c33207928346f5277b42..d0520fb0547cd396e8bb3dc341a9cfd26aa73eac 100644 (file)
@@ -1,3 +1,10 @@
+2019-02-23  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR driver/69471
+       * gcc.dg/pr69471-1.c: New test.
+       * gcc.dg/pr69471-2.c: Likewise.
+       * gcc.target/i386/pr69471-3.c: Likewise.
+
 2019-02-23  Jerry DeLisle <jvdelisle@gcc.gnu.org>
 
        PR fortran/84387
diff --git a/gcc/testsuite/gcc.dg/pr69471-1.c b/gcc/testsuite/gcc.dg/pr69471-1.c
new file mode 100644 (file)
index 0000000..3eac3b5
--- /dev/null
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+/* { dg-options "-Wno-implicit-function-declaration -Wno-int-conversion -fno-builtin-free -fno-builtin-malloc" } */
+
+void *
+foo (void * p)
+{
+  free (p);
+  return malloc (p);
+}
diff --git a/gcc/testsuite/gcc.dg/pr69471-2.c b/gcc/testsuite/gcc.dg/pr69471-2.c
new file mode 100644 (file)
index 0000000..d579960
--- /dev/null
@@ -0,0 +1,8 @@
+/* { dg-do compile } */
+/* { dg-options "-gstabs2 -gdwarf-4 -gstabs3" } */
+/* { dg-error "conflicts with prior selectio" "" { target *-*-* } 0 } */
+
+void
+foo (void)
+{
+}
diff --git a/gcc/testsuite/gcc.target/i386/pr69471-3.c b/gcc/testsuite/gcc.target/i386/pr69471-3.c
new file mode 100644 (file)
index 0000000..3826f96
--- /dev/null
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-march=native -march=knl" } */
+
+/* NB: We want to verify that -march=native -march=processor is the same
+   as -march=processor.  Since it is very unlikely that GCC will be built
+   on KNL, -march=native will have -mno-avx512er and -march=knl should
+   enable AVX512ER.  */
+
+#ifndef __AVX512ER__
+# error __AVX512ER__ is not defined
+#endif