2011-01-22 Tobias Burnus <burnus@net-b.de>
[official-gcc.git] / gcc / fortran / options.c
blob1f1cdd111d6c082d4406b23176fc10138a726572
1 /* Parse and display command line options.
2 Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
3 2009, 2010
4 Free Software Foundation, Inc.
5 Contributed by Andy Vaught
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 3, or (at your option) any later
12 version.
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 for more details.
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
23 #include "config.h"
24 #include "system.h"
25 #include "coretypes.h"
26 #include "tree.h"
27 #include "flags.h"
28 #include "intl.h"
29 #include "opts.h"
30 #include "toplev.h" /* For save_decoded_options. */
31 #include "options.h"
32 #include "params.h"
33 #include "tree-inline.h"
34 #include "gfortran.h"
35 #include "target.h"
36 #include "cpp.h"
37 #include "diagnostic-core.h" /* For sorry. */
38 #include "tm.h"
40 gfc_option_t gfc_option;
43 /* Set flags that control warnings and errors for different
44 Fortran standards to their default values. Keep in sync with
45 libgfortran/runtime/compile_options.c (init_compile_options). */
47 static void
48 set_default_std_flags (void)
50 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F95_DEL
51 | GFC_STD_F2003 | GFC_STD_F2008 | GFC_STD_F95 | GFC_STD_F77
52 | GFC_STD_F2008_OBS | GFC_STD_GNU | GFC_STD_LEGACY;
53 gfc_option.warn_std = GFC_STD_F95_DEL | GFC_STD_LEGACY;
57 /* Return language mask for Fortran options. */
59 unsigned int
60 gfc_option_lang_mask (void)
62 return CL_Fortran;
65 /* Initialize options structure OPTS. */
67 void
68 gfc_init_options_struct (struct gcc_options *opts)
70 opts->x_flag_errno_math = 0;
71 opts->x_flag_associative_math = -1;
74 /* Get ready for options handling. Keep in sync with
75 libgfortran/runtime/compile_options.c (init_compile_options). */
77 void
78 gfc_init_options (unsigned int decoded_options_count,
79 struct cl_decoded_option *decoded_options)
81 gfc_source_file = NULL;
82 gfc_option.module_dir = NULL;
83 gfc_option.source_form = FORM_UNKNOWN;
84 gfc_option.fixed_line_length = 72;
85 gfc_option.free_line_length = 132;
86 gfc_option.max_continue_fixed = 255;
87 gfc_option.max_continue_free = 255;
88 gfc_option.max_identifier_length = GFC_MAX_SYMBOL_LEN;
89 gfc_option.max_subrecord_length = 0;
90 gfc_option.flag_max_array_constructor = 65535;
91 gfc_option.convert = GFC_CONVERT_NATIVE;
92 gfc_option.record_marker = 0;
93 gfc_option.dump_fortran_original = 0;
94 gfc_option.dump_fortran_optimized = 0;
96 gfc_option.warn_aliasing = 0;
97 gfc_option.warn_ampersand = 0;
98 gfc_option.warn_character_truncation = 0;
99 gfc_option.warn_array_temp = 0;
100 gfc_option.gfc_warn_conversion = 0;
101 gfc_option.warn_conversion_extra = 0;
102 gfc_option.warn_implicit_interface = 0;
103 gfc_option.warn_line_truncation = 0;
104 gfc_option.warn_surprising = 0;
105 gfc_option.warn_tabs = 1;
106 gfc_option.warn_underflow = 1;
107 gfc_option.warn_intrinsic_shadow = 0;
108 gfc_option.warn_intrinsics_std = 0;
109 gfc_option.warn_align_commons = 1;
110 gfc_option.warn_unused_dummy_argument = 0;
111 gfc_option.max_errors = 25;
113 gfc_option.flag_all_intrinsics = 0;
114 gfc_option.flag_default_double = 0;
115 gfc_option.flag_default_integer = 0;
116 gfc_option.flag_default_real = 0;
117 gfc_option.flag_dollar_ok = 0;
118 gfc_option.flag_underscoring = 1;
119 gfc_option.flag_whole_file = 1;
120 gfc_option.flag_f2c = 0;
121 gfc_option.flag_second_underscore = -1;
122 gfc_option.flag_implicit_none = 0;
124 /* Default value of flag_max_stack_var_size is set in gfc_post_options. */
125 gfc_option.flag_max_stack_var_size = -2;
127 gfc_option.flag_range_check = 1;
128 gfc_option.flag_pack_derived = 0;
129 gfc_option.flag_repack_arrays = 0;
130 gfc_option.flag_preprocessed = 0;
131 gfc_option.flag_automatic = 1;
132 gfc_option.flag_backslash = 0;
133 gfc_option.flag_module_private = 0;
134 gfc_option.flag_backtrace = 0;
135 gfc_option.flag_allow_leading_underscore = 0;
136 gfc_option.flag_dump_core = 0;
137 gfc_option.flag_external_blas = 0;
138 gfc_option.blas_matmul_limit = 30;
139 gfc_option.flag_cray_pointer = 0;
140 gfc_option.flag_d_lines = -1;
141 gfc_option.gfc_flag_openmp = 0;
142 gfc_option.flag_sign_zero = 1;
143 gfc_option.flag_recursive = 0;
144 gfc_option.flag_init_integer = GFC_INIT_INTEGER_OFF;
145 gfc_option.flag_init_integer_value = 0;
146 gfc_option.flag_init_real = GFC_INIT_REAL_OFF;
147 gfc_option.flag_init_logical = GFC_INIT_LOGICAL_OFF;
148 gfc_option.flag_init_character = GFC_INIT_CHARACTER_OFF;
149 gfc_option.flag_init_character_value = (char)0;
150 gfc_option.flag_align_commons = 1;
151 gfc_option.flag_protect_parens = 1;
152 gfc_option.flag_realloc_lhs = -1;
154 gfc_option.fpe = 0;
155 gfc_option.rtcheck = 0;
156 gfc_option.coarray = GFC_FCOARRAY_NONE;
158 set_default_std_flags ();
160 /* Initialize cpp-related options. */
161 gfc_cpp_init_options (decoded_options_count, decoded_options);
165 /* Determine the source form from the filename extension. We assume
166 case insensitivity. */
168 static gfc_source_form
169 form_from_filename (const char *filename)
171 static const struct
173 const char *extension;
174 gfc_source_form form;
176 exttype[] =
179 ".f90", FORM_FREE}
182 ".f95", FORM_FREE}
185 ".f03", FORM_FREE}
188 ".f08", FORM_FREE}
191 ".f", FORM_FIXED}
194 ".for", FORM_FIXED}
197 ".ftn", FORM_FIXED}
200 "", FORM_UNKNOWN}
201 }; /* sentinel value */
203 gfc_source_form f_form;
204 const char *fileext;
205 int i;
207 /* Find end of file name. Note, filename is either a NULL pointer or
208 a NUL terminated string. */
209 i = 0;
210 while (filename[i] != '\0')
211 i++;
213 /* Find last period. */
214 while (i >= 0 && (filename[i] != '.'))
215 i--;
217 /* Did we see a file extension? */
218 if (i < 0)
219 return FORM_UNKNOWN; /* Nope */
221 /* Get file extension and compare it to others. */
222 fileext = &(filename[i]);
224 i = -1;
225 f_form = FORM_UNKNOWN;
228 i++;
229 if (strcasecmp (fileext, exttype[i].extension) == 0)
231 f_form = exttype[i].form;
232 break;
235 while (exttype[i].form != FORM_UNKNOWN);
237 return f_form;
241 /* Finalize commandline options. */
243 bool
244 gfc_post_options (const char **pfilename)
246 const char *filename = *pfilename, *canon_source_file = NULL;
247 char *source_path;
248 int i;
250 /* Excess precision other than "fast" requires front-end
251 support. */
252 if (flag_excess_precision_cmdline == EXCESS_PRECISION_STANDARD
253 && TARGET_FLT_EVAL_METHOD_NON_DEFAULT)
254 sorry ("-fexcess-precision=standard for Fortran");
255 flag_excess_precision_cmdline = EXCESS_PRECISION_FAST;
257 /* Whole program needs whole file mode. */
258 if (flag_whole_program)
259 gfc_option.flag_whole_file = 1;
261 /* Enable whole-file mode if LTO is in effect. */
262 if (flag_lto)
263 gfc_option.flag_whole_file = 1;
265 /* Fortran allows associative math - but we cannot reassociate if
266 we want traps or signed zeros. Cf. also flag_protect_parens. */
267 if (flag_associative_math == -1)
268 flag_associative_math = (!flag_trapping_math && !flag_signed_zeros);
270 /* By default, disable (re)allocation during assignment for -std=f95,
271 and enable it for F2003/F2008/GNU/Legacy. */
272 if (gfc_option.flag_realloc_lhs == -1)
274 if (gfc_option.allow_std & GFC_STD_F2003)
275 gfc_option.flag_realloc_lhs = 1;
276 else
277 gfc_option.flag_realloc_lhs = 0;
280 /* -fbounds-check is equivalent to -fcheck=bounds */
281 if (flag_bounds_check)
282 gfc_option.rtcheck |= GFC_RTCHECK_BOUNDS;
284 if (flag_compare_debug)
285 gfc_option.dump_fortran_original = 0;
287 /* Make -fmax-errors visible to gfortran's diagnostic machinery. */
288 if (global_options_set.x_flag_max_errors)
289 gfc_option.max_errors = flag_max_errors;
291 /* Verify the input file name. */
292 if (!filename || strcmp (filename, "-") == 0)
294 filename = "";
297 if (gfc_option.flag_preprocessed)
299 /* For preprocessed files, if the first tokens are of the form # NUM.
300 handle the directives so we know the original file name. */
301 gfc_source_file = gfc_read_orig_filename (filename, &canon_source_file);
302 if (gfc_source_file == NULL)
303 gfc_source_file = filename;
304 else
305 *pfilename = gfc_source_file;
307 else
308 gfc_source_file = filename;
310 if (canon_source_file == NULL)
311 canon_source_file = gfc_source_file;
313 /* Adds the path where the source file is to the list of include files. */
315 i = strlen (canon_source_file);
316 while (i > 0 && !IS_DIR_SEPARATOR (canon_source_file[i]))
317 i--;
319 if (i != 0)
321 source_path = (char *) alloca (i + 1);
322 memcpy (source_path, canon_source_file, i);
323 source_path[i] = 0;
324 gfc_add_include_path (source_path, true, true);
326 else
327 gfc_add_include_path (".", true, true);
329 if (canon_source_file != gfc_source_file)
330 gfc_free (CONST_CAST (char *, canon_source_file));
332 /* Decide which form the file will be read in as. */
334 if (gfc_option.source_form != FORM_UNKNOWN)
335 gfc_current_form = gfc_option.source_form;
336 else
338 gfc_current_form = form_from_filename (filename);
340 if (gfc_current_form == FORM_UNKNOWN)
342 gfc_current_form = FORM_FREE;
343 gfc_warning_now ("Reading file '%s' as free form",
344 (filename[0] == '\0') ? "<stdin>" : filename);
348 /* If the user specified -fd-lines-as-{code|comments} verify that we're
349 in fixed form. */
350 if (gfc_current_form == FORM_FREE)
352 if (gfc_option.flag_d_lines == 0)
353 gfc_warning_now ("'-fd-lines-as-comments' has no effect "
354 "in free form");
355 else if (gfc_option.flag_d_lines == 1)
356 gfc_warning_now ("'-fd-lines-as-code' has no effect in free form");
359 /* If -pedantic, warn about the use of GNU extensions. */
360 if (pedantic && (gfc_option.allow_std & GFC_STD_GNU) != 0)
361 gfc_option.warn_std |= GFC_STD_GNU;
362 /* -std=legacy -pedantic is effectively -std=gnu. */
363 if (pedantic && (gfc_option.allow_std & GFC_STD_LEGACY) != 0)
364 gfc_option.warn_std |= GFC_STD_F95_OBS | GFC_STD_F95_DEL | GFC_STD_LEGACY;
366 /* If the user didn't explicitly specify -f(no)-second-underscore we
367 use it if we're trying to be compatible with f2c, and not
368 otherwise. */
369 if (gfc_option.flag_second_underscore == -1)
370 gfc_option.flag_second_underscore = gfc_option.flag_f2c;
372 if (!gfc_option.flag_automatic && gfc_option.flag_max_stack_var_size != -2
373 && gfc_option.flag_max_stack_var_size != 0)
374 gfc_warning_now ("Flag -fno-automatic overwrites -fmax-stack-var-size=%d",
375 gfc_option.flag_max_stack_var_size);
376 else if (!gfc_option.flag_automatic && gfc_option.flag_recursive)
377 gfc_warning_now ("Flag -fno-automatic overwrites -frecursive");
378 else if (!gfc_option.flag_automatic && gfc_option.gfc_flag_openmp)
379 gfc_warning_now ("Flag -fno-automatic overwrites -frecursive implied by "
380 "-fopenmp");
381 else if (gfc_option.flag_max_stack_var_size != -2
382 && gfc_option.flag_recursive)
383 gfc_warning_now ("Flag -frecursive overwrites -fmax-stack-var-size=%d",
384 gfc_option.flag_max_stack_var_size);
385 else if (gfc_option.flag_max_stack_var_size != -2
386 && gfc_option.gfc_flag_openmp)
387 gfc_warning_now ("Flag -fmax-stack-var-size=%d overwrites -frecursive "
388 "implied by -fopenmp",
389 gfc_option.flag_max_stack_var_size);
391 /* Implement -frecursive as -fmax-stack-var-size=-1. */
392 if (gfc_option.flag_recursive)
393 gfc_option.flag_max_stack_var_size = -1;
395 /* Implied -frecursive; implemented as -fmax-stack-var-size=-1. */
396 if (gfc_option.flag_max_stack_var_size == -2 && gfc_option.gfc_flag_openmp
397 && gfc_option.flag_automatic)
399 gfc_option.flag_recursive = 1;
400 gfc_option.flag_max_stack_var_size = -1;
403 /* Set default. */
404 if (gfc_option.flag_max_stack_var_size == -2)
405 gfc_option.flag_max_stack_var_size = 32768;
407 /* Implement -fno-automatic as -fmax-stack-var-size=0. */
408 if (!gfc_option.flag_automatic)
409 gfc_option.flag_max_stack_var_size = 0;
411 if (pedantic)
413 gfc_option.warn_ampersand = 1;
414 gfc_option.warn_tabs = 0;
417 if (pedantic && gfc_option.flag_whole_file)
418 gfc_option.flag_whole_file = 2;
420 gfc_cpp_post_options ();
422 /* FIXME: return gfc_cpp_preprocess_only ();
424 The return value of this function indicates whether the
425 backend needs to be initialized. On -E, we don't need
426 the backend. However, if we return 'true' here, an
427 ICE occurs. Initializing the backend doesn't hurt much,
428 hence, for now we can live with it as is. */
429 return false;
433 /* Set the options for -Wall. */
435 static void
436 set_Wall (int setting)
438 gfc_option.warn_aliasing = setting;
439 gfc_option.warn_ampersand = setting;
440 gfc_option.gfc_warn_conversion = setting;
441 gfc_option.warn_line_truncation = setting;
442 gfc_option.warn_surprising = setting;
443 gfc_option.warn_tabs = !setting;
444 gfc_option.warn_underflow = setting;
445 gfc_option.warn_intrinsic_shadow = setting;
446 gfc_option.warn_intrinsics_std = setting;
447 gfc_option.warn_character_truncation = setting;
448 gfc_option.warn_unused_dummy_argument = setting;
450 warn_unused = setting;
451 warn_return_type = setting;
452 warn_switch = setting;
453 warn_uninitialized = setting;
457 static void
458 gfc_handle_module_path_options (const char *arg)
461 if (gfc_option.module_dir != NULL)
462 gfc_fatal_error ("gfortran: Only one -J option allowed");
464 gfc_option.module_dir = (char *) gfc_getmem (strlen (arg) + 2);
465 strcpy (gfc_option.module_dir, arg);
466 strcat (gfc_option.module_dir, "/");
468 gfc_add_include_path (gfc_option.module_dir, true, false);
472 static void
473 gfc_handle_fpe_trap_option (const char *arg)
475 int result, pos = 0, n;
476 static const char * const exception[] = { "invalid", "denormal", "zero",
477 "overflow", "underflow",
478 "precision", NULL };
479 static const int opt_exception[] = { GFC_FPE_INVALID, GFC_FPE_DENORMAL,
480 GFC_FPE_ZERO, GFC_FPE_OVERFLOW,
481 GFC_FPE_UNDERFLOW, GFC_FPE_PRECISION,
482 0 };
484 while (*arg)
486 while (*arg == ',')
487 arg++;
489 while (arg[pos] && arg[pos] != ',')
490 pos++;
492 result = 0;
493 for (n = 0; exception[n] != NULL; n++)
495 if (exception[n] && strncmp (exception[n], arg, pos) == 0)
497 gfc_option.fpe |= opt_exception[n];
498 arg += pos;
499 pos = 0;
500 result = 1;
501 break;
504 if (!result)
505 gfc_fatal_error ("Argument to -ffpe-trap is not valid: %s", arg);
510 static void
511 gfc_handle_coarray_option (const char *arg)
513 if (strcmp (arg, "none") == 0)
514 gfc_option.coarray = GFC_FCOARRAY_NONE;
515 else if (strcmp (arg, "single") == 0)
516 gfc_option.coarray = GFC_FCOARRAY_SINGLE;
517 else
518 gfc_fatal_error ("Argument to -fcoarray is not valid: %s", arg);
522 static void
523 gfc_handle_runtime_check_option (const char *arg)
525 int result, pos = 0, n;
526 static const char * const optname[] = { "all", "bounds", "array-temps",
527 "recursion", "do", "pointer",
528 "mem", NULL };
529 static const int optmask[] = { GFC_RTCHECK_ALL, GFC_RTCHECK_BOUNDS,
530 GFC_RTCHECK_ARRAY_TEMPS,
531 GFC_RTCHECK_RECURSION, GFC_RTCHECK_DO,
532 GFC_RTCHECK_POINTER, GFC_RTCHECK_MEM,
533 0 };
535 while (*arg)
537 while (*arg == ',')
538 arg++;
540 while (arg[pos] && arg[pos] != ',')
541 pos++;
543 result = 0;
544 for (n = 0; optname[n] != NULL; n++)
546 if (optname[n] && strncmp (optname[n], arg, pos) == 0)
548 gfc_option.rtcheck |= optmask[n];
549 arg += pos;
550 pos = 0;
551 result = 1;
552 break;
555 if (!result)
556 gfc_fatal_error ("Argument to -fcheck is not valid: %s", arg);
561 /* Handle command-line options. Returns 0 if unrecognized, 1 if
562 recognized and handled. */
564 bool
565 gfc_handle_option (size_t scode, const char *arg, int value,
566 int kind ATTRIBUTE_UNUSED, location_t loc ATTRIBUTE_UNUSED,
567 const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED)
569 bool result = true;
570 enum opt_code code = (enum opt_code) scode;
572 if (gfc_cpp_handle_option (scode, arg, value) == 1)
573 return true;
575 switch (code)
577 default:
578 result = false;
579 break;
581 case OPT_Wall:
582 set_Wall (value);
583 break;
585 case OPT_Waliasing:
586 gfc_option.warn_aliasing = value;
587 break;
589 case OPT_Wampersand:
590 gfc_option.warn_ampersand = value;
591 break;
593 case OPT_Warray_temporaries:
594 gfc_option.warn_array_temp = value;
595 break;
597 case OPT_Wcharacter_truncation:
598 gfc_option.warn_character_truncation = value;
599 break;
601 case OPT_Wconversion:
602 gfc_option.gfc_warn_conversion = value;
603 break;
605 case OPT_Wconversion_extra:
606 gfc_option.warn_conversion_extra = value;
607 break;
609 case OPT_Wimplicit_interface:
610 gfc_option.warn_implicit_interface = value;
611 break;
613 case OPT_Wimplicit_procedure:
614 gfc_option.warn_implicit_procedure = value;
615 break;
617 case OPT_Wline_truncation:
618 gfc_option.warn_line_truncation = value;
619 break;
621 case OPT_Wreturn_type:
622 warn_return_type = value;
623 break;
625 case OPT_Wsurprising:
626 gfc_option.warn_surprising = value;
627 break;
629 case OPT_Wtabs:
630 gfc_option.warn_tabs = value;
631 break;
633 case OPT_Wunderflow:
634 gfc_option.warn_underflow = value;
635 break;
637 case OPT_Wintrinsic_shadow:
638 gfc_option.warn_intrinsic_shadow = value;
639 break;
641 case OPT_Walign_commons:
642 gfc_option.warn_align_commons = value;
643 break;
645 case OPT_Wunused_dummy_argument:
646 gfc_option.warn_unused_dummy_argument = value;
647 break;
649 case OPT_fall_intrinsics:
650 gfc_option.flag_all_intrinsics = 1;
651 break;
653 case OPT_fautomatic:
654 gfc_option.flag_automatic = value;
655 break;
657 case OPT_fallow_leading_underscore:
658 gfc_option.flag_allow_leading_underscore = value;
659 break;
661 case OPT_fbackslash:
662 gfc_option.flag_backslash = value;
663 break;
665 case OPT_fbacktrace:
666 gfc_option.flag_backtrace = value;
667 break;
669 case OPT_fcheck_array_temporaries:
670 gfc_option.rtcheck |= GFC_RTCHECK_ARRAY_TEMPS;
671 break;
673 case OPT_fdump_core:
674 gfc_option.flag_dump_core = value;
675 break;
677 case OPT_fcray_pointer:
678 gfc_option.flag_cray_pointer = value;
679 break;
681 case OPT_ff2c:
682 gfc_option.flag_f2c = value;
683 break;
685 case OPT_fdollar_ok:
686 gfc_option.flag_dollar_ok = value;
687 break;
689 case OPT_fexternal_blas:
690 gfc_option.flag_external_blas = value;
691 break;
693 case OPT_fblas_matmul_limit_:
694 gfc_option.blas_matmul_limit = value;
695 break;
697 case OPT_fd_lines_as_code:
698 gfc_option.flag_d_lines = 1;
699 break;
701 case OPT_fd_lines_as_comments:
702 gfc_option.flag_d_lines = 0;
703 break;
705 case OPT_fdump_fortran_original:
706 case OPT_fdump_parse_tree:
707 gfc_option.dump_fortran_original = value;
708 break;
710 case OPT_fdump_fortran_optimized:
711 gfc_option.dump_fortran_optimized = value;
712 break;
714 case OPT_ffixed_form:
715 gfc_option.source_form = FORM_FIXED;
716 break;
718 case OPT_ffixed_line_length_none:
719 gfc_option.fixed_line_length = 0;
720 break;
722 case OPT_ffixed_line_length_:
723 if (value != 0 && value < 7)
724 gfc_fatal_error ("Fixed line length must be at least seven.");
725 gfc_option.fixed_line_length = value;
726 break;
728 case OPT_ffree_form:
729 gfc_option.source_form = FORM_FREE;
730 break;
732 case OPT_fopenmp:
733 gfc_option.gfc_flag_openmp = value;
734 break;
736 case OPT_ffree_line_length_none:
737 gfc_option.free_line_length = 0;
738 break;
740 case OPT_ffree_line_length_:
741 if (value != 0 && value < 4)
742 gfc_fatal_error ("Free line length must be at least three.");
743 gfc_option.free_line_length = value;
744 break;
746 case OPT_funderscoring:
747 gfc_option.flag_underscoring = value;
748 break;
750 case OPT_fwhole_file:
751 gfc_option.flag_whole_file = value;
752 break;
754 case OPT_fsecond_underscore:
755 gfc_option.flag_second_underscore = value;
756 break;
758 case OPT_static_libgfortran:
759 #ifndef HAVE_LD_STATIC_DYNAMIC
760 gfc_fatal_error ("-static-libgfortran is not supported in this "
761 "configuration");
762 #endif
763 break;
765 case OPT_fimplicit_none:
766 gfc_option.flag_implicit_none = value;
767 break;
769 case OPT_fintrinsic_modules_path:
770 gfc_add_include_path (arg, false, false);
771 gfc_add_intrinsic_modules_path (arg);
772 break;
774 case OPT_fmax_array_constructor_:
775 gfc_option.flag_max_array_constructor = value > 65535 ? value : 65535;
776 break;
778 case OPT_fmax_stack_var_size_:
779 gfc_option.flag_max_stack_var_size = value;
780 break;
782 case OPT_fmodule_private:
783 gfc_option.flag_module_private = value;
784 break;
786 case OPT_frange_check:
787 gfc_option.flag_range_check = value;
788 break;
790 case OPT_fpack_derived:
791 gfc_option.flag_pack_derived = value;
792 break;
794 case OPT_frepack_arrays:
795 gfc_option.flag_repack_arrays = value;
796 break;
798 case OPT_fpreprocessed:
799 gfc_option.flag_preprocessed = value;
800 break;
802 case OPT_fmax_identifier_length_:
803 if (value > GFC_MAX_SYMBOL_LEN)
804 gfc_fatal_error ("Maximum supported identifier length is %d",
805 GFC_MAX_SYMBOL_LEN);
806 gfc_option.max_identifier_length = value;
807 break;
809 case OPT_fdefault_integer_8:
810 gfc_option.flag_default_integer = value;
811 break;
813 case OPT_fdefault_real_8:
814 gfc_option.flag_default_real = value;
815 break;
817 case OPT_fdefault_double_8:
818 gfc_option.flag_default_double = value;
819 break;
821 case OPT_finit_local_zero:
822 gfc_option.flag_init_integer = GFC_INIT_INTEGER_ON;
823 gfc_option.flag_init_integer_value = 0;
824 gfc_option.flag_init_real = GFC_INIT_REAL_ZERO;
825 gfc_option.flag_init_logical = GFC_INIT_LOGICAL_FALSE;
826 gfc_option.flag_init_character = GFC_INIT_CHARACTER_ON;
827 gfc_option.flag_init_character_value = (char)0;
828 break;
830 case OPT_finit_logical_:
831 if (!strcasecmp (arg, "false"))
832 gfc_option.flag_init_logical = GFC_INIT_LOGICAL_FALSE;
833 else if (!strcasecmp (arg, "true"))
834 gfc_option.flag_init_logical = GFC_INIT_LOGICAL_TRUE;
835 else
836 gfc_fatal_error ("Unrecognized option to -finit-logical: %s",
837 arg);
838 break;
840 case OPT_finit_real_:
841 if (!strcasecmp (arg, "zero"))
842 gfc_option.flag_init_real = GFC_INIT_REAL_ZERO;
843 else if (!strcasecmp (arg, "nan"))
844 gfc_option.flag_init_real = GFC_INIT_REAL_NAN;
845 else if (!strcasecmp (arg, "snan"))
846 gfc_option.flag_init_real = GFC_INIT_REAL_SNAN;
847 else if (!strcasecmp (arg, "inf"))
848 gfc_option.flag_init_real = GFC_INIT_REAL_INF;
849 else if (!strcasecmp (arg, "-inf"))
850 gfc_option.flag_init_real = GFC_INIT_REAL_NEG_INF;
851 else
852 gfc_fatal_error ("Unrecognized option to -finit-real: %s",
853 arg);
854 break;
856 case OPT_finit_integer_:
857 gfc_option.flag_init_integer = GFC_INIT_INTEGER_ON;
858 gfc_option.flag_init_integer_value = atoi (arg);
859 break;
861 case OPT_finit_character_:
862 if (value >= 0 && value <= 127)
864 gfc_option.flag_init_character = GFC_INIT_CHARACTER_ON;
865 gfc_option.flag_init_character_value = (char)value;
867 else
868 gfc_fatal_error ("The value of n in -finit-character=n must be "
869 "between 0 and 127");
870 break;
872 case OPT_I:
873 gfc_add_include_path (arg, true, false);
874 break;
876 case OPT_J:
877 gfc_handle_module_path_options (arg);
878 break;
880 case OPT_fsign_zero:
881 gfc_option.flag_sign_zero = value;
882 break;
884 case OPT_ffpe_trap_:
885 gfc_handle_fpe_trap_option (arg);
886 break;
888 case OPT_std_f95:
889 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F95 | GFC_STD_F77
890 | GFC_STD_F2008_OBS;
891 gfc_option.warn_std = GFC_STD_F95_OBS;
892 gfc_option.max_continue_fixed = 19;
893 gfc_option.max_continue_free = 39;
894 gfc_option.max_identifier_length = 31;
895 gfc_option.warn_ampersand = 1;
896 gfc_option.warn_tabs = 0;
897 break;
899 case OPT_std_f2003:
900 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F77
901 | GFC_STD_F2003 | GFC_STD_F95 | GFC_STD_F2008_OBS;
902 gfc_option.warn_std = GFC_STD_F95_OBS;
903 gfc_option.max_identifier_length = 63;
904 gfc_option.warn_ampersand = 1;
905 gfc_option.warn_tabs = 0;
906 break;
908 case OPT_std_f2008:
909 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F77
910 | GFC_STD_F2003 | GFC_STD_F95 | GFC_STD_F2008 | GFC_STD_F2008_OBS;
911 gfc_option.warn_std = GFC_STD_F95_OBS | GFC_STD_F2008_OBS;
912 gfc_option.max_identifier_length = 63;
913 gfc_option.warn_ampersand = 1;
914 gfc_option.warn_tabs = 0;
915 break;
917 case OPT_std_gnu:
918 set_default_std_flags ();
919 break;
921 case OPT_std_legacy:
922 set_default_std_flags ();
923 gfc_option.warn_std = 0;
924 break;
926 case OPT_Wintrinsics_std:
927 gfc_option.warn_intrinsics_std = value;
928 break;
930 case OPT_fshort_enums:
931 /* Handled in language-independent code. */
932 break;
934 case OPT_fconvert_little_endian:
935 gfc_option.convert = GFC_CONVERT_LITTLE;
936 break;
938 case OPT_fconvert_big_endian:
939 gfc_option.convert = GFC_CONVERT_BIG;
940 break;
942 case OPT_fconvert_native:
943 gfc_option.convert = GFC_CONVERT_NATIVE;
944 break;
946 case OPT_fconvert_swap:
947 gfc_option.convert = GFC_CONVERT_SWAP;
948 break;
950 case OPT_frecord_marker_4:
951 gfc_option.record_marker = 4;
952 break;
954 case OPT_frecord_marker_8:
955 gfc_option.record_marker = 8;
956 break;
958 case OPT_fmax_subrecord_length_:
959 if (value > MAX_SUBRECORD_LENGTH)
960 gfc_fatal_error ("Maximum subrecord length cannot exceed %d",
961 MAX_SUBRECORD_LENGTH);
963 gfc_option.max_subrecord_length = value;
964 break;
966 case OPT_frecursive:
967 gfc_option.flag_recursive = value;
968 break;
970 case OPT_falign_commons:
971 gfc_option.flag_align_commons = value;
972 break;
974 case OPT_fprotect_parens:
975 gfc_option.flag_protect_parens = value;
976 break;
978 case OPT_frealloc_lhs:
979 gfc_option.flag_realloc_lhs = value;
980 break;
982 case OPT_fcheck_:
983 gfc_handle_runtime_check_option (arg);
984 break;
986 case OPT_fcoarray_:
987 gfc_handle_coarray_option (arg);
988 break;
991 return result;
995 /* Return a string with the options passed to the compiler; used for
996 Fortran's compiler_options() intrinsic. */
998 char *
999 gfc_get_option_string (void)
1001 unsigned j;
1002 size_t len, pos;
1003 char *result;
1005 /* Determine required string length. */
1007 len = 0;
1008 for (j = 1; j < save_decoded_options_count; j++)
1010 switch (save_decoded_options[j].opt_index)
1012 case OPT_o:
1013 case OPT_d:
1014 case OPT_dumpbase:
1015 case OPT_dumpdir:
1016 case OPT_auxbase:
1017 case OPT_quiet:
1018 case OPT_version:
1019 case OPT_fintrinsic_modules_path:
1020 /* Ignore these. */
1021 break;
1022 default:
1023 /* Ignore file names. */
1024 if (save_decoded_options[j].orig_option_with_args_text[0] == '-')
1025 len += 1
1026 + strlen (save_decoded_options[j].orig_option_with_args_text);
1030 result = (char *) gfc_getmem (len);
1032 pos = 0;
1033 for (j = 1; j < save_decoded_options_count; j++)
1035 switch (save_decoded_options[j].opt_index)
1037 case OPT_o:
1038 case OPT_d:
1039 case OPT_dumpbase:
1040 case OPT_dumpdir:
1041 case OPT_auxbase:
1042 case OPT_quiet:
1043 case OPT_version:
1044 case OPT_fintrinsic_modules_path:
1045 /* Ignore these. */
1046 continue;
1048 case OPT_cpp_:
1049 /* Use "-cpp" rather than "-cpp=<temporary file>". */
1050 len = 4;
1051 break;
1053 default:
1054 /* Ignore file names. */
1055 if (save_decoded_options[j].orig_option_with_args_text[0] != '-')
1056 continue;
1058 len = strlen (save_decoded_options[j].orig_option_with_args_text);
1061 memcpy (&result[pos], save_decoded_options[j].orig_option_with_args_text, len);
1062 pos += len;
1063 result[pos++] = ' ';
1066 result[--pos] = '\0';
1067 return result;