Include <bits/uses_allocator.h> in <stack> and <queue>.
[official-gcc.git] / gcc / fortran / options.c
blob6543fbd1ec6382a36402a3734b29029469658fd6
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.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.warn_c_binding_type = 0;
101 gfc_option.gfc_warn_conversion = 0;
102 gfc_option.warn_conversion_extra = 0;
103 gfc_option.warn_function_elimination = 0;
104 gfc_option.warn_implicit_interface = 0;
105 gfc_option.warn_line_truncation = 0;
106 gfc_option.warn_surprising = 0;
107 gfc_option.warn_tabs = 1;
108 gfc_option.warn_underflow = 1;
109 gfc_option.warn_intrinsic_shadow = 0;
110 gfc_option.warn_use_without_only = 0;
111 gfc_option.warn_intrinsics_std = 0;
112 gfc_option.warn_align_commons = 1;
113 gfc_option.warn_real_q_constant = 0;
114 gfc_option.warn_unused_dummy_argument = 0;
115 gfc_option.warn_zerotrip = 0;
116 gfc_option.warn_realloc_lhs = 0;
117 gfc_option.warn_realloc_lhs_all = 0;
118 gfc_option.warn_compare_reals = 0;
119 gfc_option.warn_target_lifetime = 0;
120 gfc_option.max_errors = 25;
122 gfc_option.flag_all_intrinsics = 0;
123 gfc_option.flag_default_double = 0;
124 gfc_option.flag_default_integer = 0;
125 gfc_option.flag_default_real = 0;
126 gfc_option.flag_integer4_kind = 0;
127 gfc_option.flag_real4_kind = 0;
128 gfc_option.flag_real8_kind = 0;
129 gfc_option.flag_dollar_ok = 0;
130 gfc_option.flag_underscoring = 1;
131 gfc_option.flag_f2c = 0;
132 gfc_option.flag_second_underscore = -1;
133 gfc_option.flag_implicit_none = 0;
135 /* Default value of flag_max_stack_var_size is set in gfc_post_options. */
136 gfc_option.flag_max_stack_var_size = -2;
137 gfc_option.flag_stack_arrays = -1;
139 gfc_option.flag_range_check = 1;
140 gfc_option.flag_pack_derived = 0;
141 gfc_option.flag_repack_arrays = 0;
142 gfc_option.flag_preprocessed = 0;
143 gfc_option.flag_automatic = 1;
144 gfc_option.flag_backslash = 0;
145 gfc_option.flag_module_private = 0;
146 gfc_option.flag_backtrace = 1;
147 gfc_option.flag_allow_leading_underscore = 0;
148 gfc_option.flag_external_blas = 0;
149 gfc_option.blas_matmul_limit = 30;
150 gfc_option.flag_cray_pointer = 0;
151 gfc_option.flag_d_lines = -1;
152 gfc_option.gfc_flag_openmp = 0;
153 gfc_option.flag_sign_zero = 1;
154 gfc_option.flag_recursive = 0;
155 gfc_option.flag_init_integer = GFC_INIT_INTEGER_OFF;
156 gfc_option.flag_init_integer_value = 0;
157 gfc_option.flag_init_real = GFC_INIT_REAL_OFF;
158 gfc_option.flag_init_logical = GFC_INIT_LOGICAL_OFF;
159 gfc_option.flag_init_character = GFC_INIT_CHARACTER_OFF;
160 gfc_option.flag_init_character_value = (char)0;
161 gfc_option.flag_align_commons = 1;
162 gfc_option.flag_protect_parens = -1;
163 gfc_option.flag_realloc_lhs = -1;
164 gfc_option.flag_aggressive_function_elimination = 0;
165 gfc_option.flag_frontend_optimize = -1;
167 gfc_option.fpe = 0;
168 /* All except GFC_FPE_INEXACT. */
169 gfc_option.fpe_summary = GFC_FPE_INVALID | GFC_FPE_DENORMAL
170 | GFC_FPE_ZERO | GFC_FPE_OVERFLOW
171 | GFC_FPE_UNDERFLOW;
172 gfc_option.rtcheck = 0;
173 gfc_option.coarray = GFC_FCOARRAY_NONE;
175 set_default_std_flags ();
177 /* Initialize cpp-related options. */
178 gfc_cpp_init_options (decoded_options_count, decoded_options);
179 gfc_diagnostics_init ();
183 /* Determine the source form from the filename extension. We assume
184 case insensitivity. */
186 static gfc_source_form
187 form_from_filename (const char *filename)
189 static const struct
191 const char *extension;
192 gfc_source_form form;
194 exttype[] =
197 ".f90", FORM_FREE}
200 ".f95", FORM_FREE}
203 ".f03", FORM_FREE}
206 ".f08", FORM_FREE}
209 ".f", FORM_FIXED}
212 ".for", FORM_FIXED}
215 ".ftn", FORM_FIXED}
218 "", FORM_UNKNOWN}
219 }; /* sentinel value */
221 gfc_source_form f_form;
222 const char *fileext;
223 int i;
225 /* Find end of file name. Note, filename is either a NULL pointer or
226 a NUL terminated string. */
227 i = 0;
228 while (filename[i] != '\0')
229 i++;
231 /* Find last period. */
232 while (i >= 0 && (filename[i] != '.'))
233 i--;
235 /* Did we see a file extension? */
236 if (i < 0)
237 return FORM_UNKNOWN; /* Nope */
239 /* Get file extension and compare it to others. */
240 fileext = &(filename[i]);
242 i = -1;
243 f_form = FORM_UNKNOWN;
246 i++;
247 if (strcasecmp (fileext, exttype[i].extension) == 0)
249 f_form = exttype[i].form;
250 break;
253 while (exttype[i].form != FORM_UNKNOWN);
255 return f_form;
259 /* Finalize commandline options. */
261 bool
262 gfc_post_options (const char **pfilename)
264 const char *filename = *pfilename, *canon_source_file = NULL;
265 char *source_path;
266 int i;
268 /* Excess precision other than "fast" requires front-end
269 support. */
270 if (flag_excess_precision_cmdline == EXCESS_PRECISION_STANDARD
271 && TARGET_FLT_EVAL_METHOD_NON_DEFAULT)
272 sorry ("-fexcess-precision=standard for Fortran");
273 flag_excess_precision_cmdline = EXCESS_PRECISION_FAST;
275 /* Fortran allows associative math - but we cannot reassociate if
276 we want traps or signed zeros. Cf. also flag_protect_parens. */
277 if (flag_associative_math == -1)
278 flag_associative_math = (!flag_trapping_math && !flag_signed_zeros);
280 if (gfc_option.flag_protect_parens == -1)
281 gfc_option.flag_protect_parens = !optimize_fast;
283 if (gfc_option.flag_stack_arrays == -1)
284 gfc_option.flag_stack_arrays = optimize_fast;
286 /* By default, disable (re)allocation during assignment for -std=f95,
287 and enable it for F2003/F2008/GNU/Legacy. */
288 if (gfc_option.flag_realloc_lhs == -1)
290 if (gfc_option.allow_std & GFC_STD_F2003)
291 gfc_option.flag_realloc_lhs = 1;
292 else
293 gfc_option.flag_realloc_lhs = 0;
296 /* -fbounds-check is equivalent to -fcheck=bounds */
297 if (flag_bounds_check)
298 gfc_option.rtcheck |= GFC_RTCHECK_BOUNDS;
300 if (flag_compare_debug)
301 gfc_option.dump_fortran_original = 0;
303 /* Make -fmax-errors visible to gfortran's diagnostic machinery. */
304 if (global_options_set.x_flag_max_errors)
305 gfc_option.max_errors = flag_max_errors;
307 /* Verify the input file name. */
308 if (!filename || strcmp (filename, "-") == 0)
310 filename = "";
313 if (gfc_option.flag_preprocessed)
315 /* For preprocessed files, if the first tokens are of the form # NUM.
316 handle the directives so we know the original file name. */
317 gfc_source_file = gfc_read_orig_filename (filename, &canon_source_file);
318 if (gfc_source_file == NULL)
319 gfc_source_file = filename;
320 else
321 *pfilename = gfc_source_file;
323 else
324 gfc_source_file = filename;
326 if (canon_source_file == NULL)
327 canon_source_file = gfc_source_file;
329 /* Adds the path where the source file is to the list of include files. */
331 i = strlen (canon_source_file);
332 while (i > 0 && !IS_DIR_SEPARATOR (canon_source_file[i]))
333 i--;
335 if (i != 0)
337 source_path = (char *) alloca (i + 1);
338 memcpy (source_path, canon_source_file, i);
339 source_path[i] = 0;
340 gfc_add_include_path (source_path, true, true, true);
342 else
343 gfc_add_include_path (".", true, true, true);
345 if (canon_source_file != gfc_source_file)
346 free (CONST_CAST (char *, canon_source_file));
348 /* Decide which form the file will be read in as. */
350 if (gfc_option.source_form != FORM_UNKNOWN)
351 gfc_current_form = gfc_option.source_form;
352 else
354 gfc_current_form = form_from_filename (filename);
356 if (gfc_current_form == FORM_UNKNOWN)
358 gfc_current_form = FORM_FREE;
359 gfc_warning_cmdline ("Reading file %qs as free form",
360 (filename[0] == '\0') ? "<stdin>" : filename);
364 /* If the user specified -fd-lines-as-{code|comments} verify that we're
365 in fixed form. */
366 if (gfc_current_form == FORM_FREE)
368 if (gfc_option.flag_d_lines == 0)
369 gfc_warning_cmdline ("%<-fd-lines-as-comments%> has no effect "
370 "in free form");
371 else if (gfc_option.flag_d_lines == 1)
372 gfc_warning_cmdline ("%<-fd-lines-as-code%> has no effect in free form");
375 /* If -pedantic, warn about the use of GNU extensions. */
376 if (pedantic && (gfc_option.allow_std & GFC_STD_GNU) != 0)
377 gfc_option.warn_std |= GFC_STD_GNU;
378 /* -std=legacy -pedantic is effectively -std=gnu. */
379 if (pedantic && (gfc_option.allow_std & GFC_STD_LEGACY) != 0)
380 gfc_option.warn_std |= GFC_STD_F95_OBS | GFC_STD_F95_DEL | GFC_STD_LEGACY;
382 /* If the user didn't explicitly specify -f(no)-second-underscore we
383 use it if we're trying to be compatible with f2c, and not
384 otherwise. */
385 if (gfc_option.flag_second_underscore == -1)
386 gfc_option.flag_second_underscore = gfc_option.flag_f2c;
388 if (!gfc_option.flag_automatic && gfc_option.flag_max_stack_var_size != -2
389 && gfc_option.flag_max_stack_var_size != 0)
390 gfc_warning_cmdline ("Flag %<-fno-automatic%> overwrites %<-fmax-stack-var-size=%d%>",
391 gfc_option.flag_max_stack_var_size);
392 else if (!gfc_option.flag_automatic && gfc_option.flag_recursive)
393 gfc_warning_cmdline ("Flag %<-fno-automatic%> overwrites %<-frecursive%>");
394 else if (!gfc_option.flag_automatic && gfc_option.gfc_flag_openmp)
395 gfc_warning_cmdline ("Flag %<-fno-automatic%> overwrites %<-frecursive%> implied by "
396 "%<-fopenmp%>");
397 else if (gfc_option.flag_max_stack_var_size != -2
398 && gfc_option.flag_recursive)
399 gfc_warning_cmdline ("Flag %<-frecursive%> overwrites %<-fmax-stack-var-size=%d%>",
400 gfc_option.flag_max_stack_var_size);
401 else if (gfc_option.flag_max_stack_var_size != -2
402 && gfc_option.gfc_flag_openmp)
403 gfc_warning_cmdline ("Flag %<-fmax-stack-var-size=%d%> overwrites %<-frecursive%> "
404 "implied by %<-fopenmp%>",
405 gfc_option.flag_max_stack_var_size);
407 /* Implement -frecursive as -fmax-stack-var-size=-1. */
408 if (gfc_option.flag_recursive)
409 gfc_option.flag_max_stack_var_size = -1;
411 /* Implied -frecursive; implemented as -fmax-stack-var-size=-1. */
412 if (gfc_option.flag_max_stack_var_size == -2 && gfc_option.gfc_flag_openmp
413 && gfc_option.flag_automatic)
415 gfc_option.flag_recursive = 1;
416 gfc_option.flag_max_stack_var_size = -1;
419 /* Set default. */
420 if (gfc_option.flag_max_stack_var_size == -2)
421 gfc_option.flag_max_stack_var_size = 32768;
423 /* Implement -fno-automatic as -fmax-stack-var-size=0. */
424 if (!gfc_option.flag_automatic)
425 gfc_option.flag_max_stack_var_size = 0;
427 if (pedantic)
429 gfc_option.warn_ampersand = 1;
430 gfc_option.warn_tabs = 0;
433 /* Optimization implies front end optimization, unless the user
434 specified it directly. */
436 if (gfc_option.flag_frontend_optimize == -1)
437 gfc_option.flag_frontend_optimize = optimize;
439 if (gfc_option.warn_realloc_lhs_all)
440 gfc_option.warn_realloc_lhs = 1;
442 gfc_cpp_post_options ();
444 return gfc_cpp_preprocess_only ();
448 /* Set the options for -Wall. */
450 static void
451 set_Wall (int setting)
453 gfc_option.warn_aliasing = setting;
454 gfc_option.warn_ampersand = setting;
455 gfc_option.warn_c_binding_type = setting;
456 gfc_option.gfc_warn_conversion = setting;
457 gfc_option.warn_line_truncation = setting;
458 gfc_option.warn_surprising = setting;
459 gfc_option.warn_tabs = !setting;
460 gfc_option.warn_underflow = setting;
461 gfc_option.warn_intrinsic_shadow = setting;
462 gfc_option.warn_intrinsics_std = setting;
463 gfc_option.warn_character_truncation = setting;
464 gfc_option.warn_real_q_constant = setting;
465 gfc_option.warn_unused_dummy_argument = setting;
466 gfc_option.warn_target_lifetime = setting;
467 gfc_option.warn_zerotrip = setting;
469 warn_return_type = setting;
470 warn_uninitialized = setting;
471 warn_maybe_uninitialized = setting;
474 /* Set the options for -Wextra. */
476 static void
477 set_Wextra (int setting)
479 gfc_option.warn_compare_reals = setting;
482 static void
483 gfc_handle_module_path_options (const char *arg)
486 if (gfc_option.module_dir != NULL)
487 gfc_fatal_error ("gfortran: Only one -J option allowed");
489 gfc_option.module_dir = XCNEWVEC (char, strlen (arg) + 2);
490 strcpy (gfc_option.module_dir, arg);
492 gfc_add_include_path (gfc_option.module_dir, true, false, true);
494 strcat (gfc_option.module_dir, "/");
498 /* Handle options -ffpe-trap= and -ffpe-summary=. */
500 static void
501 gfc_handle_fpe_option (const char *arg, bool trap)
503 int result, pos = 0, n;
504 /* precision is a backwards compatibility alias for inexact. */
505 static const char * const exception[] = { "invalid", "denormal", "zero",
506 "overflow", "underflow",
507 "inexact", "precision", NULL };
508 static const int opt_exception[] = { GFC_FPE_INVALID, GFC_FPE_DENORMAL,
509 GFC_FPE_ZERO, GFC_FPE_OVERFLOW,
510 GFC_FPE_UNDERFLOW, GFC_FPE_INEXACT,
511 GFC_FPE_INEXACT,
512 0 };
514 /* As the default for -ffpe-summary= is nonzero, set it to 0. */
515 if (!trap)
516 gfc_option.fpe_summary = 0;
518 while (*arg)
520 while (*arg == ',')
521 arg++;
523 while (arg[pos] && arg[pos] != ',')
524 pos++;
526 result = 0;
527 if (!trap && strncmp ("none", arg, pos) == 0)
529 gfc_option.fpe_summary = 0;
530 arg += pos;
531 pos = 0;
532 continue;
534 else if (!trap && strncmp ("all", arg, pos) == 0)
536 gfc_option.fpe_summary = GFC_FPE_INVALID | GFC_FPE_DENORMAL
537 | GFC_FPE_ZERO | GFC_FPE_OVERFLOW
538 | GFC_FPE_UNDERFLOW | GFC_FPE_INEXACT;
539 arg += pos;
540 pos = 0;
541 continue;
543 else
544 for (n = 0; exception[n] != NULL; n++)
546 if (exception[n] && strncmp (exception[n], arg, pos) == 0)
548 if (trap)
549 gfc_option.fpe |= opt_exception[n];
550 else
551 gfc_option.fpe_summary |= opt_exception[n];
552 arg += pos;
553 pos = 0;
554 result = 1;
555 break;
558 if (!result && !trap)
559 gfc_fatal_error ("Argument to -ffpe-trap is not valid: %s", arg);
560 else if (!result)
561 gfc_fatal_error ("Argument to -ffpe-summary is not valid: %s", arg);
567 static void
568 gfc_handle_coarray_option (const char *arg)
570 if (strcmp (arg, "none") == 0)
571 gfc_option.coarray = GFC_FCOARRAY_NONE;
572 else if (strcmp (arg, "single") == 0)
573 gfc_option.coarray = GFC_FCOARRAY_SINGLE;
574 else if (strcmp (arg, "lib") == 0)
575 gfc_option.coarray = GFC_FCOARRAY_LIB;
576 else
577 gfc_fatal_error ("Argument to -fcoarray is not valid: %s", arg);
581 static void
582 gfc_handle_runtime_check_option (const char *arg)
584 int result, pos = 0, n;
585 static const char * const optname[] = { "all", "bounds", "array-temps",
586 "recursion", "do", "pointer",
587 "mem", NULL };
588 static const int optmask[] = { GFC_RTCHECK_ALL, GFC_RTCHECK_BOUNDS,
589 GFC_RTCHECK_ARRAY_TEMPS,
590 GFC_RTCHECK_RECURSION, GFC_RTCHECK_DO,
591 GFC_RTCHECK_POINTER, GFC_RTCHECK_MEM,
592 0 };
594 while (*arg)
596 while (*arg == ',')
597 arg++;
599 while (arg[pos] && arg[pos] != ',')
600 pos++;
602 result = 0;
603 for (n = 0; optname[n] != NULL; n++)
605 if (optname[n] && strncmp (optname[n], arg, pos) == 0)
607 gfc_option.rtcheck |= optmask[n];
608 arg += pos;
609 pos = 0;
610 result = 1;
611 break;
614 if (!result)
615 gfc_fatal_error ("Argument to -fcheck is not valid: %s", arg);
620 /* Handle command-line options. Returns 0 if unrecognized, 1 if
621 recognized and handled. */
623 bool
624 gfc_handle_option (size_t scode, const char *arg, int value,
625 int kind ATTRIBUTE_UNUSED, location_t loc ATTRIBUTE_UNUSED,
626 const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED)
628 bool result = true;
629 enum opt_code code = (enum opt_code) scode;
631 if (gfc_cpp_handle_option (scode, arg, value) == 1)
632 return true;
634 switch (code)
636 default:
637 result = false;
638 break;
640 case OPT_Wall:
641 handle_generated_option (&global_options, &global_options_set,
642 OPT_Wunused, NULL, value,
643 gfc_option_lang_mask (), kind, loc,
644 handlers, global_dc);
645 set_Wall (value);
646 break;
648 case OPT_Waliasing:
649 gfc_option.warn_aliasing = value;
650 break;
652 case OPT_Wampersand:
653 gfc_option.warn_ampersand = value;
654 break;
656 case OPT_Warray_temporaries:
657 gfc_option.warn_array_temp = value;
658 break;
660 case OPT_Wc_binding_type:
661 gfc_option.warn_c_binding_type = value;
662 break;
664 case OPT_Wcharacter_truncation:
665 gfc_option.warn_character_truncation = value;
666 break;
668 case OPT_Wcompare_reals:
669 gfc_option.warn_compare_reals = value;
670 break;
672 case OPT_Wconversion:
673 gfc_option.gfc_warn_conversion = value;
674 break;
676 case OPT_Wconversion_extra:
677 gfc_option.warn_conversion_extra = value;
678 break;
680 case OPT_Wextra:
681 set_Wextra (value);
682 break;
684 case OPT_Wfunction_elimination:
685 gfc_option.warn_function_elimination = value;
686 break;
688 case OPT_Wimplicit_interface:
689 gfc_option.warn_implicit_interface = value;
690 break;
692 case OPT_Wimplicit_procedure:
693 gfc_option.warn_implicit_procedure = value;
694 break;
696 case OPT_Wline_truncation:
697 gfc_option.warn_line_truncation = value;
698 break;
700 case OPT_Wrealloc_lhs:
701 gfc_option.warn_realloc_lhs = value;
702 break;
704 case OPT_Wrealloc_lhs_all:
705 gfc_option.warn_realloc_lhs_all = value;
706 break;
708 case OPT_Wreturn_type:
709 warn_return_type = value;
710 break;
712 case OPT_Wsurprising:
713 gfc_option.warn_surprising = value;
714 break;
716 case OPT_Wtabs:
717 gfc_option.warn_tabs = value;
718 break;
720 case OPT_Wtarget_lifetime:
721 gfc_option.warn_target_lifetime = value;
722 break;
724 case OPT_Wunderflow:
725 gfc_option.warn_underflow = value;
726 break;
728 case OPT_Wintrinsic_shadow:
729 gfc_option.warn_intrinsic_shadow = value;
730 break;
732 case OPT_Wuse_without_only:
733 gfc_option.warn_use_without_only = value;
734 break;
736 case OPT_Walign_commons:
737 gfc_option.warn_align_commons = value;
738 break;
740 case OPT_Wreal_q_constant:
741 gfc_option.warn_real_q_constant = value;
742 break;
744 case OPT_Wunused_dummy_argument:
745 gfc_option.warn_unused_dummy_argument = value;
746 break;
748 case OPT_Wzerotrip:
749 gfc_option.warn_zerotrip = value;
750 break;
752 case OPT_fall_intrinsics:
753 gfc_option.flag_all_intrinsics = 1;
754 break;
756 case OPT_fautomatic:
757 gfc_option.flag_automatic = value;
758 break;
760 case OPT_fallow_leading_underscore:
761 gfc_option.flag_allow_leading_underscore = value;
762 break;
764 case OPT_fbackslash:
765 gfc_option.flag_backslash = value;
766 break;
768 case OPT_fbacktrace:
769 gfc_option.flag_backtrace = value;
770 break;
772 case OPT_fcheck_array_temporaries:
773 gfc_option.rtcheck |= GFC_RTCHECK_ARRAY_TEMPS;
774 break;
776 case OPT_fcray_pointer:
777 gfc_option.flag_cray_pointer = value;
778 break;
780 case OPT_ff2c:
781 gfc_option.flag_f2c = value;
782 break;
784 case OPT_fdollar_ok:
785 gfc_option.flag_dollar_ok = value;
786 break;
788 case OPT_fexternal_blas:
789 gfc_option.flag_external_blas = value;
790 break;
792 case OPT_fblas_matmul_limit_:
793 gfc_option.blas_matmul_limit = value;
794 break;
796 case OPT_fd_lines_as_code:
797 gfc_option.flag_d_lines = 1;
798 break;
800 case OPT_fd_lines_as_comments:
801 gfc_option.flag_d_lines = 0;
802 break;
804 case OPT_fdump_fortran_original:
805 case OPT_fdump_parse_tree:
806 gfc_option.dump_fortran_original = value;
807 break;
809 case OPT_fdump_fortran_optimized:
810 gfc_option.dump_fortran_optimized = value;
811 break;
813 case OPT_ffixed_form:
814 gfc_option.source_form = FORM_FIXED;
815 break;
817 case OPT_ffixed_line_length_none:
818 gfc_option.fixed_line_length = 0;
819 break;
821 case OPT_ffixed_line_length_:
822 if (value != 0 && value < 7)
823 gfc_fatal_error ("Fixed line length must be at least seven.");
824 gfc_option.fixed_line_length = value;
825 break;
827 case OPT_ffree_form:
828 gfc_option.source_form = FORM_FREE;
829 break;
831 case OPT_fopenmp:
832 gfc_option.gfc_flag_openmp = value;
833 break;
835 case OPT_fopenmp_simd:
836 gfc_option.gfc_flag_openmp_simd = value;
837 break;
839 case OPT_ffree_line_length_none:
840 gfc_option.free_line_length = 0;
841 break;
843 case OPT_ffree_line_length_:
844 if (value != 0 && value < 4)
845 gfc_fatal_error ("Free line length must be at least three.");
846 gfc_option.free_line_length = value;
847 break;
849 case OPT_funderscoring:
850 gfc_option.flag_underscoring = value;
851 break;
853 case OPT_fsecond_underscore:
854 gfc_option.flag_second_underscore = value;
855 break;
857 case OPT_static_libgfortran:
858 #ifndef HAVE_LD_STATIC_DYNAMIC
859 gfc_fatal_error ("-static-libgfortran is not supported in this "
860 "configuration");
861 #endif
862 break;
864 case OPT_fimplicit_none:
865 gfc_option.flag_implicit_none = value;
866 break;
868 case OPT_fintrinsic_modules_path:
869 case OPT_fintrinsic_modules_path_:
871 /* This is needed because omp_lib.h is in a directory together
872 with intrinsic modules. Do no warn because during testing
873 without an installed compiler, we would get lots of bogus
874 warnings for a missing include directory. */
875 gfc_add_include_path (arg, false, false, false);
877 gfc_add_intrinsic_modules_path (arg);
878 break;
880 case OPT_fmax_array_constructor_:
881 gfc_option.flag_max_array_constructor = value > 65535 ? value : 65535;
882 break;
884 case OPT_fmax_stack_var_size_:
885 gfc_option.flag_max_stack_var_size = value;
886 break;
888 case OPT_fstack_arrays:
889 gfc_option.flag_stack_arrays = value;
890 break;
892 case OPT_fmodule_private:
893 gfc_option.flag_module_private = value;
894 break;
896 case OPT_frange_check:
897 gfc_option.flag_range_check = value;
898 break;
900 case OPT_fpack_derived:
901 gfc_option.flag_pack_derived = value;
902 break;
904 case OPT_frepack_arrays:
905 gfc_option.flag_repack_arrays = value;
906 break;
908 case OPT_fpreprocessed:
909 gfc_option.flag_preprocessed = value;
910 break;
912 case OPT_fmax_identifier_length_:
913 if (value > GFC_MAX_SYMBOL_LEN)
914 gfc_fatal_error ("Maximum supported identifier length is %d",
915 GFC_MAX_SYMBOL_LEN);
916 gfc_option.max_identifier_length = value;
917 break;
919 case OPT_fdefault_integer_8:
920 gfc_option.flag_default_integer = value;
921 break;
923 case OPT_fdefault_real_8:
924 gfc_option.flag_default_real = value;
925 break;
927 case OPT_fdefault_double_8:
928 gfc_option.flag_default_double = value;
929 break;
931 case OPT_finteger_4_integer_8:
932 gfc_option.flag_integer4_kind = 8;
933 break;
935 case OPT_freal_4_real_8:
936 gfc_option.flag_real4_kind = 8;
937 break;
939 case OPT_freal_4_real_10:
940 gfc_option.flag_real4_kind = 10;
941 break;
943 case OPT_freal_4_real_16:
944 gfc_option.flag_real4_kind = 16;
945 break;
947 case OPT_freal_8_real_4:
948 gfc_option.flag_real8_kind = 4;
949 break;
951 case OPT_freal_8_real_10:
952 gfc_option.flag_real8_kind = 10;
953 break;
955 case OPT_freal_8_real_16:
956 gfc_option.flag_real8_kind = 16;
957 break;
959 case OPT_finit_local_zero:
960 gfc_option.flag_init_integer = GFC_INIT_INTEGER_ON;
961 gfc_option.flag_init_integer_value = 0;
962 gfc_option.flag_init_real = GFC_INIT_REAL_ZERO;
963 gfc_option.flag_init_logical = GFC_INIT_LOGICAL_FALSE;
964 gfc_option.flag_init_character = GFC_INIT_CHARACTER_ON;
965 gfc_option.flag_init_character_value = (char)0;
966 break;
968 case OPT_finit_logical_:
969 if (!strcasecmp (arg, "false"))
970 gfc_option.flag_init_logical = GFC_INIT_LOGICAL_FALSE;
971 else if (!strcasecmp (arg, "true"))
972 gfc_option.flag_init_logical = GFC_INIT_LOGICAL_TRUE;
973 else
974 gfc_fatal_error ("Unrecognized option to -finit-logical: %s",
975 arg);
976 break;
978 case OPT_finit_real_:
979 if (!strcasecmp (arg, "zero"))
980 gfc_option.flag_init_real = GFC_INIT_REAL_ZERO;
981 else if (!strcasecmp (arg, "nan"))
982 gfc_option.flag_init_real = GFC_INIT_REAL_NAN;
983 else if (!strcasecmp (arg, "snan"))
984 gfc_option.flag_init_real = GFC_INIT_REAL_SNAN;
985 else if (!strcasecmp (arg, "inf"))
986 gfc_option.flag_init_real = GFC_INIT_REAL_INF;
987 else if (!strcasecmp (arg, "-inf"))
988 gfc_option.flag_init_real = GFC_INIT_REAL_NEG_INF;
989 else
990 gfc_fatal_error ("Unrecognized option to -finit-real: %s",
991 arg);
992 break;
994 case OPT_finit_integer_:
995 gfc_option.flag_init_integer = GFC_INIT_INTEGER_ON;
996 gfc_option.flag_init_integer_value = atoi (arg);
997 break;
999 case OPT_finit_character_:
1000 if (value >= 0 && value <= 127)
1002 gfc_option.flag_init_character = GFC_INIT_CHARACTER_ON;
1003 gfc_option.flag_init_character_value = (char)value;
1005 else
1006 gfc_fatal_error ("The value of n in -finit-character=n must be "
1007 "between 0 and 127");
1008 break;
1010 case OPT_I:
1011 gfc_add_include_path (arg, true, false, true);
1012 break;
1014 case OPT_J:
1015 gfc_handle_module_path_options (arg);
1016 break;
1018 case OPT_fsign_zero:
1019 gfc_option.flag_sign_zero = value;
1020 break;
1022 case OPT_ffpe_trap_:
1023 gfc_handle_fpe_option (arg, true);
1024 break;
1026 case OPT_ffpe_summary_:
1027 gfc_handle_fpe_option (arg, false);
1028 break;
1030 case OPT_std_f95:
1031 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F95 | GFC_STD_F77
1032 | GFC_STD_F2008_OBS;
1033 gfc_option.warn_std = GFC_STD_F95_OBS;
1034 gfc_option.max_continue_fixed = 19;
1035 gfc_option.max_continue_free = 39;
1036 gfc_option.max_identifier_length = 31;
1037 gfc_option.warn_ampersand = 1;
1038 gfc_option.warn_tabs = 0;
1039 break;
1041 case OPT_std_f2003:
1042 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F77
1043 | GFC_STD_F2003 | GFC_STD_F95 | GFC_STD_F2008_OBS;
1044 gfc_option.warn_std = GFC_STD_F95_OBS;
1045 gfc_option.max_identifier_length = 63;
1046 gfc_option.warn_ampersand = 1;
1047 gfc_option.warn_tabs = 0;
1048 break;
1050 case OPT_std_f2008:
1051 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F77
1052 | GFC_STD_F2003 | GFC_STD_F95 | GFC_STD_F2008 | GFC_STD_F2008_OBS;
1053 gfc_option.warn_std = GFC_STD_F95_OBS | GFC_STD_F2008_OBS;
1054 gfc_option.max_identifier_length = 63;
1055 gfc_option.warn_ampersand = 1;
1056 gfc_option.warn_tabs = 0;
1057 break;
1059 case OPT_std_f2008ts:
1060 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F77
1061 | GFC_STD_F2003 | GFC_STD_F95 | GFC_STD_F2008 | GFC_STD_F2008_OBS
1062 | GFC_STD_F2008_TS;
1063 gfc_option.warn_std = GFC_STD_F95_OBS | GFC_STD_F2008_OBS;
1064 gfc_option.max_identifier_length = 63;
1065 gfc_option.warn_ampersand = 1;
1066 gfc_option.warn_tabs = 0;
1067 break;
1069 case OPT_std_gnu:
1070 set_default_std_flags ();
1071 break;
1073 case OPT_std_legacy:
1074 set_default_std_flags ();
1075 gfc_option.warn_std = 0;
1076 break;
1078 case OPT_Wintrinsics_std:
1079 gfc_option.warn_intrinsics_std = value;
1080 break;
1082 case OPT_fshort_enums:
1083 /* Handled in language-independent code. */
1084 break;
1086 case OPT_fconvert_little_endian:
1087 gfc_option.convert = GFC_CONVERT_LITTLE;
1088 break;
1090 case OPT_fconvert_big_endian:
1091 gfc_option.convert = GFC_CONVERT_BIG;
1092 break;
1094 case OPT_fconvert_native:
1095 gfc_option.convert = GFC_CONVERT_NATIVE;
1096 break;
1098 case OPT_fconvert_swap:
1099 gfc_option.convert = GFC_CONVERT_SWAP;
1100 break;
1102 case OPT_frecord_marker_4:
1103 gfc_option.record_marker = 4;
1104 break;
1106 case OPT_frecord_marker_8:
1107 gfc_option.record_marker = 8;
1108 break;
1110 case OPT_fmax_subrecord_length_:
1111 if (value > MAX_SUBRECORD_LENGTH)
1112 gfc_fatal_error ("Maximum subrecord length cannot exceed %d",
1113 MAX_SUBRECORD_LENGTH);
1115 gfc_option.max_subrecord_length = value;
1116 break;
1118 case OPT_frecursive:
1119 gfc_option.flag_recursive = value;
1120 break;
1122 case OPT_falign_commons:
1123 gfc_option.flag_align_commons = value;
1124 break;
1126 case OPT_faggressive_function_elimination:
1127 gfc_option.flag_aggressive_function_elimination = value;
1128 break;
1130 case OPT_ffrontend_optimize:
1131 gfc_option.flag_frontend_optimize = value;
1132 break;
1134 case OPT_fprotect_parens:
1135 gfc_option.flag_protect_parens = value;
1136 break;
1138 case OPT_frealloc_lhs:
1139 gfc_option.flag_realloc_lhs = value;
1140 break;
1142 case OPT_fcheck_:
1143 gfc_handle_runtime_check_option (arg);
1144 break;
1146 case OPT_fcoarray_:
1147 gfc_handle_coarray_option (arg);
1148 break;
1151 Fortran_handle_option_auto (&global_options, &global_options_set,
1152 scode, arg, value,
1153 gfc_option_lang_mask (), kind,
1154 loc, handlers, global_dc);
1155 return result;
1159 /* Return a string with the options passed to the compiler; used for
1160 Fortran's compiler_options() intrinsic. */
1162 char *
1163 gfc_get_option_string (void)
1165 unsigned j;
1166 size_t len, pos;
1167 char *result;
1169 /* Allocate and return a one-character string with '\0'. */
1170 if (!save_decoded_options_count)
1171 return XCNEWVEC (char, 1);
1173 /* Determine required string length. */
1175 len = 0;
1176 for (j = 1; j < save_decoded_options_count; j++)
1178 switch (save_decoded_options[j].opt_index)
1180 case OPT_o:
1181 case OPT_d:
1182 case OPT_dumpbase:
1183 case OPT_dumpdir:
1184 case OPT_auxbase:
1185 case OPT_quiet:
1186 case OPT_version:
1187 case OPT_fintrinsic_modules_path:
1188 case OPT_fintrinsic_modules_path_:
1189 /* Ignore these. */
1190 break;
1191 default:
1192 /* Ignore file names. */
1193 if (save_decoded_options[j].orig_option_with_args_text[0] == '-')
1194 len += 1
1195 + strlen (save_decoded_options[j].orig_option_with_args_text);
1199 result = XCNEWVEC (char, len);
1201 pos = 0;
1202 for (j = 1; j < save_decoded_options_count; j++)
1204 switch (save_decoded_options[j].opt_index)
1206 case OPT_o:
1207 case OPT_d:
1208 case OPT_dumpbase:
1209 case OPT_dumpdir:
1210 case OPT_auxbase:
1211 case OPT_quiet:
1212 case OPT_version:
1213 case OPT_fintrinsic_modules_path:
1214 case OPT_fintrinsic_modules_path_:
1215 /* Ignore these. */
1216 continue;
1218 case OPT_cpp_:
1219 /* Use "-cpp" rather than "-cpp=<temporary file>". */
1220 len = 4;
1221 break;
1223 default:
1224 /* Ignore file names. */
1225 if (save_decoded_options[j].orig_option_with_args_text[0] != '-')
1226 continue;
1228 len = strlen (save_decoded_options[j].orig_option_with_args_text);
1231 memcpy (&result[pos], save_decoded_options[j].orig_option_with_args_text, len);
1232 pos += len;
1233 result[pos++] = ' ';
1236 result[--pos] = '\0';
1237 return result;