aboutsummaryrefslogtreecommitdiff
path: root/gcc/opts.c
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2013-02-27 07:28:09 +0000
committerJakub Jelinek <jakub@redhat.com>2013-02-27 07:28:09 +0000
commite05fa4d72e050515eca0a49df08c32031c9dd8ff (patch)
treebd4cfc1abd9fbaa6e8743ef8ed88707b9b753706 /gcc/opts.c
parent73c24d77716845eef991aec87a04392fe5c637c1 (diff)
* opts.h: Include obstack.h.
(opts_concat): New prototype. (opts_obstack): New declaration. * opts.c (opts_concat): New function. (opts_obstack): New variable. (init_options_struct): Call gcc_init_obstack on opts_obstack. (finish_options): Use opts_concat instead of concat and XOBNEWVEC instead of XNEWVEC. * opts-common.c (generate_canonical_option, decode_cmdline_option, generate_option): Likewise. * Makefile.in (OPTS_H): Depend on $(OBSTACK_H). * lto-wrapper.c (main): Call gcc_init_obstack on opts_obstack. git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@196305 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/opts.c')
-rw-r--r--gcc/opts.c45
1 files changed, 41 insertions, 4 deletions
diff --git a/gcc/opts.c b/gcc/opts.c
index bd1b2dcfd35..d569b5e7e90 100644
--- a/gcc/opts.c
+++ b/gcc/opts.c
@@ -268,6 +268,40 @@ add_comma_separated_to_vector (void **pvec, const char *arg)
*pvec = v;
}
+/* Like libiberty concat, but allocate using opts_obstack. */
+
+char *
+opts_concat (const char *first, ...)
+{
+ char *newstr, *end;
+ size_t length = 0;
+ const char *arg;
+ va_list ap;
+
+ /* First compute the size of the result and get sufficient memory. */
+ va_start (ap, first);
+ for (arg = first; arg; arg = va_arg (ap, const char *))
+ length += strlen (arg);
+ newstr = XOBNEWVEC (&opts_obstack, char, length + 1);
+ va_end (ap);
+
+ /* Now copy the individual pieces to the result string. */
+ va_start (ap, first);
+ for (arg = first, end = newstr; arg; arg = va_arg (ap, const char *))
+ {
+ length = strlen (arg);
+ memcpy (end, arg, length);
+ end += length;
+ }
+ *end = '\0';
+ va_end (ap);
+ return newstr;
+}
+
+/* Obstack for option strings. */
+
+struct obstack opts_obstack;
+
/* Initialize OPTS and OPTS_SET before using them in parsing options. */
void
@@ -275,6 +309,8 @@ init_options_struct (struct gcc_options *opts, struct gcc_options *opts_set)
{
size_t num_params = get_num_compiler_params ();
+ gcc_obstack_init (&opts_obstack);
+
*opts = global_options_init;
memset (opts_set, 0, sizeof (*opts_set));
@@ -638,8 +674,8 @@ finish_options (struct gcc_options *opts, struct gcc_options *opts_set,
directory, typically the directory to contain the object
file. */
if (opts->x_dump_dir_name)
- opts->x_dump_base_name = concat (opts->x_dump_dir_name,
- opts->x_dump_base_name, NULL);
+ opts->x_dump_base_name = opts_concat (opts->x_dump_dir_name,
+ opts->x_dump_base_name, NULL);
else if (opts->x_aux_base_name
&& strcmp (opts->x_aux_base_name, HOST_BIT_BUCKET) != 0)
{
@@ -649,8 +685,9 @@ finish_options (struct gcc_options *opts, struct gcc_options *opts_set,
if (opts->x_aux_base_name != aux_base)
{
int dir_len = aux_base - opts->x_aux_base_name;
- char *new_dump_base_name =
- XNEWVEC (char, strlen (opts->x_dump_base_name) + dir_len + 1);
+ char *new_dump_base_name
+ = XOBNEWVEC (&opts_obstack, char,
+ strlen (opts->x_dump_base_name) + dir_len + 1);
/* Copy directory component from OPTS->X_AUX_BASE_NAME. */
memcpy (new_dump_base_name, opts->x_aux_base_name, dir_len);