gcc.c (eval_spec_function): Finalize/restore the current string obstack state as...
authorOlivier Hainque <hainque@adacore.com>
Fri, 4 May 2012 08:03:54 +0000 (08:03 +0000)
committerOlivier Hainque <hainque@gcc.gnu.org>
Fri, 4 May 2012 08:03:54 +0000 (08:03 +0000)
        * gcc.c (eval_spec_function): Finalize/restore the current string
        obstack state as part of the context push/pop operations.

From-SVN: r187146

gcc/ChangeLog
gcc/gcc.c

index 746087a0aae5c93a577d2fe1ed0354c4d85211b2..7496a50a4cc4187b5ca601f0e38647b6fecdc371 100644 (file)
@@ -1,3 +1,8 @@
+2012-05-04  Olivier Hainque  <hainque@adacore.com>
+
+       * gcc.c (eval_spec_function): Finalize/restore the current string
+       obstack state as part of the context push/pop operations.
+
 2012-05-04  Bin Cheng  <bin.cheng@arm.com>
 
        PR rtl-optimization/52804
index 09f9b1548b8bbb819c046131cdfb7880fe6e0a75..e152b70539380bd75cbc1837cfba5a098d6793a1 100644 (file)
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -5313,6 +5313,8 @@ eval_spec_function (const char *func, const char *args)
   int save_this_is_linker_script;
   const char *save_suffix_subst;
 
+  int save_growing_size;
+  void *save_growing_value;
 
   sf = lookup_spec_function (func);
   if (sf == NULL)
@@ -5329,6 +5331,18 @@ eval_spec_function (const char *func, const char *args)
   save_input_from_pipe = input_from_pipe;
   save_suffix_subst = suffix_subst;
 
+  /* If we have some object growing now, finalize it so the args and function
+     eval proceed from a cleared context.  This is needed to prevent the first
+     constructed arg from mistakenly including the growing value.  We'll push
+     this value back on the obstack once the function evaluation is done, to
+     restore a consistent processing context for our caller.  This is fine as
+     the address of growing objects isn't guaranteed to remain stable until
+     they are finalized, and we expect this situation to be rare enough for
+     the extra copy not to be an issue.  */
+  save_growing_size = obstack_object_size (&obstack);
+  if (save_growing_size > 0)
+    save_growing_value = obstack_finish (&obstack);
+
   /* Create a new spec processing context, and build the function
      arguments.  */
 
@@ -5354,6 +5368,9 @@ eval_spec_function (const char *func, const char *args)
   input_from_pipe = save_input_from_pipe;
   suffix_subst = save_suffix_subst;
 
+  if (save_growing_size > 0)
+    obstack_grow (&obstack, save_growing_value, save_growing_size);
+
   return funcval;
 }