diff mbox series

[PR,preprocessor/90927] Fixe dependency output

Message ID 25878fdb-0ef0-aab4-4caf-a45ccb9e9587@acm.org
State New
Headers show
Series [PR,preprocessor/90927] Fixe dependency output | expand

Commit Message

Nathan Sidwell June 26, 2019, 12:57 p.m. UTC
this patch fixes 90927.  The assert triggers when the user uses both -MT 
and -MQ target options in an unfortunate order.  I had thought about 
this and thought users wouldn't use both.  You'd think by now that I've 
learnt the answer to 'Would a user ever do $X?', is 'Yes, of course they 
will'.  Heck, they do things I can't even imagine!

applying to trunk
diff mbox series

Patch

2019-06-26  Nathan Sidwell  <nathan@acm.org>

	libcpp/
	PR preprocessor/90927
	* mkdeps.c (mkdeps::vec::operator[]): Add non-const variant.
	(deps_add_target): Deal with out of order unquoted targets.

	gcc/testsuite/
	* c-c++-common/pr90927.c: New.


Index: libcpp/mkdeps.c
===================================================================
--- libcpp/mkdeps.c	(revision 272688)
+++ libcpp/mkdeps.c	(working copy)
@@ -60,4 +60,8 @@  public:
       return ary[ix];
     }
+    T &operator[] (unsigned ix)
+    {
+      return ary[ix];
+    }
     void push (const T &elt)
     {
@@ -236,12 +240,20 @@  void
 deps_add_target (struct mkdeps *d, const char *t, int quote)
 {
-  t = apply_vpath (d, t);
+  t = xstrdup (apply_vpath (d, t));
+
   if (!quote)
     {
-      gcc_assert (d->quote_lwm == d->targets.size ());
+      /* Sometimes unquoted items are added after quoted ones.
+	 Swap out the lowest quoted.  */
+      if (d->quote_lwm != d->targets.size ())
+	{
+	  const char *lowest = d->targets[d->quote_lwm];
+	  d->targets[d->quote_lwm] = t;
+	  t = lowest;
+	}
       d->quote_lwm++;
     }
 
-  d->targets.push (xstrdup (t));
+  d->targets.push (t);
 }
 
Index: gcc/testsuite/c-c++-common/pr90927.c
===================================================================
--- gcc/testsuite/c-c++-common/pr90927.c	(revision 0)
+++ gcc/testsuite/c-c++-common/pr90927.c	(working copy)
@@ -0,0 +1,6 @@ 
+/* { dg-do preprocess } */
+/* { dg-additional-options "-M -MQ b\\\$ob -MT b\\\$ill" } */
+
+int i;
+
+/* { dg-final { scan-file pr90927.i {b\$ill b\$\$ob:} } } */