2017-02-17 Vladimir Makarov <vmakarov@redhat.com>
[official-gcc.git] / gcc / fortran / options.c
blobdc8df5b8ed3ddf8685a9aa2cf2aecd5d8325f4d3
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 /* Allow legacy code without warnings. */
56 gfc_option.allow_std |= GFC_STD_F95_OBS | GFC_STD_F95_DEL
57 | GFC_STD_GNU | GFC_STD_LEGACY;
58 gfc_option.warn_std &= ~(GFC_STD_LEGACY | GFC_STD_F95_DEL);
60 /* Set -fd-lines-as-comments by default. */
61 if (value && gfc_current_form != FORM_FREE && gfc_option.flag_d_lines == -1)
62 gfc_option.flag_d_lines = 0;
64 /* Set other DEC compatibility extensions. */
65 flag_dollar_ok |= value;
66 flag_cray_pointer |= value;
67 flag_dec_structure |= value;
68 flag_dec_intrinsic_ints |= value;
69 flag_dec_static |= value;
70 flag_dec_math |= value;
74 /* Return language mask for Fortran options. */
76 unsigned int
77 gfc_option_lang_mask (void)
79 return CL_Fortran;
82 /* Initialize options structure OPTS. */
84 void
85 gfc_init_options_struct (struct gcc_options *opts)
87 opts->x_flag_errno_math = 0;
88 opts->frontend_set_flag_errno_math = true;
89 opts->x_flag_associative_math = -1;
90 opts->frontend_set_flag_associative_math = true;
93 /* Get ready for options handling. Keep in sync with
94 libgfortran/runtime/compile_options.c (init_compile_options). */
96 void
97 gfc_init_options (unsigned int decoded_options_count,
98 struct cl_decoded_option *decoded_options)
100 gfc_source_file = NULL;
101 gfc_option.module_dir = NULL;
102 gfc_option.source_form = FORM_UNKNOWN;
103 gfc_option.max_continue_fixed = 255;
104 gfc_option.max_continue_free = 255;
105 gfc_option.max_identifier_length = GFC_MAX_SYMBOL_LEN;
106 gfc_option.max_errors = 25;
108 gfc_option.flag_preprocessed = 0;
109 gfc_option.flag_d_lines = -1;
110 gfc_option.flag_init_integer = GFC_INIT_INTEGER_OFF;
111 gfc_option.flag_init_integer_value = 0;
112 gfc_option.flag_init_logical = GFC_INIT_LOGICAL_OFF;
113 gfc_option.flag_init_character = GFC_INIT_CHARACTER_OFF;
114 gfc_option.flag_init_character_value = (char)0;
116 gfc_option.fpe = 0;
117 /* All except GFC_FPE_INEXACT. */
118 gfc_option.fpe_summary = GFC_FPE_INVALID | GFC_FPE_DENORMAL
119 | GFC_FPE_ZERO | GFC_FPE_OVERFLOW
120 | GFC_FPE_UNDERFLOW;
121 gfc_option.rtcheck = 0;
123 /* ??? Wmissing-include-dirs is disabled by default in C/C++ but
124 enabled by default in Fortran. Ideally, we should express this
125 in .opt, but that is not supported yet. */
126 if (!global_options_set.x_cpp_warn_missing_include_dirs)
127 global_options.x_cpp_warn_missing_include_dirs = 1;
129 set_dec_flags (0);
131 set_default_std_flags ();
133 /* Initialize cpp-related options. */
134 gfc_cpp_init_options (decoded_options_count, decoded_options);
135 gfc_diagnostics_init ();
139 /* Determine the source form from the filename extension. We assume
140 case insensitivity. */
142 static gfc_source_form
143 form_from_filename (const char *filename)
145 static const struct
147 const char *extension;
148 gfc_source_form form;
150 exttype[] =
153 ".f90", FORM_FREE}
156 ".f95", FORM_FREE}
159 ".f03", FORM_FREE}
162 ".f08", FORM_FREE}
165 ".f", FORM_FIXED}
168 ".for", FORM_FIXED}
171 ".ftn", FORM_FIXED}
174 "", FORM_UNKNOWN}
175 }; /* sentinel value */
177 gfc_source_form f_form;
178 const char *fileext;
179 int i;
181 /* Find end of file name. Note, filename is either a NULL pointer or
182 a NUL terminated string. */
183 i = 0;
184 while (filename[i] != '\0')
185 i++;
187 /* Find last period. */
188 while (i >= 0 && (filename[i] != '.'))
189 i--;
191 /* Did we see a file extension? */
192 if (i < 0)
193 return FORM_UNKNOWN; /* Nope */
195 /* Get file extension and compare it to others. */
196 fileext = &(filename[i]);
198 i = -1;
199 f_form = FORM_UNKNOWN;
202 i++;
203 if (strcasecmp (fileext, exttype[i].extension) == 0)
205 f_form = exttype[i].form;
206 break;
209 while (exttype[i].form != FORM_UNKNOWN);
211 return f_form;
215 /* Finalize commandline options. */
217 bool
218 gfc_post_options (const char **pfilename)
220 const char *filename = *pfilename, *canon_source_file = NULL;
221 char *source_path;
222 int i;
224 /* Excess precision other than "fast" requires front-end
225 support. */
226 if (flag_excess_precision_cmdline == EXCESS_PRECISION_STANDARD)
227 sorry ("-fexcess-precision=standard for Fortran");
228 flag_excess_precision_cmdline = EXCESS_PRECISION_FAST;
230 /* Fortran allows associative math - but we cannot reassociate if
231 we want traps or signed zeros. Cf. also flag_protect_parens. */
232 if (flag_associative_math == -1)
233 flag_associative_math = (!flag_trapping_math && !flag_signed_zeros);
235 if (flag_protect_parens == -1)
236 flag_protect_parens = !optimize_fast;
238 if (flag_stack_arrays == -1)
239 flag_stack_arrays = optimize_fast;
241 /* By default, disable (re)allocation during assignment for -std=f95,
242 and enable it for F2003/F2008/GNU/Legacy. */
243 if (flag_realloc_lhs == -1)
245 if (gfc_option.allow_std & GFC_STD_F2003)
246 flag_realloc_lhs = 1;
247 else
248 flag_realloc_lhs = 0;
251 /* -fbounds-check is equivalent to -fcheck=bounds */
252 if (flag_bounds_check)
253 gfc_option.rtcheck |= GFC_RTCHECK_BOUNDS;
255 if (flag_compare_debug)
256 flag_dump_fortran_original = 0;
258 /* Make -fmax-errors visible to gfortran's diagnostic machinery. */
259 if (global_options_set.x_flag_max_errors)
260 gfc_option.max_errors = flag_max_errors;
262 /* Verify the input file name. */
263 if (!filename || strcmp (filename, "-") == 0)
265 filename = "";
268 if (gfc_option.flag_preprocessed)
270 /* For preprocessed files, if the first tokens are of the form # NUM.
271 handle the directives so we know the original file name. */
272 gfc_source_file = gfc_read_orig_filename (filename, &canon_source_file);
273 if (gfc_source_file == NULL)
274 gfc_source_file = filename;
275 else
276 *pfilename = gfc_source_file;
278 else
279 gfc_source_file = filename;
281 if (canon_source_file == NULL)
282 canon_source_file = gfc_source_file;
284 /* Adds the path where the source file is to the list of include files. */
286 i = strlen (canon_source_file);
287 while (i > 0 && !IS_DIR_SEPARATOR (canon_source_file[i]))
288 i--;
290 if (i != 0)
292 source_path = (char *) alloca (i + 1);
293 memcpy (source_path, canon_source_file, i);
294 source_path[i] = 0;
295 gfc_add_include_path (source_path, true, true, true);
297 else
298 gfc_add_include_path (".", true, true, true);
300 if (canon_source_file != gfc_source_file)
301 free (CONST_CAST (char *, canon_source_file));
303 /* Decide which form the file will be read in as. */
305 if (gfc_option.source_form != FORM_UNKNOWN)
306 gfc_current_form = gfc_option.source_form;
307 else
309 gfc_current_form = form_from_filename (filename);
311 if (gfc_current_form == FORM_UNKNOWN)
313 gfc_current_form = FORM_FREE;
314 gfc_warning_now (0, "Reading file %qs as free form",
315 (filename[0] == '\0') ? "<stdin>" : filename);
319 /* If the user specified -fd-lines-as-{code|comments} verify that we're
320 in fixed form. */
321 if (gfc_current_form == FORM_FREE)
323 if (gfc_option.flag_d_lines == 0)
324 gfc_warning_now (0, "%<-fd-lines-as-comments%> has no effect "
325 "in free form");
326 else if (gfc_option.flag_d_lines == 1)
327 gfc_warning_now (0, "%<-fd-lines-as-code%> has no effect in free form");
329 if (warn_line_truncation == -1)
330 warn_line_truncation = 1;
332 /* Enable -Werror=line-truncation when -Werror and -Wno-error have
333 not been set. */
334 if (warn_line_truncation && !global_options_set.x_warnings_are_errors
335 && (global_dc->classify_diagnostic[OPT_Wline_truncation] ==
336 DK_UNSPECIFIED))
337 diagnostic_classify_diagnostic (global_dc, OPT_Wline_truncation,
338 DK_ERROR, UNKNOWN_LOCATION);
340 else if (warn_line_truncation == -1)
341 warn_line_truncation = 0;
343 /* If -pedantic, warn about the use of GNU extensions. */
344 if (pedantic && (gfc_option.allow_std & GFC_STD_GNU) != 0)
345 gfc_option.warn_std |= GFC_STD_GNU;
346 /* -std=legacy -pedantic is effectively -std=gnu. */
347 if (pedantic && (gfc_option.allow_std & GFC_STD_LEGACY) != 0)
348 gfc_option.warn_std |= GFC_STD_F95_OBS | GFC_STD_F95_DEL | GFC_STD_LEGACY;
350 /* If the user didn't explicitly specify -f(no)-second-underscore we
351 use it if we're trying to be compatible with f2c, and not
352 otherwise. */
353 if (flag_second_underscore == -1)
354 flag_second_underscore = flag_f2c;
356 if (!flag_automatic && flag_max_stack_var_size != -2
357 && flag_max_stack_var_size != 0)
358 gfc_warning_now (0, "Flag %<-fno-automatic%> overwrites %<-fmax-stack-var-size=%d%>",
359 flag_max_stack_var_size);
360 else if (!flag_automatic && flag_recursive)
361 gfc_warning_now (0, "Flag %<-fno-automatic%> overwrites %<-frecursive%>");
362 else if (!flag_automatic && flag_openmp)
363 gfc_warning_now (0, "Flag %<-fno-automatic%> overwrites %<-frecursive%> implied by "
364 "%<-fopenmp%>");
365 else if (flag_max_stack_var_size != -2 && flag_recursive)
366 gfc_warning_now (0, "Flag %<-frecursive%> overwrites %<-fmax-stack-var-size=%d%>",
367 flag_max_stack_var_size);
368 else if (flag_max_stack_var_size != -2 && flag_openmp)
369 gfc_warning_now (0, "Flag %<-fmax-stack-var-size=%d%> overwrites %<-frecursive%> "
370 "implied by %<-fopenmp%>", flag_max_stack_var_size);
372 /* Implement -frecursive as -fmax-stack-var-size=-1. */
373 if (flag_recursive)
374 flag_max_stack_var_size = -1;
376 /* Implied -frecursive; implemented as -fmax-stack-var-size=-1. */
377 if (flag_max_stack_var_size == -2 && flag_openmp && flag_automatic)
379 flag_recursive = 1;
380 flag_max_stack_var_size = -1;
383 /* Set default. */
384 if (flag_max_stack_var_size == -2)
385 flag_max_stack_var_size = 32768;
387 /* Implement -fno-automatic as -fmax-stack-var-size=0. */
388 if (!flag_automatic)
389 flag_max_stack_var_size = 0;
391 /* If we call BLAS directly, only inline up to the BLAS limit. */
393 if (flag_external_blas && flag_inline_matmul_limit < 0)
394 flag_inline_matmul_limit = flag_blas_matmul_limit;
396 /* Optimization implies front end optimization, unless the user
397 specified it directly. */
399 if (flag_frontend_optimize == -1)
400 flag_frontend_optimize = optimize;
402 if (flag_max_array_constructor < 65535)
403 flag_max_array_constructor = 65535;
405 if (flag_fixed_line_length != 0 && flag_fixed_line_length < 7)
406 gfc_fatal_error ("Fixed line length must be at least seven");
408 if (flag_free_line_length != 0 && flag_free_line_length < 4)
409 gfc_fatal_error ("Free line length must be at least three");
411 if (flag_max_subrecord_length > MAX_SUBRECORD_LENGTH)
412 gfc_fatal_error ("Maximum subrecord length cannot exceed %d",
413 MAX_SUBRECORD_LENGTH);
415 gfc_cpp_post_options ();
417 if (gfc_option.allow_std & GFC_STD_F2008)
418 lang_hooks.name = "GNU Fortran2008";
419 else if (gfc_option.allow_std & GFC_STD_F2003)
420 lang_hooks.name = "GNU Fortran2003";
422 return gfc_cpp_preprocess_only ();
426 static void
427 gfc_handle_module_path_options (const char *arg)
430 if (gfc_option.module_dir != NULL)
431 gfc_fatal_error ("gfortran: Only one %<-J%> option allowed");
433 gfc_option.module_dir = XCNEWVEC (char, strlen (arg) + 2);
434 strcpy (gfc_option.module_dir, arg);
436 gfc_add_include_path (gfc_option.module_dir, true, false, true);
438 strcat (gfc_option.module_dir, "/");
442 /* Handle options -ffpe-trap= and -ffpe-summary=. */
444 static void
445 gfc_handle_fpe_option (const char *arg, bool trap)
447 int result, pos = 0, n;
448 /* precision is a backwards compatibility alias for inexact. */
449 static const char * const exception[] = { "invalid", "denormal", "zero",
450 "overflow", "underflow",
451 "inexact", "precision", NULL };
452 static const int opt_exception[] = { GFC_FPE_INVALID, GFC_FPE_DENORMAL,
453 GFC_FPE_ZERO, GFC_FPE_OVERFLOW,
454 GFC_FPE_UNDERFLOW, GFC_FPE_INEXACT,
455 GFC_FPE_INEXACT,
456 0 };
458 /* As the default for -ffpe-summary= is nonzero, set it to 0. */
459 if (!trap)
460 gfc_option.fpe_summary = 0;
462 while (*arg)
464 while (*arg == ',')
465 arg++;
467 while (arg[pos] && arg[pos] != ',')
468 pos++;
470 result = 0;
471 if (!trap && strncmp ("none", arg, pos) == 0)
473 gfc_option.fpe_summary = 0;
474 arg += pos;
475 pos = 0;
476 continue;
478 else if (!trap && strncmp ("all", arg, pos) == 0)
480 gfc_option.fpe_summary = GFC_FPE_INVALID | GFC_FPE_DENORMAL
481 | GFC_FPE_ZERO | GFC_FPE_OVERFLOW
482 | GFC_FPE_UNDERFLOW | GFC_FPE_INEXACT;
483 arg += pos;
484 pos = 0;
485 continue;
487 else
488 for (n = 0; exception[n] != NULL; n++)
490 if (exception[n] && strncmp (exception[n], arg, pos) == 0)
492 if (trap)
493 gfc_option.fpe |= opt_exception[n];
494 else
495 gfc_option.fpe_summary |= opt_exception[n];
496 arg += pos;
497 pos = 0;
498 result = 1;
499 break;
502 if (!result && !trap)
503 gfc_fatal_error ("Argument to %<-ffpe-trap%> is not valid: %s", arg);
504 else if (!result)
505 gfc_fatal_error ("Argument to %<-ffpe-summary%> is not valid: %s", arg);
511 static void
512 gfc_handle_runtime_check_option (const char *arg)
514 int result, pos = 0, n;
515 static const char * const optname[] = { "all", "bounds", "array-temps",
516 "recursion", "do", "pointer",
517 "mem", NULL };
518 static const int optmask[] = { GFC_RTCHECK_ALL, GFC_RTCHECK_BOUNDS,
519 GFC_RTCHECK_ARRAY_TEMPS,
520 GFC_RTCHECK_RECURSION, GFC_RTCHECK_DO,
521 GFC_RTCHECK_POINTER, GFC_RTCHECK_MEM,
522 0 };
524 while (*arg)
526 while (*arg == ',')
527 arg++;
529 while (arg[pos] && arg[pos] != ',')
530 pos++;
532 result = 0;
533 for (n = 0; optname[n] != NULL; n++)
535 if (optname[n] && strncmp (optname[n], arg, pos) == 0)
537 gfc_option.rtcheck |= optmask[n];
538 arg += pos;
539 pos = 0;
540 result = 1;
541 break;
543 else if (optname[n] && pos > 3 && strncmp ("no-", arg, 3) == 0
544 && strncmp (optname[n], arg+3, pos-3) == 0)
546 gfc_option.rtcheck &= ~optmask[n];
547 arg += pos;
548 pos = 0;
549 result = 1;
550 break;
553 if (!result)
554 gfc_fatal_error ("Argument to %<-fcheck%> is not valid: %s", arg);
559 /* Handle command-line options. Returns 0 if unrecognized, 1 if
560 recognized and handled. */
562 bool
563 gfc_handle_option (size_t scode, const char *arg, int value,
564 int kind ATTRIBUTE_UNUSED, location_t loc ATTRIBUTE_UNUSED,
565 const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED)
567 bool result = true;
568 enum opt_code code = (enum opt_code) scode;
570 if (gfc_cpp_handle_option (scode, arg, value) == 1)
571 return true;
573 switch (code)
575 default:
576 if (cl_options[code].flags & gfc_option_lang_mask ())
577 break;
578 result = false;
579 break;
581 case OPT_fcheck_array_temporaries:
582 gfc_option.rtcheck |= GFC_RTCHECK_ARRAY_TEMPS;
583 break;
585 case OPT_fd_lines_as_code:
586 gfc_option.flag_d_lines = 1;
587 break;
589 case OPT_fd_lines_as_comments:
590 gfc_option.flag_d_lines = 0;
591 break;
593 case OPT_ffixed_form:
594 gfc_option.source_form = FORM_FIXED;
595 break;
597 case OPT_ffree_form:
598 gfc_option.source_form = FORM_FREE;
599 break;
601 case OPT_static_libgfortran:
602 #ifndef HAVE_LD_STATIC_DYNAMIC
603 gfc_fatal_error ("%<-static-libgfortran%> is not supported in this "
604 "configuration");
605 #endif
606 break;
608 case OPT_fintrinsic_modules_path:
609 case OPT_fintrinsic_modules_path_:
611 /* This is needed because omp_lib.h is in a directory together
612 with intrinsic modules. Do no warn because during testing
613 without an installed compiler, we would get lots of bogus
614 warnings for a missing include directory. */
615 gfc_add_include_path (arg, false, false, false);
617 gfc_add_intrinsic_modules_path (arg);
618 break;
620 case OPT_fpreprocessed:
621 gfc_option.flag_preprocessed = value;
622 break;
624 case OPT_fmax_identifier_length_:
625 if (value > GFC_MAX_SYMBOL_LEN)
626 gfc_fatal_error ("Maximum supported identifier length is %d",
627 GFC_MAX_SYMBOL_LEN);
628 gfc_option.max_identifier_length = value;
629 break;
631 case OPT_finit_local_zero:
632 gfc_option.flag_init_integer = GFC_INIT_INTEGER_ON;
633 gfc_option.flag_init_integer_value = 0;
634 flag_init_real = GFC_INIT_REAL_ZERO;
635 gfc_option.flag_init_logical = GFC_INIT_LOGICAL_FALSE;
636 gfc_option.flag_init_character = GFC_INIT_CHARACTER_ON;
637 gfc_option.flag_init_character_value = (char)0;
638 break;
640 case OPT_finit_logical_:
641 if (!strcasecmp (arg, "false"))
642 gfc_option.flag_init_logical = GFC_INIT_LOGICAL_FALSE;
643 else if (!strcasecmp (arg, "true"))
644 gfc_option.flag_init_logical = GFC_INIT_LOGICAL_TRUE;
645 else
646 gfc_fatal_error ("Unrecognized option to %<-finit-logical%>: %s",
647 arg);
648 break;
650 case OPT_finit_integer_:
651 gfc_option.flag_init_integer = GFC_INIT_INTEGER_ON;
652 gfc_option.flag_init_integer_value = atoi (arg);
653 break;
655 case OPT_finit_character_:
656 if (value >= 0 && value <= 127)
658 gfc_option.flag_init_character = GFC_INIT_CHARACTER_ON;
659 gfc_option.flag_init_character_value = (char)value;
661 else
662 gfc_fatal_error ("The value of n in %<-finit-character=n%> must be "
663 "between 0 and 127");
664 break;
666 case OPT_I:
667 gfc_add_include_path (arg, true, false, true);
668 break;
670 case OPT_J:
671 gfc_handle_module_path_options (arg);
672 break;
674 case OPT_ffpe_trap_:
675 gfc_handle_fpe_option (arg, true);
676 break;
678 case OPT_ffpe_summary_:
679 gfc_handle_fpe_option (arg, false);
680 break;
682 case OPT_std_f95:
683 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F95 | GFC_STD_F77
684 | GFC_STD_F2008_OBS;
685 gfc_option.warn_std = GFC_STD_F95_OBS;
686 gfc_option.max_continue_fixed = 19;
687 gfc_option.max_continue_free = 39;
688 gfc_option.max_identifier_length = 31;
689 warn_ampersand = 1;
690 warn_tabs = 1;
691 break;
693 case OPT_std_f2003:
694 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F77
695 | GFC_STD_F2003 | GFC_STD_F95 | GFC_STD_F2008_OBS;
696 gfc_option.warn_std = GFC_STD_F95_OBS;
697 gfc_option.max_identifier_length = 63;
698 warn_ampersand = 1;
699 warn_tabs = 1;
700 break;
702 case OPT_std_f2008:
703 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F77
704 | GFC_STD_F2003 | GFC_STD_F95 | GFC_STD_F2008 | GFC_STD_F2008_OBS;
705 gfc_option.warn_std = GFC_STD_F95_OBS | GFC_STD_F2008_OBS;
706 gfc_option.max_identifier_length = 63;
707 warn_ampersand = 1;
708 warn_tabs = 1;
709 break;
711 case OPT_std_f2008ts:
712 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F77
713 | GFC_STD_F2003 | GFC_STD_F95 | GFC_STD_F2008 | GFC_STD_F2008_OBS
714 | GFC_STD_F2008_TS;
715 gfc_option.warn_std = GFC_STD_F95_OBS | GFC_STD_F2008_OBS;
716 gfc_option.max_identifier_length = 63;
717 warn_ampersand = 1;
718 warn_tabs = 1;
719 break;
721 case OPT_std_gnu:
722 set_default_std_flags ();
723 break;
725 case OPT_std_legacy:
726 set_default_std_flags ();
727 gfc_option.warn_std = 0;
728 break;
730 case OPT_fshort_enums:
731 /* Handled in language-independent code. */
732 break;
734 case OPT_fcheck_:
735 gfc_handle_runtime_check_option (arg);
736 break;
738 case OPT_fdec:
739 /* Enable all DEC extensions. */
740 set_dec_flags (1);
741 break;
743 case OPT_fdec_structure:
744 flag_dec_structure = 1;
745 break;
748 Fortran_handle_option_auto (&global_options, &global_options_set,
749 scode, arg, value,
750 gfc_option_lang_mask (), kind,
751 loc, handlers, global_dc);
752 return result;
756 /* Return a string with the options passed to the compiler; used for
757 Fortran's compiler_options() intrinsic. */
759 char *
760 gfc_get_option_string (void)
762 unsigned j;
763 size_t len, pos;
764 char *result;
766 /* Allocate and return a one-character string with '\0'. */
767 if (!save_decoded_options_count)
768 return XCNEWVEC (char, 1);
770 /* Determine required string length. */
772 len = 0;
773 for (j = 1; j < save_decoded_options_count; j++)
775 switch (save_decoded_options[j].opt_index)
777 case OPT_o:
778 case OPT_d:
779 case OPT_dumpbase:
780 case OPT_dumpdir:
781 case OPT_auxbase:
782 case OPT_quiet:
783 case OPT_version:
784 case OPT_fintrinsic_modules_path:
785 case OPT_fintrinsic_modules_path_:
786 /* Ignore these. */
787 break;
788 default:
789 /* Ignore file names. */
790 if (save_decoded_options[j].orig_option_with_args_text[0] == '-')
791 len += 1
792 + strlen (save_decoded_options[j].orig_option_with_args_text);
796 result = XCNEWVEC (char, len);
798 pos = 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 continue;
815 case OPT_cpp_:
816 /* Use "-cpp" rather than "-cpp=<temporary file>". */
817 len = 4;
818 break;
820 default:
821 /* Ignore file names. */
822 if (save_decoded_options[j].orig_option_with_args_text[0] != '-')
823 continue;
825 len = strlen (save_decoded_options[j].orig_option_with_args_text);
828 memcpy (&result[pos], save_decoded_options[j].orig_option_with_args_text, len);
829 pos += len;
830 result[pos++] = ' ';
833 result[--pos] = '\0';
834 return result;