altivec.md (VParity): New mode iterator for vector parity built-in functions.
[official-gcc.git] / gcc / fortran / options.c
blob5a91ec1b2095eec5e65546e6e081cca56b512a04
1 /* Parse and display command line options.
2 Copyright (C) 2000-2016 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 "target.h"
25 #include "tree.h"
26 #include "gfortran.h"
27 #include "diagnostic.h" /* For global_dc. */
28 #include "opts.h"
29 #include "toplev.h" /* For save_decoded_options. */
30 #include "cpp.h"
31 #include "langhooks.h"
33 gfc_option_t gfc_option;
36 /* Set flags that control warnings and errors for different
37 Fortran standards to their default values. Keep in sync with
38 libgfortran/runtime/compile_options.c (init_compile_options). */
40 static void
41 set_default_std_flags (void)
43 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F95_DEL
44 | GFC_STD_F2003 | GFC_STD_F2008 | GFC_STD_F95 | GFC_STD_F77
45 | GFC_STD_F2008_OBS | GFC_STD_F2008_TS | GFC_STD_GNU | GFC_STD_LEGACY;
46 gfc_option.warn_std = GFC_STD_F95_DEL | GFC_STD_LEGACY;
50 /* Set all the DEC extension flags. */
52 static void
53 set_dec_flags (int value)
55 gfc_option.flag_dec_structure = value;
59 /* Return language mask for Fortran options. */
61 unsigned int
62 gfc_option_lang_mask (void)
64 return CL_Fortran;
67 /* Initialize options structure OPTS. */
69 void
70 gfc_init_options_struct (struct gcc_options *opts)
72 opts->x_flag_errno_math = 0;
73 opts->frontend_set_flag_errno_math = true;
74 opts->x_flag_associative_math = -1;
75 opts->frontend_set_flag_associative_math = true;
78 /* Get ready for options handling. Keep in sync with
79 libgfortran/runtime/compile_options.c (init_compile_options). */
81 void
82 gfc_init_options (unsigned int decoded_options_count,
83 struct cl_decoded_option *decoded_options)
85 gfc_source_file = NULL;
86 gfc_option.module_dir = NULL;
87 gfc_option.source_form = FORM_UNKNOWN;
88 gfc_option.max_continue_fixed = 255;
89 gfc_option.max_continue_free = 255;
90 gfc_option.max_identifier_length = GFC_MAX_SYMBOL_LEN;
91 gfc_option.max_errors = 25;
93 gfc_option.flag_preprocessed = 0;
94 gfc_option.flag_d_lines = -1;
95 gfc_option.flag_init_integer = GFC_INIT_INTEGER_OFF;
96 gfc_option.flag_init_integer_value = 0;
97 gfc_option.flag_init_logical = GFC_INIT_LOGICAL_OFF;
98 gfc_option.flag_init_character = GFC_INIT_CHARACTER_OFF;
99 gfc_option.flag_init_character_value = (char)0;
101 gfc_option.fpe = 0;
102 /* All except GFC_FPE_INEXACT. */
103 gfc_option.fpe_summary = GFC_FPE_INVALID | GFC_FPE_DENORMAL
104 | GFC_FPE_ZERO | GFC_FPE_OVERFLOW
105 | GFC_FPE_UNDERFLOW;
106 gfc_option.rtcheck = 0;
108 /* ??? Wmissing-include-dirs is disabled by default in C/C++ but
109 enabled by default in Fortran. Ideally, we should express this
110 in .opt, but that is not supported yet. */
111 if (!global_options_set.x_cpp_warn_missing_include_dirs)
112 global_options.x_cpp_warn_missing_include_dirs = 1;
114 set_dec_flags (0);
116 set_default_std_flags ();
118 /* Initialize cpp-related options. */
119 gfc_cpp_init_options (decoded_options_count, decoded_options);
120 gfc_diagnostics_init ();
124 /* Determine the source form from the filename extension. We assume
125 case insensitivity. */
127 static gfc_source_form
128 form_from_filename (const char *filename)
130 static const struct
132 const char *extension;
133 gfc_source_form form;
135 exttype[] =
138 ".f90", FORM_FREE}
141 ".f95", FORM_FREE}
144 ".f03", FORM_FREE}
147 ".f08", FORM_FREE}
150 ".f", FORM_FIXED}
153 ".for", FORM_FIXED}
156 ".ftn", FORM_FIXED}
159 "", FORM_UNKNOWN}
160 }; /* sentinel value */
162 gfc_source_form f_form;
163 const char *fileext;
164 int i;
166 /* Find end of file name. Note, filename is either a NULL pointer or
167 a NUL terminated string. */
168 i = 0;
169 while (filename[i] != '\0')
170 i++;
172 /* Find last period. */
173 while (i >= 0 && (filename[i] != '.'))
174 i--;
176 /* Did we see a file extension? */
177 if (i < 0)
178 return FORM_UNKNOWN; /* Nope */
180 /* Get file extension and compare it to others. */
181 fileext = &(filename[i]);
183 i = -1;
184 f_form = FORM_UNKNOWN;
187 i++;
188 if (strcasecmp (fileext, exttype[i].extension) == 0)
190 f_form = exttype[i].form;
191 break;
194 while (exttype[i].form != FORM_UNKNOWN);
196 return f_form;
200 /* Finalize commandline options. */
202 bool
203 gfc_post_options (const char **pfilename)
205 const char *filename = *pfilename, *canon_source_file = NULL;
206 char *source_path;
207 int i;
209 /* Excess precision other than "fast" requires front-end
210 support. */
211 if (flag_excess_precision_cmdline == EXCESS_PRECISION_STANDARD
212 && TARGET_FLT_EVAL_METHOD_NON_DEFAULT)
213 sorry ("-fexcess-precision=standard for Fortran");
214 flag_excess_precision_cmdline = EXCESS_PRECISION_FAST;
216 /* Fortran allows associative math - but we cannot reassociate if
217 we want traps or signed zeros. Cf. also flag_protect_parens. */
218 if (flag_associative_math == -1)
219 flag_associative_math = (!flag_trapping_math && !flag_signed_zeros);
221 if (flag_protect_parens == -1)
222 flag_protect_parens = !optimize_fast;
224 if (flag_stack_arrays == -1)
225 flag_stack_arrays = optimize_fast;
227 /* By default, disable (re)allocation during assignment for -std=f95,
228 and enable it for F2003/F2008/GNU/Legacy. */
229 if (flag_realloc_lhs == -1)
231 if (gfc_option.allow_std & GFC_STD_F2003)
232 flag_realloc_lhs = 1;
233 else
234 flag_realloc_lhs = 0;
237 /* -fbounds-check is equivalent to -fcheck=bounds */
238 if (flag_bounds_check)
239 gfc_option.rtcheck |= GFC_RTCHECK_BOUNDS;
241 if (flag_compare_debug)
242 flag_dump_fortran_original = 0;
244 /* Make -fmax-errors visible to gfortran's diagnostic machinery. */
245 if (global_options_set.x_flag_max_errors)
246 gfc_option.max_errors = flag_max_errors;
248 /* Verify the input file name. */
249 if (!filename || strcmp (filename, "-") == 0)
251 filename = "";
254 if (gfc_option.flag_preprocessed)
256 /* For preprocessed files, if the first tokens are of the form # NUM.
257 handle the directives so we know the original file name. */
258 gfc_source_file = gfc_read_orig_filename (filename, &canon_source_file);
259 if (gfc_source_file == NULL)
260 gfc_source_file = filename;
261 else
262 *pfilename = gfc_source_file;
264 else
265 gfc_source_file = filename;
267 if (canon_source_file == NULL)
268 canon_source_file = gfc_source_file;
270 /* Adds the path where the source file is to the list of include files. */
272 i = strlen (canon_source_file);
273 while (i > 0 && !IS_DIR_SEPARATOR (canon_source_file[i]))
274 i--;
276 if (i != 0)
278 source_path = (char *) alloca (i + 1);
279 memcpy (source_path, canon_source_file, i);
280 source_path[i] = 0;
281 gfc_add_include_path (source_path, true, true, true);
283 else
284 gfc_add_include_path (".", true, true, true);
286 if (canon_source_file != gfc_source_file)
287 free (CONST_CAST (char *, canon_source_file));
289 /* Decide which form the file will be read in as. */
291 if (gfc_option.source_form != FORM_UNKNOWN)
292 gfc_current_form = gfc_option.source_form;
293 else
295 gfc_current_form = form_from_filename (filename);
297 if (gfc_current_form == FORM_UNKNOWN)
299 gfc_current_form = FORM_FREE;
300 gfc_warning_now (0, "Reading file %qs as free form",
301 (filename[0] == '\0') ? "<stdin>" : filename);
305 /* If the user specified -fd-lines-as-{code|comments} verify that we're
306 in fixed form. */
307 if (gfc_current_form == FORM_FREE)
309 if (gfc_option.flag_d_lines == 0)
310 gfc_warning_now (0, "%<-fd-lines-as-comments%> has no effect "
311 "in free form");
312 else if (gfc_option.flag_d_lines == 1)
313 gfc_warning_now (0, "%<-fd-lines-as-code%> has no effect in free form");
315 if (warn_line_truncation == -1)
316 warn_line_truncation = 1;
318 /* Enable -Werror=line-truncation when -Werror and -Wno-error have
319 not been set. */
320 if (warn_line_truncation && !global_options_set.x_warnings_are_errors
321 && (global_dc->classify_diagnostic[OPT_Wline_truncation] ==
322 DK_UNSPECIFIED))
323 diagnostic_classify_diagnostic (global_dc, OPT_Wline_truncation,
324 DK_ERROR, UNKNOWN_LOCATION);
326 else if (warn_line_truncation == -1)
327 warn_line_truncation = 0;
329 /* If -pedantic, warn about the use of GNU extensions. */
330 if (pedantic && (gfc_option.allow_std & GFC_STD_GNU) != 0)
331 gfc_option.warn_std |= GFC_STD_GNU;
332 /* -std=legacy -pedantic is effectively -std=gnu. */
333 if (pedantic && (gfc_option.allow_std & GFC_STD_LEGACY) != 0)
334 gfc_option.warn_std |= GFC_STD_F95_OBS | GFC_STD_F95_DEL | GFC_STD_LEGACY;
336 /* If the user didn't explicitly specify -f(no)-second-underscore we
337 use it if we're trying to be compatible with f2c, and not
338 otherwise. */
339 if (flag_second_underscore == -1)
340 flag_second_underscore = flag_f2c;
342 if (!flag_automatic && flag_max_stack_var_size != -2
343 && flag_max_stack_var_size != 0)
344 gfc_warning_now (0, "Flag %<-fno-automatic%> overwrites %<-fmax-stack-var-size=%d%>",
345 flag_max_stack_var_size);
346 else if (!flag_automatic && flag_recursive)
347 gfc_warning_now (0, "Flag %<-fno-automatic%> overwrites %<-frecursive%>");
348 else if (!flag_automatic && flag_openmp)
349 gfc_warning_now (0, "Flag %<-fno-automatic%> overwrites %<-frecursive%> implied by "
350 "%<-fopenmp%>");
351 else if (flag_max_stack_var_size != -2 && flag_recursive)
352 gfc_warning_now (0, "Flag %<-frecursive%> overwrites %<-fmax-stack-var-size=%d%>",
353 flag_max_stack_var_size);
354 else if (flag_max_stack_var_size != -2 && flag_openmp)
355 gfc_warning_now (0, "Flag %<-fmax-stack-var-size=%d%> overwrites %<-frecursive%> "
356 "implied by %<-fopenmp%>", flag_max_stack_var_size);
358 /* Implement -frecursive as -fmax-stack-var-size=-1. */
359 if (flag_recursive)
360 flag_max_stack_var_size = -1;
362 /* Implied -frecursive; implemented as -fmax-stack-var-size=-1. */
363 if (flag_max_stack_var_size == -2 && flag_openmp && flag_automatic)
365 flag_recursive = 1;
366 flag_max_stack_var_size = -1;
369 /* Set default. */
370 if (flag_max_stack_var_size == -2)
371 flag_max_stack_var_size = 32768;
373 /* Implement -fno-automatic as -fmax-stack-var-size=0. */
374 if (!flag_automatic)
375 flag_max_stack_var_size = 0;
377 /* If we call BLAS directly, only inline up to the BLAS limit. */
379 if (flag_external_blas && flag_inline_matmul_limit < 0)
380 flag_inline_matmul_limit = flag_blas_matmul_limit;
382 /* Optimization implies front end optimization, unless the user
383 specified it directly. */
385 if (flag_frontend_optimize == -1)
386 flag_frontend_optimize = optimize;
388 if (flag_max_array_constructor < 65535)
389 flag_max_array_constructor = 65535;
391 if (flag_fixed_line_length != 0 && flag_fixed_line_length < 7)
392 gfc_fatal_error ("Fixed line length must be at least seven");
394 if (flag_free_line_length != 0 && flag_free_line_length < 4)
395 gfc_fatal_error ("Free line length must be at least three");
397 if (flag_max_subrecord_length > MAX_SUBRECORD_LENGTH)
398 gfc_fatal_error ("Maximum subrecord length cannot exceed %d",
399 MAX_SUBRECORD_LENGTH);
401 gfc_cpp_post_options ();
403 if (gfc_option.allow_std & GFC_STD_F2008)
404 lang_hooks.name = "GNU Fortran2008";
405 else if (gfc_option.allow_std & GFC_STD_F2003)
406 lang_hooks.name = "GNU Fortran2003";
408 return gfc_cpp_preprocess_only ();
412 static void
413 gfc_handle_module_path_options (const char *arg)
416 if (gfc_option.module_dir != NULL)
417 gfc_fatal_error ("gfortran: Only one %<-J%> option allowed");
419 gfc_option.module_dir = XCNEWVEC (char, strlen (arg) + 2);
420 strcpy (gfc_option.module_dir, arg);
422 gfc_add_include_path (gfc_option.module_dir, true, false, true);
424 strcat (gfc_option.module_dir, "/");
428 /* Handle options -ffpe-trap= and -ffpe-summary=. */
430 static void
431 gfc_handle_fpe_option (const char *arg, bool trap)
433 int result, pos = 0, n;
434 /* precision is a backwards compatibility alias for inexact. */
435 static const char * const exception[] = { "invalid", "denormal", "zero",
436 "overflow", "underflow",
437 "inexact", "precision", NULL };
438 static const int opt_exception[] = { GFC_FPE_INVALID, GFC_FPE_DENORMAL,
439 GFC_FPE_ZERO, GFC_FPE_OVERFLOW,
440 GFC_FPE_UNDERFLOW, GFC_FPE_INEXACT,
441 GFC_FPE_INEXACT,
442 0 };
444 /* As the default for -ffpe-summary= is nonzero, set it to 0. */
445 if (!trap)
446 gfc_option.fpe_summary = 0;
448 while (*arg)
450 while (*arg == ',')
451 arg++;
453 while (arg[pos] && arg[pos] != ',')
454 pos++;
456 result = 0;
457 if (!trap && strncmp ("none", arg, pos) == 0)
459 gfc_option.fpe_summary = 0;
460 arg += pos;
461 pos = 0;
462 continue;
464 else if (!trap && strncmp ("all", arg, pos) == 0)
466 gfc_option.fpe_summary = GFC_FPE_INVALID | GFC_FPE_DENORMAL
467 | GFC_FPE_ZERO | GFC_FPE_OVERFLOW
468 | GFC_FPE_UNDERFLOW | GFC_FPE_INEXACT;
469 arg += pos;
470 pos = 0;
471 continue;
473 else
474 for (n = 0; exception[n] != NULL; n++)
476 if (exception[n] && strncmp (exception[n], arg, pos) == 0)
478 if (trap)
479 gfc_option.fpe |= opt_exception[n];
480 else
481 gfc_option.fpe_summary |= opt_exception[n];
482 arg += pos;
483 pos = 0;
484 result = 1;
485 break;
488 if (!result && !trap)
489 gfc_fatal_error ("Argument to %<-ffpe-trap%> is not valid: %s", arg);
490 else if (!result)
491 gfc_fatal_error ("Argument to %<-ffpe-summary%> is not valid: %s", arg);
497 static void
498 gfc_handle_runtime_check_option (const char *arg)
500 int result, pos = 0, n;
501 static const char * const optname[] = { "all", "bounds", "array-temps",
502 "recursion", "do", "pointer",
503 "mem", NULL };
504 static const int optmask[] = { GFC_RTCHECK_ALL, GFC_RTCHECK_BOUNDS,
505 GFC_RTCHECK_ARRAY_TEMPS,
506 GFC_RTCHECK_RECURSION, GFC_RTCHECK_DO,
507 GFC_RTCHECK_POINTER, GFC_RTCHECK_MEM,
508 0 };
510 while (*arg)
512 while (*arg == ',')
513 arg++;
515 while (arg[pos] && arg[pos] != ',')
516 pos++;
518 result = 0;
519 for (n = 0; optname[n] != NULL; n++)
521 if (optname[n] && strncmp (optname[n], arg, pos) == 0)
523 gfc_option.rtcheck |= optmask[n];
524 arg += pos;
525 pos = 0;
526 result = 1;
527 break;
529 else if (optname[n] && pos > 3 && strncmp ("no-", arg, 3) == 0
530 && strncmp (optname[n], arg+3, pos-3) == 0)
532 gfc_option.rtcheck &= ~optmask[n];
533 arg += pos;
534 pos = 0;
535 result = 1;
536 break;
539 if (!result)
540 gfc_fatal_error ("Argument to %<-fcheck%> is not valid: %s", arg);
545 /* Handle command-line options. Returns 0 if unrecognized, 1 if
546 recognized and handled. */
548 bool
549 gfc_handle_option (size_t scode, const char *arg, int value,
550 int kind ATTRIBUTE_UNUSED, location_t loc ATTRIBUTE_UNUSED,
551 const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED)
553 bool result = true;
554 enum opt_code code = (enum opt_code) scode;
556 if (gfc_cpp_handle_option (scode, arg, value) == 1)
557 return true;
559 switch (code)
561 default:
562 if (cl_options[code].flags & gfc_option_lang_mask ())
563 break;
564 result = false;
565 break;
567 case OPT_fcheck_array_temporaries:
568 gfc_option.rtcheck |= GFC_RTCHECK_ARRAY_TEMPS;
569 break;
571 case OPT_fd_lines_as_code:
572 gfc_option.flag_d_lines = 1;
573 break;
575 case OPT_fd_lines_as_comments:
576 gfc_option.flag_d_lines = 0;
577 break;
579 case OPT_ffixed_form:
580 gfc_option.source_form = FORM_FIXED;
581 break;
583 case OPT_ffree_form:
584 gfc_option.source_form = FORM_FREE;
585 break;
587 case OPT_static_libgfortran:
588 #ifndef HAVE_LD_STATIC_DYNAMIC
589 gfc_fatal_error ("%<-static-libgfortran%> is not supported in this "
590 "configuration");
591 #endif
592 break;
594 case OPT_fintrinsic_modules_path:
595 case OPT_fintrinsic_modules_path_:
597 /* This is needed because omp_lib.h is in a directory together
598 with intrinsic modules. Do no warn because during testing
599 without an installed compiler, we would get lots of bogus
600 warnings for a missing include directory. */
601 gfc_add_include_path (arg, false, false, false);
603 gfc_add_intrinsic_modules_path (arg);
604 break;
606 case OPT_fpreprocessed:
607 gfc_option.flag_preprocessed = value;
608 break;
610 case OPT_fmax_identifier_length_:
611 if (value > GFC_MAX_SYMBOL_LEN)
612 gfc_fatal_error ("Maximum supported identifier length is %d",
613 GFC_MAX_SYMBOL_LEN);
614 gfc_option.max_identifier_length = value;
615 break;
617 case OPT_finit_local_zero:
618 gfc_option.flag_init_integer = GFC_INIT_INTEGER_ON;
619 gfc_option.flag_init_integer_value = 0;
620 flag_init_real = GFC_INIT_REAL_ZERO;
621 gfc_option.flag_init_logical = GFC_INIT_LOGICAL_FALSE;
622 gfc_option.flag_init_character = GFC_INIT_CHARACTER_ON;
623 gfc_option.flag_init_character_value = (char)0;
624 break;
626 case OPT_finit_logical_:
627 if (!strcasecmp (arg, "false"))
628 gfc_option.flag_init_logical = GFC_INIT_LOGICAL_FALSE;
629 else if (!strcasecmp (arg, "true"))
630 gfc_option.flag_init_logical = GFC_INIT_LOGICAL_TRUE;
631 else
632 gfc_fatal_error ("Unrecognized option to %<-finit-logical%>: %s",
633 arg);
634 break;
636 case OPT_finit_integer_:
637 gfc_option.flag_init_integer = GFC_INIT_INTEGER_ON;
638 gfc_option.flag_init_integer_value = atoi (arg);
639 break;
641 case OPT_finit_character_:
642 if (value >= 0 && value <= 127)
644 gfc_option.flag_init_character = GFC_INIT_CHARACTER_ON;
645 gfc_option.flag_init_character_value = (char)value;
647 else
648 gfc_fatal_error ("The value of n in %<-finit-character=n%> must be "
649 "between 0 and 127");
650 break;
652 case OPT_I:
653 gfc_add_include_path (arg, true, false, true);
654 break;
656 case OPT_J:
657 gfc_handle_module_path_options (arg);
658 break;
660 case OPT_ffpe_trap_:
661 gfc_handle_fpe_option (arg, true);
662 break;
664 case OPT_ffpe_summary_:
665 gfc_handle_fpe_option (arg, false);
666 break;
668 case OPT_std_f95:
669 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F95 | GFC_STD_F77
670 | GFC_STD_F2008_OBS;
671 gfc_option.warn_std = GFC_STD_F95_OBS;
672 gfc_option.max_continue_fixed = 19;
673 gfc_option.max_continue_free = 39;
674 gfc_option.max_identifier_length = 31;
675 warn_ampersand = 1;
676 warn_tabs = 1;
677 break;
679 case OPT_std_f2003:
680 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F77
681 | GFC_STD_F2003 | GFC_STD_F95 | GFC_STD_F2008_OBS;
682 gfc_option.warn_std = GFC_STD_F95_OBS;
683 gfc_option.max_identifier_length = 63;
684 warn_ampersand = 1;
685 warn_tabs = 1;
686 break;
688 case OPT_std_f2008:
689 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F77
690 | GFC_STD_F2003 | GFC_STD_F95 | GFC_STD_F2008 | GFC_STD_F2008_OBS;
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_f2008ts:
698 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F77
699 | GFC_STD_F2003 | GFC_STD_F95 | GFC_STD_F2008 | GFC_STD_F2008_OBS
700 | GFC_STD_F2008_TS;
701 gfc_option.warn_std = GFC_STD_F95_OBS | GFC_STD_F2008_OBS;
702 gfc_option.max_identifier_length = 63;
703 warn_ampersand = 1;
704 warn_tabs = 1;
705 break;
707 case OPT_std_gnu:
708 set_default_std_flags ();
709 break;
711 case OPT_std_legacy:
712 set_default_std_flags ();
713 gfc_option.warn_std = 0;
714 break;
716 case OPT_fshort_enums:
717 /* Handled in language-independent code. */
718 break;
720 case OPT_fcheck_:
721 gfc_handle_runtime_check_option (arg);
722 break;
724 case OPT_fdec:
725 /* Enable all DEC extensions. */
726 set_dec_flags (1);
727 break;
729 case OPT_fdec_structure:
730 gfc_option.flag_dec_structure = 1;
731 break;
734 Fortran_handle_option_auto (&global_options, &global_options_set,
735 scode, arg, value,
736 gfc_option_lang_mask (), kind,
737 loc, handlers, global_dc);
738 return result;
742 /* Return a string with the options passed to the compiler; used for
743 Fortran's compiler_options() intrinsic. */
745 char *
746 gfc_get_option_string (void)
748 unsigned j;
749 size_t len, pos;
750 char *result;
752 /* Allocate and return a one-character string with '\0'. */
753 if (!save_decoded_options_count)
754 return XCNEWVEC (char, 1);
756 /* Determine required string length. */
758 len = 0;
759 for (j = 1; j < save_decoded_options_count; j++)
761 switch (save_decoded_options[j].opt_index)
763 case OPT_o:
764 case OPT_d:
765 case OPT_dumpbase:
766 case OPT_dumpdir:
767 case OPT_auxbase:
768 case OPT_quiet:
769 case OPT_version:
770 case OPT_fintrinsic_modules_path:
771 case OPT_fintrinsic_modules_path_:
772 /* Ignore these. */
773 break;
774 default:
775 /* Ignore file names. */
776 if (save_decoded_options[j].orig_option_with_args_text[0] == '-')
777 len += 1
778 + strlen (save_decoded_options[j].orig_option_with_args_text);
782 result = XCNEWVEC (char, len);
784 pos = 0;
785 for (j = 1; j < save_decoded_options_count; j++)
787 switch (save_decoded_options[j].opt_index)
789 case OPT_o:
790 case OPT_d:
791 case OPT_dumpbase:
792 case OPT_dumpdir:
793 case OPT_auxbase:
794 case OPT_quiet:
795 case OPT_version:
796 case OPT_fintrinsic_modules_path:
797 case OPT_fintrinsic_modules_path_:
798 /* Ignore these. */
799 continue;
801 case OPT_cpp_:
802 /* Use "-cpp" rather than "-cpp=<temporary file>". */
803 len = 4;
804 break;
806 default:
807 /* Ignore file names. */
808 if (save_decoded_options[j].orig_option_with_args_text[0] != '-')
809 continue;
811 len = strlen (save_decoded_options[j].orig_option_with_args_text);
814 memcpy (&result[pos], save_decoded_options[j].orig_option_with_args_text, len);
815 pos += len;
816 result[pos++] = ' ';
819 result[--pos] = '\0';
820 return result;