PR rtl-optimization/82913
[official-gcc.git] / gcc / fortran / options.c
blobc584a19e5596fc3e7506fc37d10c4a874ef4e25a
1 /* Parse and display command line options.
2 Copyright (C) 2000-2017 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 if (value)
57 /* Allow legacy code without warnings. */
58 gfc_option.allow_std |= GFC_STD_F95_OBS | GFC_STD_F95_DEL
59 | GFC_STD_GNU | GFC_STD_LEGACY;
60 gfc_option.warn_std &= ~(GFC_STD_LEGACY | GFC_STD_F95_DEL);
63 /* Set other DEC compatibility extensions. */
64 flag_dollar_ok |= value;
65 flag_cray_pointer |= value;
66 flag_dec_structure |= value;
67 flag_dec_intrinsic_ints |= value;
68 flag_dec_static |= value;
69 flag_dec_math |= value;
73 /* Return language mask for Fortran options. */
75 unsigned int
76 gfc_option_lang_mask (void)
78 return CL_Fortran;
81 /* Initialize options structure OPTS. */
83 void
84 gfc_init_options_struct (struct gcc_options *opts)
86 opts->x_flag_errno_math = 0;
87 opts->frontend_set_flag_errno_math = true;
88 opts->x_flag_associative_math = -1;
89 opts->frontend_set_flag_associative_math = true;
92 /* Get ready for options handling. Keep in sync with
93 libgfortran/runtime/compile_options.c (init_compile_options). */
95 void
96 gfc_init_options (unsigned int decoded_options_count,
97 struct cl_decoded_option *decoded_options)
99 gfc_source_file = NULL;
100 gfc_option.module_dir = NULL;
101 gfc_option.source_form = FORM_UNKNOWN;
102 gfc_option.max_continue_fixed = 255;
103 gfc_option.max_continue_free = 255;
104 gfc_option.max_identifier_length = GFC_MAX_SYMBOL_LEN;
105 gfc_option.max_errors = 25;
107 gfc_option.flag_preprocessed = 0;
108 gfc_option.flag_d_lines = -1;
109 gfc_option.flag_init_integer = GFC_INIT_INTEGER_OFF;
110 gfc_option.flag_init_integer_value = 0;
111 gfc_option.flag_init_logical = GFC_INIT_LOGICAL_OFF;
112 gfc_option.flag_init_character = GFC_INIT_CHARACTER_OFF;
113 gfc_option.flag_init_character_value = (char)0;
115 gfc_option.fpe = 0;
116 /* All except GFC_FPE_INEXACT. */
117 gfc_option.fpe_summary = GFC_FPE_INVALID | GFC_FPE_DENORMAL
118 | GFC_FPE_ZERO | GFC_FPE_OVERFLOW
119 | GFC_FPE_UNDERFLOW;
120 gfc_option.rtcheck = 0;
122 /* ??? Wmissing-include-dirs is disabled by default in C/C++ but
123 enabled by default in Fortran. Ideally, we should express this
124 in .opt, but that is not supported yet. */
125 if (!global_options_set.x_cpp_warn_missing_include_dirs)
126 global_options.x_cpp_warn_missing_include_dirs = 1;
128 set_dec_flags (0);
130 set_default_std_flags ();
132 /* Initialize cpp-related options. */
133 gfc_cpp_init_options (decoded_options_count, decoded_options);
134 gfc_diagnostics_init ();
138 /* Determine the source form from the filename extension. We assume
139 case insensitivity. */
141 static gfc_source_form
142 form_from_filename (const char *filename)
144 static const struct
146 const char *extension;
147 gfc_source_form form;
149 exttype[] =
152 ".f90", FORM_FREE}
155 ".f95", FORM_FREE}
158 ".f03", FORM_FREE}
161 ".f08", FORM_FREE}
164 ".f", FORM_FIXED}
167 ".for", FORM_FIXED}
170 ".ftn", FORM_FIXED}
173 "", FORM_UNKNOWN}
174 }; /* sentinel value */
176 gfc_source_form f_form;
177 const char *fileext;
178 int i;
180 /* Find end of file name. Note, filename is either a NULL pointer or
181 a NUL terminated string. */
182 i = 0;
183 while (filename[i] != '\0')
184 i++;
186 /* Find last period. */
187 while (i >= 0 && (filename[i] != '.'))
188 i--;
190 /* Did we see a file extension? */
191 if (i < 0)
192 return FORM_UNKNOWN; /* Nope */
194 /* Get file extension and compare it to others. */
195 fileext = &(filename[i]);
197 i = -1;
198 f_form = FORM_UNKNOWN;
201 i++;
202 if (strcasecmp (fileext, exttype[i].extension) == 0)
204 f_form = exttype[i].form;
205 break;
208 while (exttype[i].form != FORM_UNKNOWN);
210 return f_form;
214 /* Finalize commandline options. */
216 bool
217 gfc_post_options (const char **pfilename)
219 const char *filename = *pfilename, *canon_source_file = NULL;
220 char *source_path;
221 int i;
223 /* Excess precision other than "fast" requires front-end
224 support. */
225 if (flag_excess_precision_cmdline == EXCESS_PRECISION_STANDARD)
226 sorry ("-fexcess-precision=standard for Fortran");
227 flag_excess_precision_cmdline = EXCESS_PRECISION_FAST;
229 /* Fortran allows associative math - but we cannot reassociate if
230 we want traps or signed zeros. Cf. also flag_protect_parens. */
231 if (flag_associative_math == -1)
232 flag_associative_math = (!flag_trapping_math && !flag_signed_zeros);
234 if (flag_protect_parens == -1)
235 flag_protect_parens = !optimize_fast;
237 /* -Ofast sets implies -fstack-arrays unless an explicit size is set for
238 stack arrays. */
239 if (flag_stack_arrays == -1 && flag_max_stack_var_size == -2)
240 flag_stack_arrays = optimize_fast;
242 /* By default, disable (re)allocation during assignment for -std=f95,
243 and enable it for F2003/F2008/GNU/Legacy. */
244 if (flag_realloc_lhs == -1)
246 if (gfc_option.allow_std & GFC_STD_F2003)
247 flag_realloc_lhs = 1;
248 else
249 flag_realloc_lhs = 0;
252 /* -fbounds-check is equivalent to -fcheck=bounds */
253 if (flag_bounds_check)
254 gfc_option.rtcheck |= GFC_RTCHECK_BOUNDS;
256 if (flag_compare_debug)
257 flag_dump_fortran_original = 0;
259 /* Make -fmax-errors visible to gfortran's diagnostic machinery. */
260 if (global_options_set.x_flag_max_errors)
261 gfc_option.max_errors = flag_max_errors;
263 /* Verify the input file name. */
264 if (!filename || strcmp (filename, "-") == 0)
266 filename = "";
269 if (gfc_option.flag_preprocessed)
271 /* For preprocessed files, if the first tokens are of the form # NUM.
272 handle the directives so we know the original file name. */
273 gfc_source_file = gfc_read_orig_filename (filename, &canon_source_file);
274 if (gfc_source_file == NULL)
275 gfc_source_file = filename;
276 else
277 *pfilename = gfc_source_file;
279 else
280 gfc_source_file = filename;
282 if (canon_source_file == NULL)
283 canon_source_file = gfc_source_file;
285 /* Adds the path where the source file is to the list of include files. */
287 i = strlen (canon_source_file);
288 while (i > 0 && !IS_DIR_SEPARATOR (canon_source_file[i]))
289 i--;
291 if (i != 0)
293 source_path = (char *) alloca (i + 1);
294 memcpy (source_path, canon_source_file, i);
295 source_path[i] = 0;
296 gfc_add_include_path (source_path, true, true, true);
298 else
299 gfc_add_include_path (".", true, true, true);
301 if (canon_source_file != gfc_source_file)
302 free (CONST_CAST (char *, canon_source_file));
304 /* Decide which form the file will be read in as. */
306 if (gfc_option.source_form != FORM_UNKNOWN)
307 gfc_current_form = gfc_option.source_form;
308 else
310 gfc_current_form = form_from_filename (filename);
312 if (gfc_current_form == FORM_UNKNOWN)
314 gfc_current_form = FORM_FREE;
315 gfc_warning_now (0, "Reading file %qs as free form",
316 (filename[0] == '\0') ? "<stdin>" : filename);
320 /* If the user specified -fd-lines-as-{code|comments} verify that we're
321 in fixed form. */
322 if (gfc_current_form == FORM_FREE)
324 if (gfc_option.flag_d_lines == 0)
325 gfc_warning_now (0, "%<-fd-lines-as-comments%> has no effect "
326 "in free form");
327 else if (gfc_option.flag_d_lines == 1)
328 gfc_warning_now (0, "%<-fd-lines-as-code%> has no effect in free form");
330 if (warn_line_truncation == -1)
331 warn_line_truncation = 1;
333 /* Enable -Werror=line-truncation when -Werror and -Wno-error have
334 not been set. */
335 if (warn_line_truncation && !global_options_set.x_warnings_are_errors
336 && (global_dc->classify_diagnostic[OPT_Wline_truncation] ==
337 DK_UNSPECIFIED))
338 diagnostic_classify_diagnostic (global_dc, OPT_Wline_truncation,
339 DK_ERROR, UNKNOWN_LOCATION);
341 else
343 /* With -fdec, set -fd-lines-as-comments by default in fixed form. */
344 if (flag_dec && gfc_option.flag_d_lines == -1)
345 gfc_option.flag_d_lines = 0;
347 if (warn_line_truncation == -1)
348 warn_line_truncation = 0;
351 /* If -pedantic, warn about the use of GNU extensions. */
352 if (pedantic && (gfc_option.allow_std & GFC_STD_GNU) != 0)
353 gfc_option.warn_std |= GFC_STD_GNU;
354 /* -std=legacy -pedantic is effectively -std=gnu. */
355 if (pedantic && (gfc_option.allow_std & GFC_STD_LEGACY) != 0)
356 gfc_option.warn_std |= GFC_STD_F95_OBS | GFC_STD_F95_DEL | GFC_STD_LEGACY;
358 /* If the user didn't explicitly specify -f(no)-second-underscore we
359 use it if we're trying to be compatible with f2c, and not
360 otherwise. */
361 if (flag_second_underscore == -1)
362 flag_second_underscore = flag_f2c;
364 if (!flag_automatic && flag_max_stack_var_size != -2
365 && flag_max_stack_var_size != 0)
366 gfc_warning_now (0, "Flag %<-fno-automatic%> overwrites %<-fmax-stack-var-size=%d%>",
367 flag_max_stack_var_size);
368 else if (!flag_automatic && flag_recursive)
369 gfc_warning_now (0, "Flag %<-fno-automatic%> overwrites %<-frecursive%>");
370 else if (!flag_automatic && flag_openmp)
371 gfc_warning_now (0, "Flag %<-fno-automatic%> overwrites %<-frecursive%> implied by "
372 "%<-fopenmp%>");
373 else if (flag_max_stack_var_size != -2 && flag_recursive)
374 gfc_warning_now (0, "Flag %<-frecursive%> overwrites %<-fmax-stack-var-size=%d%>",
375 flag_max_stack_var_size);
376 else if (flag_max_stack_var_size != -2 && flag_openmp)
377 gfc_warning_now (0, "Flag %<-fmax-stack-var-size=%d%> overwrites %<-frecursive%> "
378 "implied by %<-fopenmp%>", flag_max_stack_var_size);
380 /* Implement -frecursive as -fmax-stack-var-size=-1. */
381 if (flag_recursive)
382 flag_max_stack_var_size = -1;
384 /* Implied -frecursive; implemented as -fmax-stack-var-size=-1. */
385 if (flag_max_stack_var_size == -2 && flag_openmp && flag_automatic)
387 flag_recursive = 1;
388 flag_max_stack_var_size = -1;
391 /* Set flag_stack_arrays correctly. */
392 if (flag_stack_arrays == -1)
393 flag_stack_arrays = 0;
395 /* Set default. */
396 if (flag_max_stack_var_size == -2)
397 flag_max_stack_var_size = 32768;
399 /* Implement -fno-automatic as -fmax-stack-var-size=0. */
400 if (!flag_automatic)
401 flag_max_stack_var_size = 0;
403 /* If the user did not specify an inline matmul limit, inline up to the BLAS
404 limit or up to 30 if no external BLAS is specified. */
406 if (flag_inline_matmul_limit < 0)
408 if (flag_external_blas)
409 flag_inline_matmul_limit = flag_blas_matmul_limit;
410 else
411 flag_inline_matmul_limit = 30;
414 /* Optimization implies front end optimization, unless the user
415 specified it directly. */
417 if (flag_frontend_optimize == -1)
418 flag_frontend_optimize = optimize;
420 /* Same for front end loop interchange. */
422 if (flag_frontend_loop_interchange == -1)
423 flag_frontend_loop_interchange = optimize;
425 if (flag_max_array_constructor < 65535)
426 flag_max_array_constructor = 65535;
428 if (flag_fixed_line_length != 0 && flag_fixed_line_length < 7)
429 gfc_fatal_error ("Fixed line length must be at least seven");
431 if (flag_free_line_length != 0 && flag_free_line_length < 4)
432 gfc_fatal_error ("Free line length must be at least three");
434 if (flag_max_subrecord_length > MAX_SUBRECORD_LENGTH)
435 gfc_fatal_error ("Maximum subrecord length cannot exceed %d",
436 MAX_SUBRECORD_LENGTH);
438 if (warn_return_type == -1)
439 warn_return_type = 0;
441 gfc_cpp_post_options ();
443 if (gfc_option.allow_std & GFC_STD_F2008)
444 lang_hooks.name = "GNU Fortran2008";
445 else if (gfc_option.allow_std & GFC_STD_F2003)
446 lang_hooks.name = "GNU Fortran2003";
448 return gfc_cpp_preprocess_only ();
452 static void
453 gfc_handle_module_path_options (const char *arg)
456 if (gfc_option.module_dir != NULL)
457 gfc_fatal_error ("gfortran: Only one %<-J%> option allowed");
459 gfc_option.module_dir = XCNEWVEC (char, strlen (arg) + 2);
460 strcpy (gfc_option.module_dir, arg);
462 gfc_add_include_path (gfc_option.module_dir, true, false, true);
464 strcat (gfc_option.module_dir, "/");
468 /* Handle options -ffpe-trap= and -ffpe-summary=. */
470 static void
471 gfc_handle_fpe_option (const char *arg, bool trap)
473 int result, pos = 0, n;
474 /* precision is a backwards compatibility alias for inexact. */
475 static const char * const exception[] = { "invalid", "denormal", "zero",
476 "overflow", "underflow",
477 "inexact", "precision", NULL };
478 static const int opt_exception[] = { GFC_FPE_INVALID, GFC_FPE_DENORMAL,
479 GFC_FPE_ZERO, GFC_FPE_OVERFLOW,
480 GFC_FPE_UNDERFLOW, GFC_FPE_INEXACT,
481 GFC_FPE_INEXACT,
482 0 };
484 /* As the default for -ffpe-summary= is nonzero, set it to 0. */
485 if (!trap)
486 gfc_option.fpe_summary = 0;
488 while (*arg)
490 while (*arg == ',')
491 arg++;
493 while (arg[pos] && arg[pos] != ',')
494 pos++;
496 result = 0;
497 if (!trap && strncmp ("none", arg, pos) == 0)
499 gfc_option.fpe_summary = 0;
500 arg += pos;
501 pos = 0;
502 continue;
504 else if (!trap && strncmp ("all", arg, pos) == 0)
506 gfc_option.fpe_summary = GFC_FPE_INVALID | GFC_FPE_DENORMAL
507 | GFC_FPE_ZERO | GFC_FPE_OVERFLOW
508 | GFC_FPE_UNDERFLOW | GFC_FPE_INEXACT;
509 arg += pos;
510 pos = 0;
511 continue;
513 else
514 for (n = 0; exception[n] != NULL; n++)
516 if (exception[n] && strncmp (exception[n], arg, pos) == 0)
518 if (trap)
519 gfc_option.fpe |= opt_exception[n];
520 else
521 gfc_option.fpe_summary |= opt_exception[n];
522 arg += pos;
523 pos = 0;
524 result = 1;
525 break;
528 if (!result && !trap)
529 gfc_fatal_error ("Argument to %<-ffpe-trap%> is not valid: %s", arg);
530 else if (!result)
531 gfc_fatal_error ("Argument to %<-ffpe-summary%> is not valid: %s", arg);
537 static void
538 gfc_handle_runtime_check_option (const char *arg)
540 int result, pos = 0, n;
541 static const char * const optname[] = { "all", "bounds", "array-temps",
542 "recursion", "do", "pointer",
543 "mem", NULL };
544 static const int optmask[] = { GFC_RTCHECK_ALL, GFC_RTCHECK_BOUNDS,
545 GFC_RTCHECK_ARRAY_TEMPS,
546 GFC_RTCHECK_RECURSION, GFC_RTCHECK_DO,
547 GFC_RTCHECK_POINTER, GFC_RTCHECK_MEM,
548 0 };
550 while (*arg)
552 while (*arg == ',')
553 arg++;
555 while (arg[pos] && arg[pos] != ',')
556 pos++;
558 result = 0;
559 for (n = 0; optname[n] != NULL; n++)
561 if (optname[n] && strncmp (optname[n], arg, pos) == 0)
563 gfc_option.rtcheck |= optmask[n];
564 arg += pos;
565 pos = 0;
566 result = 1;
567 break;
569 else if (optname[n] && pos > 3 && strncmp ("no-", arg, 3) == 0
570 && strncmp (optname[n], arg+3, pos-3) == 0)
572 gfc_option.rtcheck &= ~optmask[n];
573 arg += pos;
574 pos = 0;
575 result = 1;
576 break;
579 if (!result)
580 gfc_fatal_error ("Argument to %<-fcheck%> is not valid: %s", arg);
585 /* Handle command-line options. Returns 0 if unrecognized, 1 if
586 recognized and handled. */
588 bool
589 gfc_handle_option (size_t scode, const char *arg, int value,
590 int kind ATTRIBUTE_UNUSED, location_t loc ATTRIBUTE_UNUSED,
591 const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED)
593 bool result = true;
594 enum opt_code code = (enum opt_code) scode;
596 if (gfc_cpp_handle_option (scode, arg, value) == 1)
597 return true;
599 switch (code)
601 default:
602 if (cl_options[code].flags & gfc_option_lang_mask ())
603 break;
604 result = false;
605 break;
607 case OPT_fcheck_array_temporaries:
608 gfc_option.rtcheck |= GFC_RTCHECK_ARRAY_TEMPS;
609 break;
611 case OPT_fd_lines_as_code:
612 gfc_option.flag_d_lines = 1;
613 break;
615 case OPT_fd_lines_as_comments:
616 gfc_option.flag_d_lines = 0;
617 break;
619 case OPT_ffixed_form:
620 gfc_option.source_form = FORM_FIXED;
621 break;
623 case OPT_ffree_form:
624 gfc_option.source_form = FORM_FREE;
625 break;
627 case OPT_static_libgfortran:
628 #ifndef HAVE_LD_STATIC_DYNAMIC
629 gfc_fatal_error ("%<-static-libgfortran%> is not supported in this "
630 "configuration");
631 #endif
632 break;
634 case OPT_fintrinsic_modules_path:
635 case OPT_fintrinsic_modules_path_:
637 /* This is needed because omp_lib.h is in a directory together
638 with intrinsic modules. Do no warn because during testing
639 without an installed compiler, we would get lots of bogus
640 warnings for a missing include directory. */
641 gfc_add_include_path (arg, false, false, false);
643 gfc_add_intrinsic_modules_path (arg);
644 break;
646 case OPT_fpreprocessed:
647 gfc_option.flag_preprocessed = value;
648 break;
650 case OPT_fmax_identifier_length_:
651 if (value > GFC_MAX_SYMBOL_LEN)
652 gfc_fatal_error ("Maximum supported identifier length is %d",
653 GFC_MAX_SYMBOL_LEN);
654 gfc_option.max_identifier_length = value;
655 break;
657 case OPT_finit_local_zero:
658 gfc_option.flag_init_integer = GFC_INIT_INTEGER_ON;
659 gfc_option.flag_init_integer_value = 0;
660 flag_init_real = GFC_INIT_REAL_ZERO;
661 gfc_option.flag_init_logical = GFC_INIT_LOGICAL_FALSE;
662 gfc_option.flag_init_character = GFC_INIT_CHARACTER_ON;
663 gfc_option.flag_init_character_value = (char)0;
664 break;
666 case OPT_finit_logical_:
667 if (!strcasecmp (arg, "false"))
668 gfc_option.flag_init_logical = GFC_INIT_LOGICAL_FALSE;
669 else if (!strcasecmp (arg, "true"))
670 gfc_option.flag_init_logical = GFC_INIT_LOGICAL_TRUE;
671 else
672 gfc_fatal_error ("Unrecognized option to %<-finit-logical%>: %s",
673 arg);
674 break;
676 case OPT_finit_integer_:
677 gfc_option.flag_init_integer = GFC_INIT_INTEGER_ON;
678 gfc_option.flag_init_integer_value = atoi (arg);
679 break;
681 case OPT_finit_character_:
682 if (value >= 0 && value <= 127)
684 gfc_option.flag_init_character = GFC_INIT_CHARACTER_ON;
685 gfc_option.flag_init_character_value = (char)value;
687 else
688 gfc_fatal_error ("The value of n in %<-finit-character=n%> must be "
689 "between 0 and 127");
690 break;
692 case OPT_I:
693 gfc_add_include_path (arg, true, false, true);
694 break;
696 case OPT_J:
697 gfc_handle_module_path_options (arg);
698 break;
700 case OPT_ffpe_trap_:
701 gfc_handle_fpe_option (arg, true);
702 break;
704 case OPT_ffpe_summary_:
705 gfc_handle_fpe_option (arg, false);
706 break;
708 case OPT_std_f95:
709 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F95 | GFC_STD_F77
710 | GFC_STD_F2008_OBS;
711 gfc_option.warn_std = GFC_STD_F95_OBS;
712 gfc_option.max_continue_fixed = 19;
713 gfc_option.max_continue_free = 39;
714 gfc_option.max_identifier_length = 31;
715 warn_ampersand = 1;
716 warn_tabs = 1;
717 break;
719 case OPT_std_f2003:
720 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F77
721 | GFC_STD_F2003 | GFC_STD_F95 | GFC_STD_F2008_OBS;
722 gfc_option.warn_std = GFC_STD_F95_OBS;
723 gfc_option.max_identifier_length = 63;
724 warn_ampersand = 1;
725 warn_tabs = 1;
726 break;
728 case OPT_std_f2008:
729 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F77
730 | GFC_STD_F2003 | GFC_STD_F95 | GFC_STD_F2008 | GFC_STD_F2008_OBS;
731 gfc_option.warn_std = GFC_STD_F95_OBS | GFC_STD_F2008_OBS;
732 gfc_option.max_identifier_length = 63;
733 warn_ampersand = 1;
734 warn_tabs = 1;
735 break;
737 case OPT_std_f2008ts:
738 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F77
739 | GFC_STD_F2003 | GFC_STD_F95 | GFC_STD_F2008 | GFC_STD_F2008_OBS
740 | GFC_STD_F2008_TS;
741 gfc_option.warn_std = GFC_STD_F95_OBS | GFC_STD_F2008_OBS;
742 gfc_option.max_identifier_length = 63;
743 warn_ampersand = 1;
744 warn_tabs = 1;
745 break;
747 case OPT_std_gnu:
748 set_default_std_flags ();
749 break;
751 case OPT_std_legacy:
752 set_default_std_flags ();
753 gfc_option.warn_std = 0;
754 break;
756 case OPT_fshort_enums:
757 /* Handled in language-independent code. */
758 break;
760 case OPT_fcheck_:
761 gfc_handle_runtime_check_option (arg);
762 break;
764 case OPT_fdec:
765 /* Enable all DEC extensions. */
766 set_dec_flags (1);
767 break;
769 case OPT_fdec_structure:
770 flag_dec_structure = 1;
771 break;
774 Fortran_handle_option_auto (&global_options, &global_options_set,
775 scode, arg, value,
776 gfc_option_lang_mask (), kind,
777 loc, handlers, global_dc);
778 return result;
782 /* Return a string with the options passed to the compiler; used for
783 Fortran's compiler_options() intrinsic. */
785 char *
786 gfc_get_option_string (void)
788 unsigned j;
789 size_t len, pos;
790 char *result;
792 /* Allocate and return a one-character string with '\0'. */
793 if (!save_decoded_options_count)
794 return XCNEWVEC (char, 1);
796 /* Determine required string length. */
798 len = 0;
799 for (j = 1; j < save_decoded_options_count; j++)
801 switch (save_decoded_options[j].opt_index)
803 case OPT_o:
804 case OPT_d:
805 case OPT_dumpbase:
806 case OPT_dumpdir:
807 case OPT_auxbase:
808 case OPT_quiet:
809 case OPT_version:
810 case OPT_fintrinsic_modules_path:
811 case OPT_fintrinsic_modules_path_:
812 /* Ignore these. */
813 break;
814 default:
815 /* Ignore file names. */
816 if (save_decoded_options[j].orig_option_with_args_text[0] == '-')
817 len += 1
818 + strlen (save_decoded_options[j].orig_option_with_args_text);
822 result = XCNEWVEC (char, len);
824 pos = 0;
825 for (j = 1; j < save_decoded_options_count; j++)
827 switch (save_decoded_options[j].opt_index)
829 case OPT_o:
830 case OPT_d:
831 case OPT_dumpbase:
832 case OPT_dumpdir:
833 case OPT_auxbase:
834 case OPT_quiet:
835 case OPT_version:
836 case OPT_fintrinsic_modules_path:
837 case OPT_fintrinsic_modules_path_:
838 /* Ignore these. */
839 continue;
841 case OPT_cpp_:
842 /* Use "-cpp" rather than "-cpp=<temporary file>". */
843 len = 4;
844 break;
846 default:
847 /* Ignore file names. */
848 if (save_decoded_options[j].orig_option_with_args_text[0] != '-')
849 continue;
851 len = strlen (save_decoded_options[j].orig_option_with_args_text);
854 memcpy (&result[pos], save_decoded_options[j].orig_option_with_args_text, len);
855 pos += len;
856 result[pos++] = ' ';
859 result[--pos] = '\0';
860 return result;