On Thu, Feb 14, 2019 at 12:15:53AM +0100, Jakub Jelinek wrote:
> On Wed, Feb 13, 2019 at 03:08:01PM -0800, H.J. Lu wrote:
> > > How does this test verify that both -fno-builtin-* options are in effect?
> > > That is, how does it fail if you remove either or both of those options?
> > >
> > 
> > Without -fno-builtin-free -fno-builtin-malloc
> 
> As you haven't discovered any ubsan/asan etc. failures, I guess I'll add
> a test for similar thing with -fsanitize=signed-integer-overflow 
> -fsanitize=shift
> and similar (two -fsanitize-recover=, two -fno-sanitize=, two
> -fno-sanitize-recover=).  But I can do that incrementally.
> There is
> c-c++-common/ubsan/attrib-2.c:/* { dg-options "-fsanitize=undefined 
> -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow" } */
> but it doesn't actually test all of those are instrumented.
> 

Tested on x86-64.  OK for trunk?

Thanks.

H.J.
---
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/config/i386/i386.opt         |  4 ++--
 gcc/doc/options.texi             |  5 ++++-
 gcc/opts-common.c                | 11 ++++++++---
 gcc/testsuite/gcc.dg/pr69471-1.c |  9 +++++++++
 gcc/testsuite/gcc.dg/pr69471-2.c |  8 ++++++++
 5 files changed, 31 insertions(+), 6 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/pr69471-1.c
 create mode 100644 gcc/testsuite/gcc.dg/pr69471-2.c

diff --git a/gcc/config/i386/i386.opt b/gcc/config/i386/i386.opt
index 9b93241f790..b7998ee7363 100644
--- a/gcc/config/i386/i386.opt
+++ b/gcc/config/i386/i386.opt
@@ -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=
diff --git a/gcc/doc/options.texi b/gcc/doc/options.texi
index 0081243acab..6b29d56de62 100644
--- a/gcc/doc/options.texi
+++ b/gcc/doc/options.texi
@@ -227,7 +227,10 @@ options, their @code{Negative} properties should form a 
circular chain.
 For example, if options @option{-@var{a}}, @option{-@var{b}} and
 @option{-@var{c}} are mutually exclusive, their respective @code{Negative}
 properties should be @samp{Negative(@var{b})}, @samp{Negative(@var{c})}
-and @samp{Negative(@var{a})}.
+and @samp{Negative(@var{a})}.  @code{Negative} can be used together
+with @code{Joined} if there is no @code{RejectNegative} property.
+@code{Negative} is ignored if there is @code{Joined} without
+@code{RejectNegative}.
 
 @item Joined
 @itemx Separate
diff --git a/gcc/opts-common.c b/gcc/opts-common.c
index ee8898b22ec..edbb3ac9b6d 100644
--- a/gcc/opts-common.c
+++ b/gcc/opts-common.c
@@ -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;
            }
diff --git a/gcc/testsuite/gcc.dg/pr69471-1.c b/gcc/testsuite/gcc.dg/pr69471-1.c
new file mode 100644
index 00000000000..3eac3b5bdbc
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr69471-1.c
@@ -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
index 00000000000..d5799604b36
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr69471-2.c
@@ -0,0 +1,8 @@
+/* { dg-do compile } */
+/* { dg-options "-gstabs2 -gdwarf-4 -gstabs3" } */
+/* { dg-error "conflicts with prior selectio" "" { target *-*-* } 0 } */
+
+void
+foo (void)
+{
+}
-- 
2.20.1

Reply via email to