2011-05-02 Steven G. Kargl <kargl@gcc.gnu.org>
[official-gcc.git] / gcc / fortran / options.c
blobf56fad7fce46da42287402b2fccbc0c96fb88694
1 /* Parse and display command line options.
2 Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
3 2009, 2010, 2011
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_function_elimination = 0;
103 gfc_option.warn_implicit_interface = 0;
104 gfc_option.warn_line_truncation = 0;
105 gfc_option.warn_surprising = 0;
106 gfc_option.warn_tabs = 1;
107 gfc_option.warn_underflow = 1;
108 gfc_option.warn_intrinsic_shadow = 0;
109 gfc_option.warn_intrinsics_std = 0;
110 gfc_option.warn_align_commons = 1;
111 gfc_option.warn_real_q_constant = 0;
112 gfc_option.warn_unused_dummy_argument = 0;
113 gfc_option.max_errors = 25;
115 gfc_option.flag_all_intrinsics = 0;
116 gfc_option.flag_default_double = 0;
117 gfc_option.flag_default_integer = 0;
118 gfc_option.flag_default_real = 0;
119 gfc_option.flag_dollar_ok = 0;
120 gfc_option.flag_underscoring = 1;
121 gfc_option.flag_whole_file = 1;
122 gfc_option.flag_f2c = 0;
123 gfc_option.flag_second_underscore = -1;
124 gfc_option.flag_implicit_none = 0;
126 /* Default value of flag_max_stack_var_size is set in gfc_post_options. */
127 gfc_option.flag_max_stack_var_size = -2;
128 gfc_option.flag_stack_arrays = 0;
130 gfc_option.flag_range_check = 1;
131 gfc_option.flag_pack_derived = 0;
132 gfc_option.flag_repack_arrays = 0;
133 gfc_option.flag_preprocessed = 0;
134 gfc_option.flag_automatic = 1;
135 gfc_option.flag_backslash = 0;
136 gfc_option.flag_module_private = 0;
137 gfc_option.flag_backtrace = 0;
138 gfc_option.flag_allow_leading_underscore = 0;
139 gfc_option.flag_dump_core = 0;
140 gfc_option.flag_external_blas = 0;
141 gfc_option.blas_matmul_limit = 30;
142 gfc_option.flag_cray_pointer = 0;
143 gfc_option.flag_d_lines = -1;
144 gfc_option.gfc_flag_openmp = 0;
145 gfc_option.flag_sign_zero = 1;
146 gfc_option.flag_recursive = 0;
147 gfc_option.flag_init_integer = GFC_INIT_INTEGER_OFF;
148 gfc_option.flag_init_integer_value = 0;
149 gfc_option.flag_init_real = GFC_INIT_REAL_OFF;
150 gfc_option.flag_init_logical = GFC_INIT_LOGICAL_OFF;
151 gfc_option.flag_init_character = GFC_INIT_CHARACTER_OFF;
152 gfc_option.flag_init_character_value = (char)0;
153 gfc_option.flag_align_commons = 1;
154 gfc_option.flag_protect_parens = 1;
155 gfc_option.flag_realloc_lhs = -1;
156 gfc_option.flag_aggressive_function_elimination = 0;
157 gfc_option.flag_frontend_optimize = -1;
159 gfc_option.fpe = 0;
160 gfc_option.rtcheck = 0;
161 gfc_option.coarray = GFC_FCOARRAY_NONE;
163 set_default_std_flags ();
165 /* Initialize cpp-related options. */
166 gfc_cpp_init_options (decoded_options_count, decoded_options);
170 /* Determine the source form from the filename extension. We assume
171 case insensitivity. */
173 static gfc_source_form
174 form_from_filename (const char *filename)
176 static const struct
178 const char *extension;
179 gfc_source_form form;
181 exttype[] =
184 ".f90", FORM_FREE}
187 ".f95", FORM_FREE}
190 ".f03", FORM_FREE}
193 ".f08", FORM_FREE}
196 ".f", FORM_FIXED}
199 ".for", FORM_FIXED}
202 ".ftn", FORM_FIXED}
205 "", FORM_UNKNOWN}
206 }; /* sentinel value */
208 gfc_source_form f_form;
209 const char *fileext;
210 int i;
212 /* Find end of file name. Note, filename is either a NULL pointer or
213 a NUL terminated string. */
214 i = 0;
215 while (filename[i] != '\0')
216 i++;
218 /* Find last period. */
219 while (i >= 0 && (filename[i] != '.'))
220 i--;
222 /* Did we see a file extension? */
223 if (i < 0)
224 return FORM_UNKNOWN; /* Nope */
226 /* Get file extension and compare it to others. */
227 fileext = &(filename[i]);
229 i = -1;
230 f_form = FORM_UNKNOWN;
233 i++;
234 if (strcasecmp (fileext, exttype[i].extension) == 0)
236 f_form = exttype[i].form;
237 break;
240 while (exttype[i].form != FORM_UNKNOWN);
242 return f_form;
246 /* Finalize commandline options. */
248 bool
249 gfc_post_options (const char **pfilename)
251 const char *filename = *pfilename, *canon_source_file = NULL;
252 char *source_path;
253 int i;
255 /* Excess precision other than "fast" requires front-end
256 support. */
257 if (flag_excess_precision_cmdline == EXCESS_PRECISION_STANDARD
258 && TARGET_FLT_EVAL_METHOD_NON_DEFAULT)
259 sorry ("-fexcess-precision=standard for Fortran");
260 flag_excess_precision_cmdline = EXCESS_PRECISION_FAST;
262 /* Whole program needs whole file mode. */
263 if (flag_whole_program)
264 gfc_option.flag_whole_file = 1;
266 /* Enable whole-file mode if LTO is in effect. */
267 if (flag_lto)
268 gfc_option.flag_whole_file = 1;
270 /* Fortran allows associative math - but we cannot reassociate if
271 we want traps or signed zeros. Cf. also flag_protect_parens. */
272 if (flag_associative_math == -1)
273 flag_associative_math = (!flag_trapping_math && !flag_signed_zeros);
275 /* By default, disable (re)allocation during assignment for -std=f95,
276 and enable it for F2003/F2008/GNU/Legacy. */
277 if (gfc_option.flag_realloc_lhs == -1)
279 if (gfc_option.allow_std & GFC_STD_F2003)
280 gfc_option.flag_realloc_lhs = 1;
281 else
282 gfc_option.flag_realloc_lhs = 0;
285 /* -fbounds-check is equivalent to -fcheck=bounds */
286 if (flag_bounds_check)
287 gfc_option.rtcheck |= GFC_RTCHECK_BOUNDS;
289 if (flag_compare_debug)
290 gfc_option.dump_fortran_original = 0;
292 /* Make -fmax-errors visible to gfortran's diagnostic machinery. */
293 if (global_options_set.x_flag_max_errors)
294 gfc_option.max_errors = flag_max_errors;
296 /* Verify the input file name. */
297 if (!filename || strcmp (filename, "-") == 0)
299 filename = "";
302 if (gfc_option.flag_preprocessed)
304 /* For preprocessed files, if the first tokens are of the form # NUM.
305 handle the directives so we know the original file name. */
306 gfc_source_file = gfc_read_orig_filename (filename, &canon_source_file);
307 if (gfc_source_file == NULL)
308 gfc_source_file = filename;
309 else
310 *pfilename = gfc_source_file;
312 else
313 gfc_source_file = filename;
315 if (canon_source_file == NULL)
316 canon_source_file = gfc_source_file;
318 /* Adds the path where the source file is to the list of include files. */
320 i = strlen (canon_source_file);
321 while (i > 0 && !IS_DIR_SEPARATOR (canon_source_file[i]))
322 i--;
324 if (i != 0)
326 source_path = (char *) alloca (i + 1);
327 memcpy (source_path, canon_source_file, i);
328 source_path[i] = 0;
329 gfc_add_include_path (source_path, true, true);
331 else
332 gfc_add_include_path (".", true, true);
334 if (canon_source_file != gfc_source_file)
335 free (CONST_CAST (char *, canon_source_file));
337 /* Decide which form the file will be read in as. */
339 if (gfc_option.source_form != FORM_UNKNOWN)
340 gfc_current_form = gfc_option.source_form;
341 else
343 gfc_current_form = form_from_filename (filename);
345 if (gfc_current_form == FORM_UNKNOWN)
347 gfc_current_form = FORM_FREE;
348 gfc_warning_now ("Reading file '%s' as free form",
349 (filename[0] == '\0') ? "<stdin>" : filename);
353 /* If the user specified -fd-lines-as-{code|comments} verify that we're
354 in fixed form. */
355 if (gfc_current_form == FORM_FREE)
357 if (gfc_option.flag_d_lines == 0)
358 gfc_warning_now ("'-fd-lines-as-comments' has no effect "
359 "in free form");
360 else if (gfc_option.flag_d_lines == 1)
361 gfc_warning_now ("'-fd-lines-as-code' has no effect in free form");
364 /* If -pedantic, warn about the use of GNU extensions. */
365 if (pedantic && (gfc_option.allow_std & GFC_STD_GNU) != 0)
366 gfc_option.warn_std |= GFC_STD_GNU;
367 /* -std=legacy -pedantic is effectively -std=gnu. */
368 if (pedantic && (gfc_option.allow_std & GFC_STD_LEGACY) != 0)
369 gfc_option.warn_std |= GFC_STD_F95_OBS | GFC_STD_F95_DEL | GFC_STD_LEGACY;
371 /* If the user didn't explicitly specify -f(no)-second-underscore we
372 use it if we're trying to be compatible with f2c, and not
373 otherwise. */
374 if (gfc_option.flag_second_underscore == -1)
375 gfc_option.flag_second_underscore = gfc_option.flag_f2c;
377 if (!gfc_option.flag_automatic && gfc_option.flag_max_stack_var_size != -2
378 && gfc_option.flag_max_stack_var_size != 0)
379 gfc_warning_now ("Flag -fno-automatic overwrites -fmax-stack-var-size=%d",
380 gfc_option.flag_max_stack_var_size);
381 else if (!gfc_option.flag_automatic && gfc_option.flag_recursive)
382 gfc_warning_now ("Flag -fno-automatic overwrites -frecursive");
383 else if (!gfc_option.flag_automatic && gfc_option.gfc_flag_openmp)
384 gfc_warning_now ("Flag -fno-automatic overwrites -frecursive implied by "
385 "-fopenmp");
386 else if (gfc_option.flag_max_stack_var_size != -2
387 && gfc_option.flag_recursive)
388 gfc_warning_now ("Flag -frecursive overwrites -fmax-stack-var-size=%d",
389 gfc_option.flag_max_stack_var_size);
390 else if (gfc_option.flag_max_stack_var_size != -2
391 && gfc_option.gfc_flag_openmp)
392 gfc_warning_now ("Flag -fmax-stack-var-size=%d overwrites -frecursive "
393 "implied by -fopenmp",
394 gfc_option.flag_max_stack_var_size);
396 /* Implement -frecursive as -fmax-stack-var-size=-1. */
397 if (gfc_option.flag_recursive)
398 gfc_option.flag_max_stack_var_size = -1;
400 /* Implied -frecursive; implemented as -fmax-stack-var-size=-1. */
401 if (gfc_option.flag_max_stack_var_size == -2 && gfc_option.gfc_flag_openmp
402 && gfc_option.flag_automatic)
404 gfc_option.flag_recursive = 1;
405 gfc_option.flag_max_stack_var_size = -1;
408 /* Set default. */
409 if (gfc_option.flag_max_stack_var_size == -2)
410 gfc_option.flag_max_stack_var_size = 32768;
412 /* Implement -fno-automatic as -fmax-stack-var-size=0. */
413 if (!gfc_option.flag_automatic)
414 gfc_option.flag_max_stack_var_size = 0;
416 if (pedantic)
418 gfc_option.warn_ampersand = 1;
419 gfc_option.warn_tabs = 0;
422 if (pedantic && gfc_option.flag_whole_file)
423 gfc_option.flag_whole_file = 2;
425 /* Optimization implies front end optimization, unless the user
426 specified it directly. */
428 if (gfc_option.flag_frontend_optimize == -1)
429 gfc_option.flag_frontend_optimize = optimize;
431 gfc_cpp_post_options ();
433 /* FIXME: return gfc_cpp_preprocess_only ();
435 The return value of this function indicates whether the
436 backend needs to be initialized. On -E, we don't need
437 the backend. However, if we return 'true' here, an
438 ICE occurs. Initializing the backend doesn't hurt much,
439 hence, for now we can live with it as is. */
440 return false;
444 /* Set the options for -Wall. */
446 static void
447 set_Wall (int setting)
449 gfc_option.warn_aliasing = setting;
450 gfc_option.warn_ampersand = setting;
451 gfc_option.gfc_warn_conversion = setting;
452 gfc_option.warn_line_truncation = setting;
453 gfc_option.warn_surprising = setting;
454 gfc_option.warn_tabs = !setting;
455 gfc_option.warn_underflow = setting;
456 gfc_option.warn_intrinsic_shadow = setting;
457 gfc_option.warn_intrinsics_std = setting;
458 gfc_option.warn_character_truncation = setting;
459 gfc_option.warn_real_q_constant = setting;
460 gfc_option.warn_unused_dummy_argument = setting;
462 warn_unused = setting;
463 warn_return_type = setting;
464 warn_switch = setting;
465 warn_uninitialized = setting;
466 warn_maybe_uninitialized = setting;
470 static void
471 gfc_handle_module_path_options (const char *arg)
474 if (gfc_option.module_dir != NULL)
475 gfc_fatal_error ("gfortran: Only one -J option allowed");
477 gfc_option.module_dir = XCNEWVEC (char, strlen (arg) + 2);
478 strcpy (gfc_option.module_dir, arg);
480 gfc_add_include_path (gfc_option.module_dir, true, false);
482 strcat (gfc_option.module_dir, "/");
486 static void
487 gfc_handle_fpe_trap_option (const char *arg)
489 int result, pos = 0, n;
490 static const char * const exception[] = { "invalid", "denormal", "zero",
491 "overflow", "underflow",
492 "precision", NULL };
493 static const int opt_exception[] = { GFC_FPE_INVALID, GFC_FPE_DENORMAL,
494 GFC_FPE_ZERO, GFC_FPE_OVERFLOW,
495 GFC_FPE_UNDERFLOW, GFC_FPE_PRECISION,
496 0 };
498 while (*arg)
500 while (*arg == ',')
501 arg++;
503 while (arg[pos] && arg[pos] != ',')
504 pos++;
506 result = 0;
507 for (n = 0; exception[n] != NULL; n++)
509 if (exception[n] && strncmp (exception[n], arg, pos) == 0)
511 gfc_option.fpe |= opt_exception[n];
512 arg += pos;
513 pos = 0;
514 result = 1;
515 break;
518 if (!result)
519 gfc_fatal_error ("Argument to -ffpe-trap is not valid: %s", arg);
524 static void
525 gfc_handle_coarray_option (const char *arg)
527 if (strcmp (arg, "none") == 0)
528 gfc_option.coarray = GFC_FCOARRAY_NONE;
529 else if (strcmp (arg, "single") == 0)
530 gfc_option.coarray = GFC_FCOARRAY_SINGLE;
531 else if (strcmp (arg, "lib") == 0)
532 gfc_option.coarray = GFC_FCOARRAY_LIB;
533 else
534 gfc_fatal_error ("Argument to -fcoarray is not valid: %s", arg);
538 static void
539 gfc_handle_runtime_check_option (const char *arg)
541 int result, pos = 0, n;
542 static const char * const optname[] = { "all", "bounds", "array-temps",
543 "recursion", "do", "pointer",
544 "mem", NULL };
545 static const int optmask[] = { GFC_RTCHECK_ALL, GFC_RTCHECK_BOUNDS,
546 GFC_RTCHECK_ARRAY_TEMPS,
547 GFC_RTCHECK_RECURSION, GFC_RTCHECK_DO,
548 GFC_RTCHECK_POINTER, GFC_RTCHECK_MEM,
549 0 };
551 while (*arg)
553 while (*arg == ',')
554 arg++;
556 while (arg[pos] && arg[pos] != ',')
557 pos++;
559 result = 0;
560 for (n = 0; optname[n] != NULL; n++)
562 if (optname[n] && strncmp (optname[n], arg, pos) == 0)
564 gfc_option.rtcheck |= optmask[n];
565 arg += pos;
566 pos = 0;
567 result = 1;
568 break;
571 if (!result)
572 gfc_fatal_error ("Argument to -fcheck is not valid: %s", arg);
577 /* Handle command-line options. Returns 0 if unrecognized, 1 if
578 recognized and handled. */
580 bool
581 gfc_handle_option (size_t scode, const char *arg, int value,
582 int kind ATTRIBUTE_UNUSED, location_t loc ATTRIBUTE_UNUSED,
583 const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED)
585 bool result = true;
586 enum opt_code code = (enum opt_code) scode;
588 if (gfc_cpp_handle_option (scode, arg, value) == 1)
589 return true;
591 switch (code)
593 default:
594 result = false;
595 break;
597 case OPT_Wall:
598 set_Wall (value);
599 break;
601 case OPT_Waliasing:
602 gfc_option.warn_aliasing = value;
603 break;
605 case OPT_Wampersand:
606 gfc_option.warn_ampersand = value;
607 break;
609 case OPT_Warray_temporaries:
610 gfc_option.warn_array_temp = value;
611 break;
613 case OPT_Wcharacter_truncation:
614 gfc_option.warn_character_truncation = value;
615 break;
617 case OPT_Wconversion:
618 gfc_option.gfc_warn_conversion = value;
619 break;
621 case OPT_Wconversion_extra:
622 gfc_option.warn_conversion_extra = value;
623 break;
625 case OPT_Wfunction_elimination:
626 gfc_option.warn_function_elimination = value;
627 break;
629 case OPT_Wimplicit_interface:
630 gfc_option.warn_implicit_interface = value;
631 break;
633 case OPT_Wimplicit_procedure:
634 gfc_option.warn_implicit_procedure = value;
635 break;
637 case OPT_Wline_truncation:
638 gfc_option.warn_line_truncation = value;
639 break;
641 case OPT_Wreturn_type:
642 warn_return_type = value;
643 break;
645 case OPT_Wsurprising:
646 gfc_option.warn_surprising = value;
647 break;
649 case OPT_Wtabs:
650 gfc_option.warn_tabs = value;
651 break;
653 case OPT_Wunderflow:
654 gfc_option.warn_underflow = value;
655 break;
657 case OPT_Wintrinsic_shadow:
658 gfc_option.warn_intrinsic_shadow = value;
659 break;
661 case OPT_Walign_commons:
662 gfc_option.warn_align_commons = value;
663 break;
665 case OPT_Wreal_q_constant:
666 gfc_option.warn_real_q_constant = value;
667 break;
669 case OPT_Wunused_dummy_argument:
670 gfc_option.warn_unused_dummy_argument = value;
671 break;
673 case OPT_fall_intrinsics:
674 gfc_option.flag_all_intrinsics = 1;
675 break;
677 case OPT_fautomatic:
678 gfc_option.flag_automatic = value;
679 break;
681 case OPT_fallow_leading_underscore:
682 gfc_option.flag_allow_leading_underscore = value;
683 break;
685 case OPT_fbackslash:
686 gfc_option.flag_backslash = value;
687 break;
689 case OPT_fbacktrace:
690 gfc_option.flag_backtrace = value;
691 break;
693 case OPT_fcheck_array_temporaries:
694 gfc_option.rtcheck |= GFC_RTCHECK_ARRAY_TEMPS;
695 break;
697 case OPT_fdump_core:
698 gfc_option.flag_dump_core = value;
699 break;
701 case OPT_fcray_pointer:
702 gfc_option.flag_cray_pointer = value;
703 break;
705 case OPT_ff2c:
706 gfc_option.flag_f2c = value;
707 break;
709 case OPT_fdollar_ok:
710 gfc_option.flag_dollar_ok = value;
711 break;
713 case OPT_fexternal_blas:
714 gfc_option.flag_external_blas = value;
715 break;
717 case OPT_fblas_matmul_limit_:
718 gfc_option.blas_matmul_limit = value;
719 break;
721 case OPT_fd_lines_as_code:
722 gfc_option.flag_d_lines = 1;
723 break;
725 case OPT_fd_lines_as_comments:
726 gfc_option.flag_d_lines = 0;
727 break;
729 case OPT_fdump_fortran_original:
730 case OPT_fdump_parse_tree:
731 gfc_option.dump_fortran_original = value;
732 break;
734 case OPT_fdump_fortran_optimized:
735 gfc_option.dump_fortran_optimized = value;
736 break;
738 case OPT_ffixed_form:
739 gfc_option.source_form = FORM_FIXED;
740 break;
742 case OPT_ffixed_line_length_none:
743 gfc_option.fixed_line_length = 0;
744 break;
746 case OPT_ffixed_line_length_:
747 if (value != 0 && value < 7)
748 gfc_fatal_error ("Fixed line length must be at least seven.");
749 gfc_option.fixed_line_length = value;
750 break;
752 case OPT_ffree_form:
753 gfc_option.source_form = FORM_FREE;
754 break;
756 case OPT_fopenmp:
757 gfc_option.gfc_flag_openmp = value;
758 break;
760 case OPT_ffree_line_length_none:
761 gfc_option.free_line_length = 0;
762 break;
764 case OPT_ffree_line_length_:
765 if (value != 0 && value < 4)
766 gfc_fatal_error ("Free line length must be at least three.");
767 gfc_option.free_line_length = value;
768 break;
770 case OPT_funderscoring:
771 gfc_option.flag_underscoring = value;
772 break;
774 case OPT_fwhole_file:
775 gfc_option.flag_whole_file = value;
776 break;
778 case OPT_fsecond_underscore:
779 gfc_option.flag_second_underscore = value;
780 break;
782 case OPT_static_libgfortran:
783 #ifndef HAVE_LD_STATIC_DYNAMIC
784 gfc_fatal_error ("-static-libgfortran is not supported in this "
785 "configuration");
786 #endif
787 break;
789 case OPT_fimplicit_none:
790 gfc_option.flag_implicit_none = value;
791 break;
793 case OPT_fintrinsic_modules_path:
794 gfc_add_include_path (arg, false, false);
795 gfc_add_intrinsic_modules_path (arg);
796 break;
798 case OPT_fmax_array_constructor_:
799 gfc_option.flag_max_array_constructor = value > 65535 ? value : 65535;
800 break;
802 case OPT_fmax_stack_var_size_:
803 gfc_option.flag_max_stack_var_size = value;
804 break;
806 case OPT_fstack_arrays:
807 gfc_option.flag_stack_arrays = value;
808 break;
810 case OPT_fmodule_private:
811 gfc_option.flag_module_private = value;
812 break;
814 case OPT_frange_check:
815 gfc_option.flag_range_check = value;
816 break;
818 case OPT_fpack_derived:
819 gfc_option.flag_pack_derived = value;
820 break;
822 case OPT_frepack_arrays:
823 gfc_option.flag_repack_arrays = value;
824 break;
826 case OPT_fpreprocessed:
827 gfc_option.flag_preprocessed = value;
828 break;
830 case OPT_fmax_identifier_length_:
831 if (value > GFC_MAX_SYMBOL_LEN)
832 gfc_fatal_error ("Maximum supported identifier length is %d",
833 GFC_MAX_SYMBOL_LEN);
834 gfc_option.max_identifier_length = value;
835 break;
837 case OPT_fdefault_integer_8:
838 gfc_option.flag_default_integer = value;
839 break;
841 case OPT_fdefault_real_8:
842 gfc_option.flag_default_real = value;
843 break;
845 case OPT_fdefault_double_8:
846 gfc_option.flag_default_double = value;
847 break;
849 case OPT_finit_local_zero:
850 gfc_option.flag_init_integer = GFC_INIT_INTEGER_ON;
851 gfc_option.flag_init_integer_value = 0;
852 gfc_option.flag_init_real = GFC_INIT_REAL_ZERO;
853 gfc_option.flag_init_logical = GFC_INIT_LOGICAL_FALSE;
854 gfc_option.flag_init_character = GFC_INIT_CHARACTER_ON;
855 gfc_option.flag_init_character_value = (char)0;
856 break;
858 case OPT_finit_logical_:
859 if (!strcasecmp (arg, "false"))
860 gfc_option.flag_init_logical = GFC_INIT_LOGICAL_FALSE;
861 else if (!strcasecmp (arg, "true"))
862 gfc_option.flag_init_logical = GFC_INIT_LOGICAL_TRUE;
863 else
864 gfc_fatal_error ("Unrecognized option to -finit-logical: %s",
865 arg);
866 break;
868 case OPT_finit_real_:
869 if (!strcasecmp (arg, "zero"))
870 gfc_option.flag_init_real = GFC_INIT_REAL_ZERO;
871 else if (!strcasecmp (arg, "nan"))
872 gfc_option.flag_init_real = GFC_INIT_REAL_NAN;
873 else if (!strcasecmp (arg, "snan"))
874 gfc_option.flag_init_real = GFC_INIT_REAL_SNAN;
875 else if (!strcasecmp (arg, "inf"))
876 gfc_option.flag_init_real = GFC_INIT_REAL_INF;
877 else if (!strcasecmp (arg, "-inf"))
878 gfc_option.flag_init_real = GFC_INIT_REAL_NEG_INF;
879 else
880 gfc_fatal_error ("Unrecognized option to -finit-real: %s",
881 arg);
882 break;
884 case OPT_finit_integer_:
885 gfc_option.flag_init_integer = GFC_INIT_INTEGER_ON;
886 gfc_option.flag_init_integer_value = atoi (arg);
887 break;
889 case OPT_finit_character_:
890 if (value >= 0 && value <= 127)
892 gfc_option.flag_init_character = GFC_INIT_CHARACTER_ON;
893 gfc_option.flag_init_character_value = (char)value;
895 else
896 gfc_fatal_error ("The value of n in -finit-character=n must be "
897 "between 0 and 127");
898 break;
900 case OPT_I:
901 gfc_add_include_path (arg, true, false);
902 break;
904 case OPT_J:
905 gfc_handle_module_path_options (arg);
906 break;
908 case OPT_fsign_zero:
909 gfc_option.flag_sign_zero = value;
910 break;
912 case OPT_ffpe_trap_:
913 gfc_handle_fpe_trap_option (arg);
914 break;
916 case OPT_std_f95:
917 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F95 | GFC_STD_F77
918 | GFC_STD_F2008_OBS;
919 gfc_option.warn_std = GFC_STD_F95_OBS;
920 gfc_option.max_continue_fixed = 19;
921 gfc_option.max_continue_free = 39;
922 gfc_option.max_identifier_length = 31;
923 gfc_option.warn_ampersand = 1;
924 gfc_option.warn_tabs = 0;
925 break;
927 case OPT_std_f2003:
928 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F77
929 | GFC_STD_F2003 | GFC_STD_F95 | GFC_STD_F2008_OBS;
930 gfc_option.warn_std = GFC_STD_F95_OBS;
931 gfc_option.max_identifier_length = 63;
932 gfc_option.warn_ampersand = 1;
933 gfc_option.warn_tabs = 0;
934 break;
936 case OPT_std_f2008:
937 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F77
938 | GFC_STD_F2003 | GFC_STD_F95 | GFC_STD_F2008 | GFC_STD_F2008_OBS;
939 gfc_option.warn_std = GFC_STD_F95_OBS | GFC_STD_F2008_OBS;
940 gfc_option.max_identifier_length = 63;
941 gfc_option.warn_ampersand = 1;
942 gfc_option.warn_tabs = 0;
943 break;
945 case OPT_std_gnu:
946 set_default_std_flags ();
947 break;
949 case OPT_std_legacy:
950 set_default_std_flags ();
951 gfc_option.warn_std = 0;
952 break;
954 case OPT_Wintrinsics_std:
955 gfc_option.warn_intrinsics_std = value;
956 break;
958 case OPT_fshort_enums:
959 /* Handled in language-independent code. */
960 break;
962 case OPT_fconvert_little_endian:
963 gfc_option.convert = GFC_CONVERT_LITTLE;
964 break;
966 case OPT_fconvert_big_endian:
967 gfc_option.convert = GFC_CONVERT_BIG;
968 break;
970 case OPT_fconvert_native:
971 gfc_option.convert = GFC_CONVERT_NATIVE;
972 break;
974 case OPT_fconvert_swap:
975 gfc_option.convert = GFC_CONVERT_SWAP;
976 break;
978 case OPT_frecord_marker_4:
979 gfc_option.record_marker = 4;
980 break;
982 case OPT_frecord_marker_8:
983 gfc_option.record_marker = 8;
984 break;
986 case OPT_fmax_subrecord_length_:
987 if (value > MAX_SUBRECORD_LENGTH)
988 gfc_fatal_error ("Maximum subrecord length cannot exceed %d",
989 MAX_SUBRECORD_LENGTH);
991 gfc_option.max_subrecord_length = value;
992 break;
994 case OPT_frecursive:
995 gfc_option.flag_recursive = value;
996 break;
998 case OPT_falign_commons:
999 gfc_option.flag_align_commons = value;
1000 break;
1002 case OPT_faggressive_function_elimination:
1003 gfc_option.flag_aggressive_function_elimination = value;
1004 break;
1006 case OPT_ffrontend_optimize:
1007 gfc_option.flag_frontend_optimize = value;
1008 break;
1010 case OPT_fprotect_parens:
1011 gfc_option.flag_protect_parens = value;
1012 break;
1014 case OPT_frealloc_lhs:
1015 gfc_option.flag_realloc_lhs = value;
1016 break;
1018 case OPT_fcheck_:
1019 gfc_handle_runtime_check_option (arg);
1020 break;
1022 case OPT_fcoarray_:
1023 gfc_handle_coarray_option (arg);
1024 break;
1027 return result;
1031 /* Return a string with the options passed to the compiler; used for
1032 Fortran's compiler_options() intrinsic. */
1034 char *
1035 gfc_get_option_string (void)
1037 unsigned j;
1038 size_t len, pos;
1039 char *result;
1041 /* Determine required string length. */
1043 len = 0;
1044 for (j = 1; j < save_decoded_options_count; j++)
1046 switch (save_decoded_options[j].opt_index)
1048 case OPT_o:
1049 case OPT_d:
1050 case OPT_dumpbase:
1051 case OPT_dumpdir:
1052 case OPT_auxbase:
1053 case OPT_quiet:
1054 case OPT_version:
1055 case OPT_fintrinsic_modules_path:
1056 /* Ignore these. */
1057 break;
1058 default:
1059 /* Ignore file names. */
1060 if (save_decoded_options[j].orig_option_with_args_text[0] == '-')
1061 len += 1
1062 + strlen (save_decoded_options[j].orig_option_with_args_text);
1066 result = XCNEWVEC (char, len);
1068 pos = 0;
1069 for (j = 1; j < save_decoded_options_count; j++)
1071 switch (save_decoded_options[j].opt_index)
1073 case OPT_o:
1074 case OPT_d:
1075 case OPT_dumpbase:
1076 case OPT_dumpdir:
1077 case OPT_auxbase:
1078 case OPT_quiet:
1079 case OPT_version:
1080 case OPT_fintrinsic_modules_path:
1081 /* Ignore these. */
1082 continue;
1084 case OPT_cpp_:
1085 /* Use "-cpp" rather than "-cpp=<temporary file>". */
1086 len = 4;
1087 break;
1089 default:
1090 /* Ignore file names. */
1091 if (save_decoded_options[j].orig_option_with_args_text[0] != '-')
1092 continue;
1094 len = strlen (save_decoded_options[j].orig_option_with_args_text);
1097 memcpy (&result[pos], save_decoded_options[j].orig_option_with_args_text, len);
1098 pos += len;
1099 result[pos++] = ' ';
1102 result[--pos] = '\0';
1103 return result;