ada/
[official-gcc.git] / gcc / fortran / options.c
blob1262ccc19aa019cde26ee4912dd0b1e719e830d0
1 /* Parse and display command line options.
2 Copyright (C) 2000-2015 Free Software Foundation, Inc.
3 Contributed by Andy Vaught
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
10 version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "hash-set.h"
25 #include "machmode.h"
26 #include "vec.h"
27 #include "double-int.h"
28 #include "input.h"
29 #include "alias.h"
30 #include "symtab.h"
31 #include "options.h"
32 #include "wide-int.h"
33 #include "inchash.h"
34 #include "tree.h"
35 #include "flags.h"
36 #include "intl.h"
37 #include "opts.h"
38 #include "toplev.h" /* For save_decoded_options. */
39 #include "params.h"
40 #include "tree-inline.h"
41 #include "gfortran.h"
42 #include "target.h"
43 #include "cpp.h"
44 #include "diagnostic.h" /* For global_dc. */
45 #include "tm.h"
46 #include "langhooks.h"
48 gfc_option_t gfc_option;
51 /* Set flags that control warnings and errors for different
52 Fortran standards to their default values. Keep in sync with
53 libgfortran/runtime/compile_options.c (init_compile_options). */
55 static void
56 set_default_std_flags (void)
58 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F95_DEL
59 | GFC_STD_F2003 | GFC_STD_F2008 | GFC_STD_F95 | GFC_STD_F77
60 | GFC_STD_F2008_OBS | GFC_STD_F2008_TS | GFC_STD_GNU | GFC_STD_LEGACY;
61 gfc_option.warn_std = GFC_STD_F95_DEL | GFC_STD_LEGACY;
65 /* Return language mask for Fortran options. */
67 unsigned int
68 gfc_option_lang_mask (void)
70 return CL_Fortran;
73 /* Initialize options structure OPTS. */
75 void
76 gfc_init_options_struct (struct gcc_options *opts)
78 opts->x_flag_errno_math = 0;
79 opts->frontend_set_flag_errno_math = true;
80 opts->x_flag_associative_math = -1;
81 opts->frontend_set_flag_associative_math = true;
84 /* Get ready for options handling. Keep in sync with
85 libgfortran/runtime/compile_options.c (init_compile_options). */
87 void
88 gfc_init_options (unsigned int decoded_options_count,
89 struct cl_decoded_option *decoded_options)
91 gfc_source_file = NULL;
92 gfc_option.module_dir = NULL;
93 gfc_option.source_form = FORM_UNKNOWN;
94 gfc_option.max_continue_fixed = 255;
95 gfc_option.max_continue_free = 255;
96 gfc_option.max_identifier_length = GFC_MAX_SYMBOL_LEN;
97 gfc_option.max_errors = 25;
99 gfc_option.flag_preprocessed = 0;
100 gfc_option.flag_d_lines = -1;
101 gfc_option.flag_init_integer = GFC_INIT_INTEGER_OFF;
102 gfc_option.flag_init_integer_value = 0;
103 gfc_option.flag_init_logical = GFC_INIT_LOGICAL_OFF;
104 gfc_option.flag_init_character = GFC_INIT_CHARACTER_OFF;
105 gfc_option.flag_init_character_value = (char)0;
107 gfc_option.fpe = 0;
108 /* All except GFC_FPE_INEXACT. */
109 gfc_option.fpe_summary = GFC_FPE_INVALID | GFC_FPE_DENORMAL
110 | GFC_FPE_ZERO | GFC_FPE_OVERFLOW
111 | GFC_FPE_UNDERFLOW;
112 gfc_option.rtcheck = 0;
114 /* ??? Wmissing-include-dirs is disabled by default in C/C++ but
115 enabled by default in Fortran. Ideally, we should express this
116 in .opt, but that is not supported yet. */
117 if (!global_options_set.x_cpp_warn_missing_include_dirs)
118 global_options.x_cpp_warn_missing_include_dirs = 1;;
120 set_default_std_flags ();
122 /* Initialize cpp-related options. */
123 gfc_cpp_init_options (decoded_options_count, decoded_options);
124 gfc_diagnostics_init ();
128 /* Determine the source form from the filename extension. We assume
129 case insensitivity. */
131 static gfc_source_form
132 form_from_filename (const char *filename)
134 static const struct
136 const char *extension;
137 gfc_source_form form;
139 exttype[] =
142 ".f90", FORM_FREE}
145 ".f95", FORM_FREE}
148 ".f03", FORM_FREE}
151 ".f08", FORM_FREE}
154 ".f", FORM_FIXED}
157 ".for", FORM_FIXED}
160 ".ftn", FORM_FIXED}
163 "", FORM_UNKNOWN}
164 }; /* sentinel value */
166 gfc_source_form f_form;
167 const char *fileext;
168 int i;
170 /* Find end of file name. Note, filename is either a NULL pointer or
171 a NUL terminated string. */
172 i = 0;
173 while (filename[i] != '\0')
174 i++;
176 /* Find last period. */
177 while (i >= 0 && (filename[i] != '.'))
178 i--;
180 /* Did we see a file extension? */
181 if (i < 0)
182 return FORM_UNKNOWN; /* Nope */
184 /* Get file extension and compare it to others. */
185 fileext = &(filename[i]);
187 i = -1;
188 f_form = FORM_UNKNOWN;
191 i++;
192 if (strcasecmp (fileext, exttype[i].extension) == 0)
194 f_form = exttype[i].form;
195 break;
198 while (exttype[i].form != FORM_UNKNOWN);
200 return f_form;
204 /* Finalize commandline options. */
206 bool
207 gfc_post_options (const char **pfilename)
209 const char *filename = *pfilename, *canon_source_file = NULL;
210 char *source_path;
211 int i;
213 /* Excess precision other than "fast" requires front-end
214 support. */
215 if (flag_excess_precision_cmdline == EXCESS_PRECISION_STANDARD
216 && TARGET_FLT_EVAL_METHOD_NON_DEFAULT)
217 sorry ("-fexcess-precision=standard for Fortran");
218 flag_excess_precision_cmdline = EXCESS_PRECISION_FAST;
220 /* Fortran allows associative math - but we cannot reassociate if
221 we want traps or signed zeros. Cf. also flag_protect_parens. */
222 if (flag_associative_math == -1)
223 flag_associative_math = (!flag_trapping_math && !flag_signed_zeros);
225 if (flag_protect_parens == -1)
226 flag_protect_parens = !optimize_fast;
228 if (flag_stack_arrays == -1)
229 flag_stack_arrays = optimize_fast;
231 /* By default, disable (re)allocation during assignment for -std=f95,
232 and enable it for F2003/F2008/GNU/Legacy. */
233 if (flag_realloc_lhs == -1)
235 if (gfc_option.allow_std & GFC_STD_F2003)
236 flag_realloc_lhs = 1;
237 else
238 flag_realloc_lhs = 0;
241 /* -fbounds-check is equivalent to -fcheck=bounds */
242 if (flag_bounds_check)
243 gfc_option.rtcheck |= GFC_RTCHECK_BOUNDS;
245 if (flag_compare_debug)
246 flag_dump_fortran_original = 0;
248 /* Make -fmax-errors visible to gfortran's diagnostic machinery. */
249 if (global_options_set.x_flag_max_errors)
250 gfc_option.max_errors = flag_max_errors;
252 /* Verify the input file name. */
253 if (!filename || strcmp (filename, "-") == 0)
255 filename = "";
258 if (gfc_option.flag_preprocessed)
260 /* For preprocessed files, if the first tokens are of the form # NUM.
261 handle the directives so we know the original file name. */
262 gfc_source_file = gfc_read_orig_filename (filename, &canon_source_file);
263 if (gfc_source_file == NULL)
264 gfc_source_file = filename;
265 else
266 *pfilename = gfc_source_file;
268 else
269 gfc_source_file = filename;
271 if (canon_source_file == NULL)
272 canon_source_file = gfc_source_file;
274 /* Adds the path where the source file is to the list of include files. */
276 i = strlen (canon_source_file);
277 while (i > 0 && !IS_DIR_SEPARATOR (canon_source_file[i]))
278 i--;
280 if (i != 0)
282 source_path = (char *) alloca (i + 1);
283 memcpy (source_path, canon_source_file, i);
284 source_path[i] = 0;
285 gfc_add_include_path (source_path, true, true, true);
287 else
288 gfc_add_include_path (".", true, true, true);
290 if (canon_source_file != gfc_source_file)
291 free (CONST_CAST (char *, canon_source_file));
293 /* Decide which form the file will be read in as. */
295 if (gfc_option.source_form != FORM_UNKNOWN)
296 gfc_current_form = gfc_option.source_form;
297 else
299 gfc_current_form = form_from_filename (filename);
301 if (gfc_current_form == FORM_UNKNOWN)
303 gfc_current_form = FORM_FREE;
304 gfc_warning_now (0, "Reading file %qs as free form",
305 (filename[0] == '\0') ? "<stdin>" : filename);
309 /* If the user specified -fd-lines-as-{code|comments} verify that we're
310 in fixed form. */
311 if (gfc_current_form == FORM_FREE)
313 if (gfc_option.flag_d_lines == 0)
314 gfc_warning_now (0, "%<-fd-lines-as-comments%> has no effect "
315 "in free form");
316 else if (gfc_option.flag_d_lines == 1)
317 gfc_warning_now (0, "%<-fd-lines-as-code%> has no effect in free form");
319 if (warn_line_truncation == -1)
320 warn_line_truncation = 1;
322 /* Enable -Werror=line-truncation when -Werror and -Wno-error have
323 not been set. */
324 if (warn_line_truncation && !global_options_set.x_warnings_are_errors
325 && (global_dc->classify_diagnostic[OPT_Wline_truncation] ==
326 DK_UNSPECIFIED))
327 diagnostic_classify_diagnostic (global_dc, OPT_Wline_truncation,
328 DK_ERROR, UNKNOWN_LOCATION);
330 else if (warn_line_truncation == -1)
331 warn_line_truncation = 0;
333 /* If -pedantic, warn about the use of GNU extensions. */
334 if (pedantic && (gfc_option.allow_std & GFC_STD_GNU) != 0)
335 gfc_option.warn_std |= GFC_STD_GNU;
336 /* -std=legacy -pedantic is effectively -std=gnu. */
337 if (pedantic && (gfc_option.allow_std & GFC_STD_LEGACY) != 0)
338 gfc_option.warn_std |= GFC_STD_F95_OBS | GFC_STD_F95_DEL | GFC_STD_LEGACY;
340 /* If the user didn't explicitly specify -f(no)-second-underscore we
341 use it if we're trying to be compatible with f2c, and not
342 otherwise. */
343 if (flag_second_underscore == -1)
344 flag_second_underscore = flag_f2c;
346 if (!flag_automatic && flag_max_stack_var_size != -2
347 && flag_max_stack_var_size != 0)
348 gfc_warning_now (0, "Flag %<-fno-automatic%> overwrites %<-fmax-stack-var-size=%d%>",
349 flag_max_stack_var_size);
350 else if (!flag_automatic && flag_recursive)
351 gfc_warning_now (0, "Flag %<-fno-automatic%> overwrites %<-frecursive%>");
352 else if (!flag_automatic && flag_openmp)
353 gfc_warning_now (0, "Flag %<-fno-automatic%> overwrites %<-frecursive%> implied by "
354 "%<-fopenmp%>");
355 else if (flag_max_stack_var_size != -2 && flag_recursive)
356 gfc_warning_now (0, "Flag %<-frecursive%> overwrites %<-fmax-stack-var-size=%d%>",
357 flag_max_stack_var_size);
358 else if (flag_max_stack_var_size != -2 && flag_openmp)
359 gfc_warning_now (0, "Flag %<-fmax-stack-var-size=%d%> overwrites %<-frecursive%> "
360 "implied by %<-fopenmp%>", flag_max_stack_var_size);
362 /* Implement -frecursive as -fmax-stack-var-size=-1. */
363 if (flag_recursive)
364 flag_max_stack_var_size = -1;
366 /* Implied -frecursive; implemented as -fmax-stack-var-size=-1. */
367 if (flag_max_stack_var_size == -2 && flag_openmp && flag_automatic)
369 flag_recursive = 1;
370 flag_max_stack_var_size = -1;
373 /* Set default. */
374 if (flag_max_stack_var_size == -2)
375 flag_max_stack_var_size = 32768;
377 /* Implement -fno-automatic as -fmax-stack-var-size=0. */
378 if (!flag_automatic)
379 flag_max_stack_var_size = 0;
381 /* Optimization implies front end optimization, unless the user
382 specified it directly. */
384 if (flag_frontend_optimize == -1)
385 flag_frontend_optimize = optimize;
387 if (flag_max_array_constructor < 65535)
388 flag_max_array_constructor = 65535;
390 if (flag_fixed_line_length != 0 && flag_fixed_line_length < 7)
391 gfc_fatal_error ("Fixed line length must be at least seven");
393 if (flag_free_line_length != 0 && flag_free_line_length < 4)
394 gfc_fatal_error ("Free line length must be at least three");
396 if (flag_max_subrecord_length > MAX_SUBRECORD_LENGTH)
397 gfc_fatal_error ("Maximum subrecord length cannot exceed %d",
398 MAX_SUBRECORD_LENGTH);
400 gfc_cpp_post_options ();
402 if (gfc_option.allow_std & GFC_STD_F2008)
403 lang_hooks.name = "GNU Fortran2008";
404 else if (gfc_option.allow_std & GFC_STD_F2003)
405 lang_hooks.name = "GNU Fortran2003";
407 return gfc_cpp_preprocess_only ();
411 static void
412 gfc_handle_module_path_options (const char *arg)
415 if (gfc_option.module_dir != NULL)
416 gfc_fatal_error ("gfortran: Only one %<-J%> option allowed");
418 gfc_option.module_dir = XCNEWVEC (char, strlen (arg) + 2);
419 strcpy (gfc_option.module_dir, arg);
421 gfc_add_include_path (gfc_option.module_dir, true, false, true);
423 strcat (gfc_option.module_dir, "/");
427 /* Handle options -ffpe-trap= and -ffpe-summary=. */
429 static void
430 gfc_handle_fpe_option (const char *arg, bool trap)
432 int result, pos = 0, n;
433 /* precision is a backwards compatibility alias for inexact. */
434 static const char * const exception[] = { "invalid", "denormal", "zero",
435 "overflow", "underflow",
436 "inexact", "precision", NULL };
437 static const int opt_exception[] = { GFC_FPE_INVALID, GFC_FPE_DENORMAL,
438 GFC_FPE_ZERO, GFC_FPE_OVERFLOW,
439 GFC_FPE_UNDERFLOW, GFC_FPE_INEXACT,
440 GFC_FPE_INEXACT,
441 0 };
443 /* As the default for -ffpe-summary= is nonzero, set it to 0. */
444 if (!trap)
445 gfc_option.fpe_summary = 0;
447 while (*arg)
449 while (*arg == ',')
450 arg++;
452 while (arg[pos] && arg[pos] != ',')
453 pos++;
455 result = 0;
456 if (!trap && strncmp ("none", arg, pos) == 0)
458 gfc_option.fpe_summary = 0;
459 arg += pos;
460 pos = 0;
461 continue;
463 else if (!trap && strncmp ("all", arg, pos) == 0)
465 gfc_option.fpe_summary = GFC_FPE_INVALID | GFC_FPE_DENORMAL
466 | GFC_FPE_ZERO | GFC_FPE_OVERFLOW
467 | GFC_FPE_UNDERFLOW | GFC_FPE_INEXACT;
468 arg += pos;
469 pos = 0;
470 continue;
472 else
473 for (n = 0; exception[n] != NULL; n++)
475 if (exception[n] && strncmp (exception[n], arg, pos) == 0)
477 if (trap)
478 gfc_option.fpe |= opt_exception[n];
479 else
480 gfc_option.fpe_summary |= opt_exception[n];
481 arg += pos;
482 pos = 0;
483 result = 1;
484 break;
487 if (!result && !trap)
488 gfc_fatal_error ("Argument to %<-ffpe-trap%> is not valid: %s", arg);
489 else if (!result)
490 gfc_fatal_error ("Argument to %<-ffpe-summary%> is not valid: %s", arg);
496 static void
497 gfc_handle_runtime_check_option (const char *arg)
499 int result, pos = 0, n;
500 static const char * const optname[] = { "all", "bounds", "array-temps",
501 "recursion", "do", "pointer",
502 "mem", NULL };
503 static const int optmask[] = { GFC_RTCHECK_ALL, GFC_RTCHECK_BOUNDS,
504 GFC_RTCHECK_ARRAY_TEMPS,
505 GFC_RTCHECK_RECURSION, GFC_RTCHECK_DO,
506 GFC_RTCHECK_POINTER, GFC_RTCHECK_MEM,
507 0 };
509 while (*arg)
511 while (*arg == ',')
512 arg++;
514 while (arg[pos] && arg[pos] != ',')
515 pos++;
517 result = 0;
518 for (n = 0; optname[n] != NULL; n++)
520 if (optname[n] && strncmp (optname[n], arg, pos) == 0)
522 gfc_option.rtcheck |= optmask[n];
523 arg += pos;
524 pos = 0;
525 result = 1;
526 break;
529 if (!result)
530 gfc_fatal_error ("Argument to %<-fcheck%> is not valid: %s", arg);
535 /* Handle command-line options. Returns 0 if unrecognized, 1 if
536 recognized and handled. */
538 bool
539 gfc_handle_option (size_t scode, const char *arg, int value,
540 int kind ATTRIBUTE_UNUSED, location_t loc ATTRIBUTE_UNUSED,
541 const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED)
543 bool result = true;
544 enum opt_code code = (enum opt_code) scode;
546 if (gfc_cpp_handle_option (scode, arg, value) == 1)
547 return true;
549 switch (code)
551 default:
552 if (cl_options[code].flags & gfc_option_lang_mask ())
553 break;
554 result = false;
555 break;
557 case OPT_fcheck_array_temporaries:
558 gfc_option.rtcheck |= GFC_RTCHECK_ARRAY_TEMPS;
559 break;
561 case OPT_fd_lines_as_code:
562 gfc_option.flag_d_lines = 1;
563 break;
565 case OPT_fd_lines_as_comments:
566 gfc_option.flag_d_lines = 0;
567 break;
569 case OPT_ffixed_form:
570 gfc_option.source_form = FORM_FIXED;
571 break;
573 case OPT_ffree_form:
574 gfc_option.source_form = FORM_FREE;
575 break;
577 case OPT_static_libgfortran:
578 #ifndef HAVE_LD_STATIC_DYNAMIC
579 gfc_fatal_error ("%<-static-libgfortran%> is not supported in this "
580 "configuration");
581 #endif
582 break;
584 case OPT_fintrinsic_modules_path:
585 case OPT_fintrinsic_modules_path_:
587 /* This is needed because omp_lib.h is in a directory together
588 with intrinsic modules. Do no warn because during testing
589 without an installed compiler, we would get lots of bogus
590 warnings for a missing include directory. */
591 gfc_add_include_path (arg, false, false, false);
593 gfc_add_intrinsic_modules_path (arg);
594 break;
596 case OPT_fpreprocessed:
597 gfc_option.flag_preprocessed = value;
598 break;
600 case OPT_fmax_identifier_length_:
601 if (value > GFC_MAX_SYMBOL_LEN)
602 gfc_fatal_error ("Maximum supported identifier length is %d",
603 GFC_MAX_SYMBOL_LEN);
604 gfc_option.max_identifier_length = value;
605 break;
607 case OPT_finit_local_zero:
608 gfc_option.flag_init_integer = GFC_INIT_INTEGER_ON;
609 gfc_option.flag_init_integer_value = 0;
610 flag_init_real = GFC_INIT_REAL_ZERO;
611 gfc_option.flag_init_logical = GFC_INIT_LOGICAL_FALSE;
612 gfc_option.flag_init_character = GFC_INIT_CHARACTER_ON;
613 gfc_option.flag_init_character_value = (char)0;
614 break;
616 case OPT_finit_logical_:
617 if (!strcasecmp (arg, "false"))
618 gfc_option.flag_init_logical = GFC_INIT_LOGICAL_FALSE;
619 else if (!strcasecmp (arg, "true"))
620 gfc_option.flag_init_logical = GFC_INIT_LOGICAL_TRUE;
621 else
622 gfc_fatal_error ("Unrecognized option to %<-finit-logical%>: %s",
623 arg);
624 break;
626 case OPT_finit_integer_:
627 gfc_option.flag_init_integer = GFC_INIT_INTEGER_ON;
628 gfc_option.flag_init_integer_value = atoi (arg);
629 break;
631 case OPT_finit_character_:
632 if (value >= 0 && value <= 127)
634 gfc_option.flag_init_character = GFC_INIT_CHARACTER_ON;
635 gfc_option.flag_init_character_value = (char)value;
637 else
638 gfc_fatal_error ("The value of n in %<-finit-character=n%> must be "
639 "between 0 and 127");
640 break;
642 case OPT_I:
643 gfc_add_include_path (arg, true, false, true);
644 break;
646 case OPT_J:
647 gfc_handle_module_path_options (arg);
648 break;
650 case OPT_ffpe_trap_:
651 gfc_handle_fpe_option (arg, true);
652 break;
654 case OPT_ffpe_summary_:
655 gfc_handle_fpe_option (arg, false);
656 break;
658 case OPT_std_f95:
659 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F95 | GFC_STD_F77
660 | GFC_STD_F2008_OBS;
661 gfc_option.warn_std = GFC_STD_F95_OBS;
662 gfc_option.max_continue_fixed = 19;
663 gfc_option.max_continue_free = 39;
664 gfc_option.max_identifier_length = 31;
665 warn_ampersand = 1;
666 warn_tabs = 1;
667 break;
669 case OPT_std_f2003:
670 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F77
671 | GFC_STD_F2003 | GFC_STD_F95 | GFC_STD_F2008_OBS;
672 gfc_option.warn_std = GFC_STD_F95_OBS;
673 gfc_option.max_identifier_length = 63;
674 warn_ampersand = 1;
675 warn_tabs = 1;
676 break;
678 case OPT_std_f2008:
679 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F77
680 | GFC_STD_F2003 | GFC_STD_F95 | GFC_STD_F2008 | GFC_STD_F2008_OBS;
681 gfc_option.warn_std = GFC_STD_F95_OBS | GFC_STD_F2008_OBS;
682 gfc_option.max_identifier_length = 63;
683 warn_ampersand = 1;
684 warn_tabs = 1;
685 break;
687 case OPT_std_f2008ts:
688 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F77
689 | GFC_STD_F2003 | GFC_STD_F95 | GFC_STD_F2008 | GFC_STD_F2008_OBS
690 | GFC_STD_F2008_TS;
691 gfc_option.warn_std = GFC_STD_F95_OBS | GFC_STD_F2008_OBS;
692 gfc_option.max_identifier_length = 63;
693 warn_ampersand = 1;
694 warn_tabs = 1;
695 break;
697 case OPT_std_gnu:
698 set_default_std_flags ();
699 break;
701 case OPT_std_legacy:
702 set_default_std_flags ();
703 gfc_option.warn_std = 0;
704 break;
706 case OPT_fshort_enums:
707 /* Handled in language-independent code. */
708 break;
710 case OPT_fcheck_:
711 gfc_handle_runtime_check_option (arg);
712 break;
715 Fortran_handle_option_auto (&global_options, &global_options_set,
716 scode, arg, value,
717 gfc_option_lang_mask (), kind,
718 loc, handlers, global_dc);
719 return result;
723 /* Return a string with the options passed to the compiler; used for
724 Fortran's compiler_options() intrinsic. */
726 char *
727 gfc_get_option_string (void)
729 unsigned j;
730 size_t len, pos;
731 char *result;
733 /* Allocate and return a one-character string with '\0'. */
734 if (!save_decoded_options_count)
735 return XCNEWVEC (char, 1);
737 /* Determine required string length. */
739 len = 0;
740 for (j = 1; j < save_decoded_options_count; j++)
742 switch (save_decoded_options[j].opt_index)
744 case OPT_o:
745 case OPT_d:
746 case OPT_dumpbase:
747 case OPT_dumpdir:
748 case OPT_auxbase:
749 case OPT_quiet:
750 case OPT_version:
751 case OPT_fintrinsic_modules_path:
752 case OPT_fintrinsic_modules_path_:
753 /* Ignore these. */
754 break;
755 default:
756 /* Ignore file names. */
757 if (save_decoded_options[j].orig_option_with_args_text[0] == '-')
758 len += 1
759 + strlen (save_decoded_options[j].orig_option_with_args_text);
763 result = XCNEWVEC (char, len);
765 pos = 0;
766 for (j = 1; j < save_decoded_options_count; j++)
768 switch (save_decoded_options[j].opt_index)
770 case OPT_o:
771 case OPT_d:
772 case OPT_dumpbase:
773 case OPT_dumpdir:
774 case OPT_auxbase:
775 case OPT_quiet:
776 case OPT_version:
777 case OPT_fintrinsic_modules_path:
778 case OPT_fintrinsic_modules_path_:
779 /* Ignore these. */
780 continue;
782 case OPT_cpp_:
783 /* Use "-cpp" rather than "-cpp=<temporary file>". */
784 len = 4;
785 break;
787 default:
788 /* Ignore file names. */
789 if (save_decoded_options[j].orig_option_with_args_text[0] != '-')
790 continue;
792 len = strlen (save_decoded_options[j].orig_option_with_args_text);
795 memcpy (&result[pos], save_decoded_options[j].orig_option_with_args_text, len);
796 pos += len;
797 result[pos++] = ' ';
800 result[--pos] = '\0';
801 return result;