gfortran.h (gfc_option_t): Remove warn_aliasing,
[official-gcc.git] / gcc / fortran / options.c
blobaf71ded54d0bfc35460ecc59ab5360b74162db6c
1 /* Parse and display command line options.
2 Copyright (C) 2000-2014 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 "tree.h"
25 #include "flags.h"
26 #include "intl.h"
27 #include "opts.h"
28 #include "toplev.h" /* For save_decoded_options. */
29 #include "options.h"
30 #include "params.h"
31 #include "tree-inline.h"
32 #include "gfortran.h"
33 #include "target.h"
34 #include "cpp.h"
35 #include "diagnostic.h" /* For global_dc. */
36 #include "tm.h"
38 gfc_option_t gfc_option;
41 /* Set flags that control warnings and errors for different
42 Fortran standards to their default values. Keep in sync with
43 libgfortran/runtime/compile_options.c (init_compile_options). */
45 static void
46 set_default_std_flags (void)
48 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F95_DEL
49 | GFC_STD_F2003 | GFC_STD_F2008 | GFC_STD_F95 | GFC_STD_F77
50 | GFC_STD_F2008_OBS | GFC_STD_F2008_TS | GFC_STD_GNU | GFC_STD_LEGACY;
51 gfc_option.warn_std = GFC_STD_F95_DEL | GFC_STD_LEGACY;
55 /* Return language mask for Fortran options. */
57 unsigned int
58 gfc_option_lang_mask (void)
60 return CL_Fortran;
63 /* Initialize options structure OPTS. */
65 void
66 gfc_init_options_struct (struct gcc_options *opts)
68 opts->x_flag_errno_math = 0;
69 opts->frontend_set_flag_errno_math = true;
70 opts->x_flag_associative_math = -1;
71 opts->frontend_set_flag_associative_math = true;
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.max_errors = 25;
98 gfc_option.flag_all_intrinsics = 0;
99 gfc_option.flag_default_double = 0;
100 gfc_option.flag_default_integer = 0;
101 gfc_option.flag_default_real = 0;
102 gfc_option.flag_integer4_kind = 0;
103 gfc_option.flag_real4_kind = 0;
104 gfc_option.flag_real8_kind = 0;
105 gfc_option.flag_dollar_ok = 0;
106 gfc_option.flag_underscoring = 1;
107 gfc_option.flag_f2c = 0;
108 gfc_option.flag_second_underscore = -1;
109 gfc_option.flag_implicit_none = 0;
111 /* Default value of flag_max_stack_var_size is set in gfc_post_options. */
112 gfc_option.flag_max_stack_var_size = -2;
113 gfc_option.flag_stack_arrays = -1;
115 gfc_option.flag_range_check = 1;
116 gfc_option.flag_pack_derived = 0;
117 gfc_option.flag_repack_arrays = 0;
118 gfc_option.flag_preprocessed = 0;
119 gfc_option.flag_automatic = 1;
120 gfc_option.flag_backslash = 0;
121 gfc_option.flag_module_private = 0;
122 gfc_option.flag_backtrace = 1;
123 gfc_option.flag_allow_leading_underscore = 0;
124 gfc_option.flag_external_blas = 0;
125 gfc_option.blas_matmul_limit = 30;
126 gfc_option.flag_cray_pointer = 0;
127 gfc_option.flag_d_lines = -1;
128 gfc_option.gfc_flag_openmp = 0;
129 gfc_option.flag_sign_zero = 1;
130 gfc_option.flag_recursive = 0;
131 gfc_option.flag_init_integer = GFC_INIT_INTEGER_OFF;
132 gfc_option.flag_init_integer_value = 0;
133 gfc_option.flag_init_real = GFC_INIT_REAL_OFF;
134 gfc_option.flag_init_logical = GFC_INIT_LOGICAL_OFF;
135 gfc_option.flag_init_character = GFC_INIT_CHARACTER_OFF;
136 gfc_option.flag_init_character_value = (char)0;
137 gfc_option.flag_align_commons = 1;
138 gfc_option.flag_protect_parens = -1;
139 gfc_option.flag_realloc_lhs = -1;
140 gfc_option.flag_aggressive_function_elimination = 0;
141 gfc_option.flag_frontend_optimize = -1;
143 gfc_option.fpe = 0;
144 /* All except GFC_FPE_INEXACT. */
145 gfc_option.fpe_summary = GFC_FPE_INVALID | GFC_FPE_DENORMAL
146 | GFC_FPE_ZERO | GFC_FPE_OVERFLOW
147 | GFC_FPE_UNDERFLOW;
148 gfc_option.rtcheck = 0;
149 gfc_option.coarray = GFC_FCOARRAY_NONE;
151 /* ??? Wmissing-include-dirs is disabled by default in C/C++ but
152 enabled by default in Fortran. Ideally, we should express this
153 in .opt, but that is not supported yet. */
154 if (!global_options_set.x_cpp_warn_missing_include_dirs)
155 global_options.x_cpp_warn_missing_include_dirs = 1;;
157 set_default_std_flags ();
159 /* Initialize cpp-related options. */
160 gfc_cpp_init_options (decoded_options_count, decoded_options);
161 gfc_diagnostics_init ();
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 /* Fortran allows associative math - but we cannot reassociate if
258 we want traps or signed zeros. Cf. also flag_protect_parens. */
259 if (flag_associative_math == -1)
260 flag_associative_math = (!flag_trapping_math && !flag_signed_zeros);
262 if (gfc_option.flag_protect_parens == -1)
263 gfc_option.flag_protect_parens = !optimize_fast;
265 if (gfc_option.flag_stack_arrays == -1)
266 gfc_option.flag_stack_arrays = optimize_fast;
268 /* By default, disable (re)allocation during assignment for -std=f95,
269 and enable it for F2003/F2008/GNU/Legacy. */
270 if (gfc_option.flag_realloc_lhs == -1)
272 if (gfc_option.allow_std & GFC_STD_F2003)
273 gfc_option.flag_realloc_lhs = 1;
274 else
275 gfc_option.flag_realloc_lhs = 0;
278 /* -fbounds-check is equivalent to -fcheck=bounds */
279 if (flag_bounds_check)
280 gfc_option.rtcheck |= GFC_RTCHECK_BOUNDS;
282 if (flag_compare_debug)
283 gfc_option.dump_fortran_original = 0;
285 /* Make -fmax-errors visible to gfortran's diagnostic machinery. */
286 if (global_options_set.x_flag_max_errors)
287 gfc_option.max_errors = flag_max_errors;
289 /* Verify the input file name. */
290 if (!filename || strcmp (filename, "-") == 0)
292 filename = "";
295 if (gfc_option.flag_preprocessed)
297 /* For preprocessed files, if the first tokens are of the form # NUM.
298 handle the directives so we know the original file name. */
299 gfc_source_file = gfc_read_orig_filename (filename, &canon_source_file);
300 if (gfc_source_file == NULL)
301 gfc_source_file = filename;
302 else
303 *pfilename = gfc_source_file;
305 else
306 gfc_source_file = filename;
308 if (canon_source_file == NULL)
309 canon_source_file = gfc_source_file;
311 /* Adds the path where the source file is to the list of include files. */
313 i = strlen (canon_source_file);
314 while (i > 0 && !IS_DIR_SEPARATOR (canon_source_file[i]))
315 i--;
317 if (i != 0)
319 source_path = (char *) alloca (i + 1);
320 memcpy (source_path, canon_source_file, i);
321 source_path[i] = 0;
322 gfc_add_include_path (source_path, true, true, true);
324 else
325 gfc_add_include_path (".", true, true, true);
327 if (canon_source_file != gfc_source_file)
328 free (CONST_CAST (char *, canon_source_file));
330 /* Decide which form the file will be read in as. */
332 if (gfc_option.source_form != FORM_UNKNOWN)
333 gfc_current_form = gfc_option.source_form;
334 else
336 gfc_current_form = form_from_filename (filename);
338 if (gfc_current_form == FORM_UNKNOWN)
340 gfc_current_form = FORM_FREE;
341 gfc_warning_now ("Reading file %qs as free form",
342 (filename[0] == '\0') ? "<stdin>" : filename);
346 /* If the user specified -fd-lines-as-{code|comments} verify that we're
347 in fixed form. */
348 if (gfc_current_form == FORM_FREE)
350 if (gfc_option.flag_d_lines == 0)
351 gfc_warning_now ("%<-fd-lines-as-comments%> has no effect "
352 "in free form");
353 else if (gfc_option.flag_d_lines == 1)
354 gfc_warning_now ("%<-fd-lines-as-code%> has no effect in free form");
357 /* If -pedantic, warn about the use of GNU extensions. */
358 if (pedantic && (gfc_option.allow_std & GFC_STD_GNU) != 0)
359 gfc_option.warn_std |= GFC_STD_GNU;
360 /* -std=legacy -pedantic is effectively -std=gnu. */
361 if (pedantic && (gfc_option.allow_std & GFC_STD_LEGACY) != 0)
362 gfc_option.warn_std |= GFC_STD_F95_OBS | GFC_STD_F95_DEL | GFC_STD_LEGACY;
364 /* If the user didn't explicitly specify -f(no)-second-underscore we
365 use it if we're trying to be compatible with f2c, and not
366 otherwise. */
367 if (gfc_option.flag_second_underscore == -1)
368 gfc_option.flag_second_underscore = gfc_option.flag_f2c;
370 if (!gfc_option.flag_automatic && gfc_option.flag_max_stack_var_size != -2
371 && gfc_option.flag_max_stack_var_size != 0)
372 gfc_warning_now ("Flag %<-fno-automatic%> overwrites %<-fmax-stack-var-size=%d%>",
373 gfc_option.flag_max_stack_var_size);
374 else if (!gfc_option.flag_automatic && gfc_option.flag_recursive)
375 gfc_warning_now ("Flag %<-fno-automatic%> overwrites %<-frecursive%>");
376 else if (!gfc_option.flag_automatic && gfc_option.gfc_flag_openmp)
377 gfc_warning_now ("Flag %<-fno-automatic%> overwrites %<-frecursive%> implied by "
378 "%<-fopenmp%>");
379 else if (gfc_option.flag_max_stack_var_size != -2
380 && gfc_option.flag_recursive)
381 gfc_warning_now ("Flag %<-frecursive%> overwrites %<-fmax-stack-var-size=%d%>",
382 gfc_option.flag_max_stack_var_size);
383 else if (gfc_option.flag_max_stack_var_size != -2
384 && gfc_option.gfc_flag_openmp)
385 gfc_warning_now ("Flag %<-fmax-stack-var-size=%d%> overwrites %<-frecursive%> "
386 "implied by %<-fopenmp%>",
387 gfc_option.flag_max_stack_var_size);
389 /* Implement -frecursive as -fmax-stack-var-size=-1. */
390 if (gfc_option.flag_recursive)
391 gfc_option.flag_max_stack_var_size = -1;
393 /* Implied -frecursive; implemented as -fmax-stack-var-size=-1. */
394 if (gfc_option.flag_max_stack_var_size == -2 && gfc_option.gfc_flag_openmp
395 && gfc_option.flag_automatic)
397 gfc_option.flag_recursive = 1;
398 gfc_option.flag_max_stack_var_size = -1;
401 /* Set default. */
402 if (gfc_option.flag_max_stack_var_size == -2)
403 gfc_option.flag_max_stack_var_size = 32768;
405 /* Implement -fno-automatic as -fmax-stack-var-size=0. */
406 if (!gfc_option.flag_automatic)
407 gfc_option.flag_max_stack_var_size = 0;
409 /* Optimization implies front end optimization, unless the user
410 specified it directly. */
412 if (gfc_option.flag_frontend_optimize == -1)
413 gfc_option.flag_frontend_optimize = optimize;
415 gfc_cpp_post_options ();
417 return gfc_cpp_preprocess_only ();
421 static void
422 gfc_handle_module_path_options (const char *arg)
425 if (gfc_option.module_dir != NULL)
426 gfc_fatal_error ("gfortran: Only one %<-J%> option allowed");
428 gfc_option.module_dir = XCNEWVEC (char, strlen (arg) + 2);
429 strcpy (gfc_option.module_dir, arg);
431 gfc_add_include_path (gfc_option.module_dir, true, false, true);
433 strcat (gfc_option.module_dir, "/");
437 /* Handle options -ffpe-trap= and -ffpe-summary=. */
439 static void
440 gfc_handle_fpe_option (const char *arg, bool trap)
442 int result, pos = 0, n;
443 /* precision is a backwards compatibility alias for inexact. */
444 static const char * const exception[] = { "invalid", "denormal", "zero",
445 "overflow", "underflow",
446 "inexact", "precision", NULL };
447 static const int opt_exception[] = { GFC_FPE_INVALID, GFC_FPE_DENORMAL,
448 GFC_FPE_ZERO, GFC_FPE_OVERFLOW,
449 GFC_FPE_UNDERFLOW, GFC_FPE_INEXACT,
450 GFC_FPE_INEXACT,
451 0 };
453 /* As the default for -ffpe-summary= is nonzero, set it to 0. */
454 if (!trap)
455 gfc_option.fpe_summary = 0;
457 while (*arg)
459 while (*arg == ',')
460 arg++;
462 while (arg[pos] && arg[pos] != ',')
463 pos++;
465 result = 0;
466 if (!trap && strncmp ("none", arg, pos) == 0)
468 gfc_option.fpe_summary = 0;
469 arg += pos;
470 pos = 0;
471 continue;
473 else if (!trap && strncmp ("all", arg, pos) == 0)
475 gfc_option.fpe_summary = GFC_FPE_INVALID | GFC_FPE_DENORMAL
476 | GFC_FPE_ZERO | GFC_FPE_OVERFLOW
477 | GFC_FPE_UNDERFLOW | GFC_FPE_INEXACT;
478 arg += pos;
479 pos = 0;
480 continue;
482 else
483 for (n = 0; exception[n] != NULL; n++)
485 if (exception[n] && strncmp (exception[n], arg, pos) == 0)
487 if (trap)
488 gfc_option.fpe |= opt_exception[n];
489 else
490 gfc_option.fpe_summary |= opt_exception[n];
491 arg += pos;
492 pos = 0;
493 result = 1;
494 break;
497 if (!result && !trap)
498 gfc_fatal_error ("Argument to %<-ffpe-trap%> is not valid: %s", arg);
499 else if (!result)
500 gfc_fatal_error ("Argument to %<-ffpe-summary%> is not valid: %s", arg);
506 static void
507 gfc_handle_coarray_option (const char *arg)
509 if (strcmp (arg, "none") == 0)
510 gfc_option.coarray = GFC_FCOARRAY_NONE;
511 else if (strcmp (arg, "single") == 0)
512 gfc_option.coarray = GFC_FCOARRAY_SINGLE;
513 else if (strcmp (arg, "lib") == 0)
514 gfc_option.coarray = GFC_FCOARRAY_LIB;
515 else
516 gfc_fatal_error ("Argument to %<-fcoarray%> is not valid: %s", arg);
520 static void
521 gfc_handle_runtime_check_option (const char *arg)
523 int result, pos = 0, n;
524 static const char * const optname[] = { "all", "bounds", "array-temps",
525 "recursion", "do", "pointer",
526 "mem", NULL };
527 static const int optmask[] = { GFC_RTCHECK_ALL, GFC_RTCHECK_BOUNDS,
528 GFC_RTCHECK_ARRAY_TEMPS,
529 GFC_RTCHECK_RECURSION, GFC_RTCHECK_DO,
530 GFC_RTCHECK_POINTER, GFC_RTCHECK_MEM,
531 0 };
533 while (*arg)
535 while (*arg == ',')
536 arg++;
538 while (arg[pos] && arg[pos] != ',')
539 pos++;
541 result = 0;
542 for (n = 0; optname[n] != NULL; n++)
544 if (optname[n] && strncmp (optname[n], arg, pos) == 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_fall_intrinsics:
582 gfc_option.flag_all_intrinsics = 1;
583 break;
585 case OPT_fautomatic:
586 gfc_option.flag_automatic = value;
587 break;
589 case OPT_fallow_leading_underscore:
590 gfc_option.flag_allow_leading_underscore = value;
591 break;
593 case OPT_fbackslash:
594 gfc_option.flag_backslash = value;
595 break;
597 case OPT_fbacktrace:
598 gfc_option.flag_backtrace = value;
599 break;
601 case OPT_fcheck_array_temporaries:
602 gfc_option.rtcheck |= GFC_RTCHECK_ARRAY_TEMPS;
603 break;
605 case OPT_fcray_pointer:
606 gfc_option.flag_cray_pointer = value;
607 break;
609 case OPT_ff2c:
610 gfc_option.flag_f2c = value;
611 break;
613 case OPT_fdollar_ok:
614 gfc_option.flag_dollar_ok = value;
615 break;
617 case OPT_fexternal_blas:
618 gfc_option.flag_external_blas = value;
619 break;
621 case OPT_fblas_matmul_limit_:
622 gfc_option.blas_matmul_limit = value;
623 break;
625 case OPT_fd_lines_as_code:
626 gfc_option.flag_d_lines = 1;
627 break;
629 case OPT_fd_lines_as_comments:
630 gfc_option.flag_d_lines = 0;
631 break;
633 case OPT_fdump_fortran_original:
634 case OPT_fdump_parse_tree:
635 gfc_option.dump_fortran_original = value;
636 break;
638 case OPT_fdump_fortran_optimized:
639 gfc_option.dump_fortran_optimized = value;
640 break;
642 case OPT_ffixed_form:
643 gfc_option.source_form = FORM_FIXED;
644 break;
646 case OPT_ffixed_line_length_none:
647 gfc_option.fixed_line_length = 0;
648 break;
650 case OPT_ffixed_line_length_:
651 if (value != 0 && value < 7)
652 gfc_fatal_error ("Fixed line length must be at least seven");
653 gfc_option.fixed_line_length = value;
654 break;
656 case OPT_ffree_form:
657 gfc_option.source_form = FORM_FREE;
658 break;
660 case OPT_fopenmp:
661 gfc_option.gfc_flag_openmp = value;
662 break;
664 case OPT_fopenmp_simd:
665 gfc_option.gfc_flag_openmp_simd = value;
666 break;
668 case OPT_ffree_line_length_none:
669 gfc_option.free_line_length = 0;
670 break;
672 case OPT_ffree_line_length_:
673 if (value != 0 && value < 4)
674 gfc_fatal_error ("Free line length must be at least three");
675 gfc_option.free_line_length = value;
676 break;
678 case OPT_funderscoring:
679 gfc_option.flag_underscoring = value;
680 break;
682 case OPT_fsecond_underscore:
683 gfc_option.flag_second_underscore = value;
684 break;
686 case OPT_static_libgfortran:
687 #ifndef HAVE_LD_STATIC_DYNAMIC
688 gfc_fatal_error ("%<-static-libgfortran%> is not supported in this "
689 "configuration");
690 #endif
691 break;
693 case OPT_fimplicit_none:
694 gfc_option.flag_implicit_none = value;
695 break;
697 case OPT_fintrinsic_modules_path:
698 case OPT_fintrinsic_modules_path_:
700 /* This is needed because omp_lib.h is in a directory together
701 with intrinsic modules. Do no warn because during testing
702 without an installed compiler, we would get lots of bogus
703 warnings for a missing include directory. */
704 gfc_add_include_path (arg, false, false, false);
706 gfc_add_intrinsic_modules_path (arg);
707 break;
709 case OPT_fmax_array_constructor_:
710 gfc_option.flag_max_array_constructor = value > 65535 ? value : 65535;
711 break;
713 case OPT_fmax_stack_var_size_:
714 gfc_option.flag_max_stack_var_size = value;
715 break;
717 case OPT_fstack_arrays:
718 gfc_option.flag_stack_arrays = value;
719 break;
721 case OPT_fmodule_private:
722 gfc_option.flag_module_private = value;
723 break;
725 case OPT_frange_check:
726 gfc_option.flag_range_check = value;
727 break;
729 case OPT_fpack_derived:
730 gfc_option.flag_pack_derived = value;
731 break;
733 case OPT_frepack_arrays:
734 gfc_option.flag_repack_arrays = value;
735 break;
737 case OPT_fpreprocessed:
738 gfc_option.flag_preprocessed = value;
739 break;
741 case OPT_fmax_identifier_length_:
742 if (value > GFC_MAX_SYMBOL_LEN)
743 gfc_fatal_error ("Maximum supported identifier length is %d",
744 GFC_MAX_SYMBOL_LEN);
745 gfc_option.max_identifier_length = value;
746 break;
748 case OPT_fdefault_integer_8:
749 gfc_option.flag_default_integer = value;
750 break;
752 case OPT_fdefault_real_8:
753 gfc_option.flag_default_real = value;
754 break;
756 case OPT_fdefault_double_8:
757 gfc_option.flag_default_double = value;
758 break;
760 case OPT_finteger_4_integer_8:
761 gfc_option.flag_integer4_kind = 8;
762 break;
764 case OPT_freal_4_real_8:
765 gfc_option.flag_real4_kind = 8;
766 break;
768 case OPT_freal_4_real_10:
769 gfc_option.flag_real4_kind = 10;
770 break;
772 case OPT_freal_4_real_16:
773 gfc_option.flag_real4_kind = 16;
774 break;
776 case OPT_freal_8_real_4:
777 gfc_option.flag_real8_kind = 4;
778 break;
780 case OPT_freal_8_real_10:
781 gfc_option.flag_real8_kind = 10;
782 break;
784 case OPT_freal_8_real_16:
785 gfc_option.flag_real8_kind = 16;
786 break;
788 case OPT_finit_local_zero:
789 gfc_option.flag_init_integer = GFC_INIT_INTEGER_ON;
790 gfc_option.flag_init_integer_value = 0;
791 gfc_option.flag_init_real = GFC_INIT_REAL_ZERO;
792 gfc_option.flag_init_logical = GFC_INIT_LOGICAL_FALSE;
793 gfc_option.flag_init_character = GFC_INIT_CHARACTER_ON;
794 gfc_option.flag_init_character_value = (char)0;
795 break;
797 case OPT_finit_logical_:
798 if (!strcasecmp (arg, "false"))
799 gfc_option.flag_init_logical = GFC_INIT_LOGICAL_FALSE;
800 else if (!strcasecmp (arg, "true"))
801 gfc_option.flag_init_logical = GFC_INIT_LOGICAL_TRUE;
802 else
803 gfc_fatal_error ("Unrecognized option to %<-finit-logical%>: %s",
804 arg);
805 break;
807 case OPT_finit_real_:
808 if (!strcasecmp (arg, "zero"))
809 gfc_option.flag_init_real = GFC_INIT_REAL_ZERO;
810 else if (!strcasecmp (arg, "nan"))
811 gfc_option.flag_init_real = GFC_INIT_REAL_NAN;
812 else if (!strcasecmp (arg, "snan"))
813 gfc_option.flag_init_real = GFC_INIT_REAL_SNAN;
814 else if (!strcasecmp (arg, "inf"))
815 gfc_option.flag_init_real = GFC_INIT_REAL_INF;
816 else if (!strcasecmp (arg, "-inf"))
817 gfc_option.flag_init_real = GFC_INIT_REAL_NEG_INF;
818 else
819 gfc_fatal_error ("Unrecognized option to %<-finit-real%>: %s",
820 arg);
821 break;
823 case OPT_finit_integer_:
824 gfc_option.flag_init_integer = GFC_INIT_INTEGER_ON;
825 gfc_option.flag_init_integer_value = atoi (arg);
826 break;
828 case OPT_finit_character_:
829 if (value >= 0 && value <= 127)
831 gfc_option.flag_init_character = GFC_INIT_CHARACTER_ON;
832 gfc_option.flag_init_character_value = (char)value;
834 else
835 gfc_fatal_error ("The value of n in %<-finit-character=n%> must be "
836 "between 0 and 127");
837 break;
839 case OPT_I:
840 gfc_add_include_path (arg, true, false, true);
841 break;
843 case OPT_J:
844 gfc_handle_module_path_options (arg);
845 break;
847 case OPT_fsign_zero:
848 gfc_option.flag_sign_zero = value;
849 break;
851 case OPT_ffpe_trap_:
852 gfc_handle_fpe_option (arg, true);
853 break;
855 case OPT_ffpe_summary_:
856 gfc_handle_fpe_option (arg, false);
857 break;
859 case OPT_std_f95:
860 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F95 | GFC_STD_F77
861 | GFC_STD_F2008_OBS;
862 gfc_option.warn_std = GFC_STD_F95_OBS;
863 gfc_option.max_continue_fixed = 19;
864 gfc_option.max_continue_free = 39;
865 gfc_option.max_identifier_length = 31;
866 warn_ampersand = 1;
867 warn_tabs = 1;
868 break;
870 case OPT_std_f2003:
871 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F77
872 | GFC_STD_F2003 | GFC_STD_F95 | GFC_STD_F2008_OBS;
873 gfc_option.warn_std = GFC_STD_F95_OBS;
874 gfc_option.max_identifier_length = 63;
875 warn_ampersand = 1;
876 warn_tabs = 1;
877 break;
879 case OPT_std_f2008:
880 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F77
881 | GFC_STD_F2003 | GFC_STD_F95 | GFC_STD_F2008 | GFC_STD_F2008_OBS;
882 gfc_option.warn_std = GFC_STD_F95_OBS | GFC_STD_F2008_OBS;
883 gfc_option.max_identifier_length = 63;
884 warn_ampersand = 1;
885 warn_tabs = 1;
886 break;
888 case OPT_std_f2008ts:
889 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F77
890 | GFC_STD_F2003 | GFC_STD_F95 | GFC_STD_F2008 | GFC_STD_F2008_OBS
891 | GFC_STD_F2008_TS;
892 gfc_option.warn_std = GFC_STD_F95_OBS | GFC_STD_F2008_OBS;
893 gfc_option.max_identifier_length = 63;
894 warn_ampersand = 1;
895 warn_tabs = 1;
896 break;
898 case OPT_std_gnu:
899 set_default_std_flags ();
900 break;
902 case OPT_std_legacy:
903 set_default_std_flags ();
904 gfc_option.warn_std = 0;
905 break;
907 case OPT_fshort_enums:
908 /* Handled in language-independent code. */
909 break;
911 case OPT_fconvert_little_endian:
912 gfc_option.convert = GFC_CONVERT_LITTLE;
913 break;
915 case OPT_fconvert_big_endian:
916 gfc_option.convert = GFC_CONVERT_BIG;
917 break;
919 case OPT_fconvert_native:
920 gfc_option.convert = GFC_CONVERT_NATIVE;
921 break;
923 case OPT_fconvert_swap:
924 gfc_option.convert = GFC_CONVERT_SWAP;
925 break;
927 case OPT_frecord_marker_4:
928 gfc_option.record_marker = 4;
929 break;
931 case OPT_frecord_marker_8:
932 gfc_option.record_marker = 8;
933 break;
935 case OPT_fmax_subrecord_length_:
936 if (value > MAX_SUBRECORD_LENGTH)
937 gfc_fatal_error ("Maximum subrecord length cannot exceed %d",
938 MAX_SUBRECORD_LENGTH);
940 gfc_option.max_subrecord_length = value;
941 break;
943 case OPT_frecursive:
944 gfc_option.flag_recursive = value;
945 break;
947 case OPT_falign_commons:
948 gfc_option.flag_align_commons = value;
949 break;
951 case OPT_faggressive_function_elimination:
952 gfc_option.flag_aggressive_function_elimination = value;
953 break;
955 case OPT_ffrontend_optimize:
956 gfc_option.flag_frontend_optimize = value;
957 break;
959 case OPT_fprotect_parens:
960 gfc_option.flag_protect_parens = value;
961 break;
963 case OPT_frealloc_lhs:
964 gfc_option.flag_realloc_lhs = value;
965 break;
967 case OPT_fcheck_:
968 gfc_handle_runtime_check_option (arg);
969 break;
971 case OPT_fcoarray_:
972 gfc_handle_coarray_option (arg);
973 break;
976 Fortran_handle_option_auto (&global_options, &global_options_set,
977 scode, arg, value,
978 gfc_option_lang_mask (), kind,
979 loc, handlers, global_dc);
980 return result;
984 /* Return a string with the options passed to the compiler; used for
985 Fortran's compiler_options() intrinsic. */
987 char *
988 gfc_get_option_string (void)
990 unsigned j;
991 size_t len, pos;
992 char *result;
994 /* Allocate and return a one-character string with '\0'. */
995 if (!save_decoded_options_count)
996 return XCNEWVEC (char, 1);
998 /* Determine required string length. */
1000 len = 0;
1001 for (j = 1; j < save_decoded_options_count; j++)
1003 switch (save_decoded_options[j].opt_index)
1005 case OPT_o:
1006 case OPT_d:
1007 case OPT_dumpbase:
1008 case OPT_dumpdir:
1009 case OPT_auxbase:
1010 case OPT_quiet:
1011 case OPT_version:
1012 case OPT_fintrinsic_modules_path:
1013 case OPT_fintrinsic_modules_path_:
1014 /* Ignore these. */
1015 break;
1016 default:
1017 /* Ignore file names. */
1018 if (save_decoded_options[j].orig_option_with_args_text[0] == '-')
1019 len += 1
1020 + strlen (save_decoded_options[j].orig_option_with_args_text);
1024 result = XCNEWVEC (char, len);
1026 pos = 0;
1027 for (j = 1; j < save_decoded_options_count; j++)
1029 switch (save_decoded_options[j].opt_index)
1031 case OPT_o:
1032 case OPT_d:
1033 case OPT_dumpbase:
1034 case OPT_dumpdir:
1035 case OPT_auxbase:
1036 case OPT_quiet:
1037 case OPT_version:
1038 case OPT_fintrinsic_modules_path:
1039 case OPT_fintrinsic_modules_path_:
1040 /* Ignore these. */
1041 continue;
1043 case OPT_cpp_:
1044 /* Use "-cpp" rather than "-cpp=<temporary file>". */
1045 len = 4;
1046 break;
1048 default:
1049 /* Ignore file names. */
1050 if (save_decoded_options[j].orig_option_with_args_text[0] != '-')
1051 continue;
1053 len = strlen (save_decoded_options[j].orig_option_with_args_text);
1056 memcpy (&result[pos], save_decoded_options[j].orig_option_with_args_text, len);
1057 pos += len;
1058 result[pos++] = ' ';
1061 result[--pos] = '\0';
1062 return result;