]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/fortran/options.c
re PR fortran/85735 (f951 crashes on empty input)
[thirdparty/gcc.git] / gcc / fortran / options.c
1 /* Parse and display command line options.
2 Copyright (C) 2000-2018 Free Software Foundation, Inc.
3 Contributed by Andy Vaught
4
5 This file is part of GCC.
6
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.
11
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.
16
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/>. */
20
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "target.h"
25 #include "tree.h"
26 #include "gfortran.h"
27 #include "diagnostic.h" /* For global_dc. */
28 #include "opts.h"
29 #include "toplev.h" /* For save_decoded_options. */
30 #include "cpp.h"
31 #include "langhooks.h"
32
33 gfc_option_t gfc_option;
34
35
36 /* Set flags that control warnings and errors for different
37 Fortran standards to their default values. Keep in sync with
38 libgfortran/runtime/compile_options.c (init_compile_options). */
39
40 static void
41 set_default_std_flags (void)
42 {
43 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F95_DEL
44 | GFC_STD_F2003 | GFC_STD_F2008 | GFC_STD_F95 | GFC_STD_F77
45 | GFC_STD_F2008_OBS | GFC_STD_F2008_TS | GFC_STD_GNU | GFC_STD_LEGACY
46 | GFC_STD_F2018 | GFC_STD_F2018_DEL | GFC_STD_F2018_OBS;
47 gfc_option.warn_std = GFC_STD_F95_DEL | GFC_STD_LEGACY;
48 }
49
50
51 /* Set all the DEC extension flags. */
52
53 static void
54 set_dec_flags (int value)
55 {
56 if (value)
57 {
58 /* Allow legacy code without warnings. */
59 gfc_option.allow_std |= GFC_STD_F95_OBS | GFC_STD_F95_DEL
60 | GFC_STD_GNU | GFC_STD_LEGACY;
61 gfc_option.warn_std &= ~(GFC_STD_LEGACY | GFC_STD_F95_DEL);
62 }
63
64 /* Set other DEC compatibility extensions. */
65 flag_dollar_ok |= value;
66 flag_cray_pointer |= value;
67 flag_dec_structure |= value;
68 flag_dec_intrinsic_ints |= value;
69 flag_dec_static |= value;
70 flag_dec_math |= value;
71 }
72
73
74 /* Return language mask for Fortran options. */
75
76 unsigned int
77 gfc_option_lang_mask (void)
78 {
79 return CL_Fortran;
80 }
81
82 /* Initialize options structure OPTS. */
83
84 void
85 gfc_init_options_struct (struct gcc_options *opts)
86 {
87 opts->x_flag_errno_math = 0;
88 opts->frontend_set_flag_errno_math = true;
89 opts->x_flag_associative_math = -1;
90 opts->frontend_set_flag_associative_math = true;
91 }
92
93 /* Get ready for options handling. Keep in sync with
94 libgfortran/runtime/compile_options.c (init_compile_options). */
95
96 void
97 gfc_init_options (unsigned int decoded_options_count,
98 struct cl_decoded_option *decoded_options)
99 {
100 gfc_source_file = NULL;
101 gfc_option.module_dir = NULL;
102 gfc_option.source_form = FORM_UNKNOWN;
103 gfc_option.max_continue_fixed = 255;
104 gfc_option.max_continue_free = 255;
105 gfc_option.max_identifier_length = GFC_MAX_SYMBOL_LEN;
106 gfc_option.max_errors = 25;
107
108 gfc_option.flag_preprocessed = 0;
109 gfc_option.flag_d_lines = -1;
110 gfc_option.flag_init_integer = GFC_INIT_INTEGER_OFF;
111 gfc_option.flag_init_integer_value = 0;
112 gfc_option.flag_init_logical = GFC_INIT_LOGICAL_OFF;
113 gfc_option.flag_init_character = GFC_INIT_CHARACTER_OFF;
114 gfc_option.flag_init_character_value = (char)0;
115
116 gfc_option.fpe = 0;
117 /* All except GFC_FPE_INEXACT. */
118 gfc_option.fpe_summary = GFC_FPE_INVALID | GFC_FPE_DENORMAL
119 | GFC_FPE_ZERO | GFC_FPE_OVERFLOW
120 | GFC_FPE_UNDERFLOW;
121 gfc_option.rtcheck = 0;
122
123 /* ??? Wmissing-include-dirs is disabled by default in C/C++ but
124 enabled by default in Fortran. Ideally, we should express this
125 in .opt, but that is not supported yet. */
126 if (!global_options_set.x_cpp_warn_missing_include_dirs)
127 global_options.x_cpp_warn_missing_include_dirs = 1;
128
129 set_dec_flags (0);
130
131 set_default_std_flags ();
132
133 /* Initialize cpp-related options. */
134 gfc_cpp_init_options (decoded_options_count, decoded_options);
135 gfc_diagnostics_init ();
136 }
137
138
139 /* Determine the source form from the filename extension. We assume
140 case insensitivity. */
141
142 static gfc_source_form
143 form_from_filename (const char *filename)
144 {
145 static const struct
146 {
147 const char *extension;
148 gfc_source_form form;
149 }
150 exttype[] =
151 {
152 {
153 ".f90", FORM_FREE}
154 ,
155 {
156 ".f95", FORM_FREE}
157 ,
158 {
159 ".f03", FORM_FREE}
160 ,
161 {
162 ".f08", FORM_FREE}
163 ,
164 {
165 ".f", FORM_FIXED}
166 ,
167 {
168 ".for", FORM_FIXED}
169 ,
170 {
171 ".ftn", FORM_FIXED}
172 ,
173 {
174 "", FORM_UNKNOWN}
175 }; /* sentinel value */
176
177 gfc_source_form f_form;
178 const char *fileext;
179 int i;
180
181 /* Find end of file name. Note, filename is either a NULL pointer or
182 a NUL terminated string. */
183 i = 0;
184 while (filename[i] != '\0')
185 i++;
186
187 /* Find last period. */
188 while (i >= 0 && (filename[i] != '.'))
189 i--;
190
191 /* Did we see a file extension? */
192 if (i < 0)
193 return FORM_UNKNOWN; /* Nope */
194
195 /* Get file extension and compare it to others. */
196 fileext = &(filename[i]);
197
198 i = -1;
199 f_form = FORM_UNKNOWN;
200 do
201 {
202 i++;
203 if (strcasecmp (fileext, exttype[i].extension) == 0)
204 {
205 f_form = exttype[i].form;
206 break;
207 }
208 }
209 while (exttype[i].form != FORM_UNKNOWN);
210
211 return f_form;
212 }
213
214
215 /* Finalize commandline options. */
216
217 bool
218 gfc_post_options (const char **pfilename)
219 {
220 const char *filename = *pfilename, *canon_source_file = NULL;
221 char *source_path;
222 int i;
223
224 /* Excess precision other than "fast" requires front-end
225 support. */
226 if (flag_excess_precision_cmdline == EXCESS_PRECISION_STANDARD)
227 sorry ("-fexcess-precision=standard for Fortran");
228 flag_excess_precision_cmdline = EXCESS_PRECISION_FAST;
229
230 /* Fortran allows associative math - but we cannot reassociate if
231 we want traps or signed zeros. Cf. also flag_protect_parens. */
232 if (flag_associative_math == -1)
233 flag_associative_math = (!flag_trapping_math && !flag_signed_zeros);
234
235 if (flag_protect_parens == -1)
236 flag_protect_parens = !optimize_fast;
237
238 /* -Ofast sets implies -fstack-arrays unless an explicit size is set for
239 stack arrays. */
240 if (flag_stack_arrays == -1 && flag_max_stack_var_size == -2)
241 flag_stack_arrays = optimize_fast;
242
243 /* By default, disable (re)allocation during assignment for -std=f95,
244 and enable it for F2003/F2008/GNU/Legacy. */
245 if (flag_realloc_lhs == -1)
246 {
247 if (gfc_option.allow_std & GFC_STD_F2003)
248 flag_realloc_lhs = 1;
249 else
250 flag_realloc_lhs = 0;
251 }
252
253 /* -fbounds-check is equivalent to -fcheck=bounds */
254 if (flag_bounds_check)
255 gfc_option.rtcheck |= GFC_RTCHECK_BOUNDS;
256
257 if (flag_compare_debug)
258 flag_dump_fortran_original = 0;
259
260 /* Make -fmax-errors visible to gfortran's diagnostic machinery. */
261 if (global_options_set.x_flag_max_errors)
262 gfc_option.max_errors = flag_max_errors;
263
264 /* Verify the input file name. */
265 if (!filename || strcmp (filename, "-") == 0)
266 {
267 filename = "";
268 }
269
270 if (gfc_option.flag_preprocessed)
271 {
272 /* For preprocessed files, if the first tokens are of the form # NUM.
273 handle the directives so we know the original file name. */
274 gfc_source_file = gfc_read_orig_filename (filename, &canon_source_file);
275 if (gfc_source_file == NULL)
276 gfc_source_file = filename;
277 else
278 *pfilename = gfc_source_file;
279 }
280 else
281 gfc_source_file = filename;
282
283 if (canon_source_file == NULL)
284 canon_source_file = gfc_source_file;
285
286 /* Adds the path where the source file is to the list of include files. */
287
288 i = strlen (canon_source_file);
289 while (i > 0 && !IS_DIR_SEPARATOR (canon_source_file[i]))
290 i--;
291
292 if (i != 0)
293 {
294 source_path = (char *) alloca (i + 1);
295 memcpy (source_path, canon_source_file, i);
296 source_path[i] = 0;
297 gfc_add_include_path (source_path, true, true, true);
298 }
299 else
300 gfc_add_include_path (".", true, true, true);
301
302 if (canon_source_file != gfc_source_file)
303 free (CONST_CAST (char *, canon_source_file));
304
305 /* Decide which form the file will be read in as. */
306
307 if (gfc_option.source_form != FORM_UNKNOWN)
308 gfc_current_form = gfc_option.source_form;
309 else
310 {
311 gfc_current_form = form_from_filename (filename);
312
313 if (gfc_current_form == FORM_UNKNOWN)
314 {
315 gfc_current_form = FORM_FREE;
316 main_input_filename = filename;
317 gfc_warning_now (0, "Reading file %qs as free form",
318 (filename[0] == '\0') ? "<stdin>" : filename);
319 }
320 }
321
322 /* If the user specified -fd-lines-as-{code|comments} verify that we're
323 in fixed form. */
324 if (gfc_current_form == FORM_FREE)
325 {
326 if (gfc_option.flag_d_lines == 0)
327 gfc_warning_now (0, "%<-fd-lines-as-comments%> has no effect "
328 "in free form");
329 else if (gfc_option.flag_d_lines == 1)
330 gfc_warning_now (0, "%<-fd-lines-as-code%> has no effect in free form");
331
332 if (warn_line_truncation == -1)
333 warn_line_truncation = 1;
334
335 /* Enable -Werror=line-truncation when -Werror and -Wno-error have
336 not been set. */
337 if (warn_line_truncation && !global_options_set.x_warnings_are_errors
338 && (global_dc->classify_diagnostic[OPT_Wline_truncation] ==
339 DK_UNSPECIFIED))
340 diagnostic_classify_diagnostic (global_dc, OPT_Wline_truncation,
341 DK_ERROR, UNKNOWN_LOCATION);
342 }
343 else
344 {
345 /* With -fdec, set -fd-lines-as-comments by default in fixed form. */
346 if (flag_dec && gfc_option.flag_d_lines == -1)
347 gfc_option.flag_d_lines = 0;
348
349 if (warn_line_truncation == -1)
350 warn_line_truncation = 0;
351 }
352
353 /* If -pedantic, warn about the use of GNU extensions. */
354 if (pedantic && (gfc_option.allow_std & GFC_STD_GNU) != 0)
355 gfc_option.warn_std |= GFC_STD_GNU;
356 /* -std=legacy -pedantic is effectively -std=gnu. */
357 if (pedantic && (gfc_option.allow_std & GFC_STD_LEGACY) != 0)
358 gfc_option.warn_std |= GFC_STD_F95_OBS | GFC_STD_F95_DEL | GFC_STD_LEGACY;
359
360 /* If the user didn't explicitly specify -f(no)-second-underscore we
361 use it if we're trying to be compatible with f2c, and not
362 otherwise. */
363 if (flag_second_underscore == -1)
364 flag_second_underscore = flag_f2c;
365
366 if (!flag_automatic && flag_max_stack_var_size != -2
367 && flag_max_stack_var_size != 0)
368 gfc_warning_now (0, "Flag %<-fno-automatic%> overwrites %<-fmax-stack-var-size=%d%>",
369 flag_max_stack_var_size);
370 else if (!flag_automatic && flag_recursive)
371 gfc_warning_now (0, "Flag %<-fno-automatic%> overwrites %<-frecursive%>");
372 else if (!flag_automatic && flag_openmp)
373 gfc_warning_now (0, "Flag %<-fno-automatic%> overwrites %<-frecursive%> implied by "
374 "%<-fopenmp%>");
375 else if (flag_max_stack_var_size != -2 && flag_recursive)
376 gfc_warning_now (0, "Flag %<-frecursive%> overwrites %<-fmax-stack-var-size=%d%>",
377 flag_max_stack_var_size);
378 else if (flag_max_stack_var_size != -2 && flag_openmp)
379 gfc_warning_now (0, "Flag %<-fmax-stack-var-size=%d%> overwrites %<-frecursive%> "
380 "implied by %<-fopenmp%>", flag_max_stack_var_size);
381
382 /* Implement -frecursive as -fmax-stack-var-size=-1. */
383 if (flag_recursive)
384 flag_max_stack_var_size = -1;
385
386 /* Implied -frecursive; implemented as -fmax-stack-var-size=-1. */
387 if (flag_max_stack_var_size == -2 && flag_openmp && flag_automatic)
388 {
389 flag_recursive = 1;
390 flag_max_stack_var_size = -1;
391 }
392
393 /* Set flag_stack_arrays correctly. */
394 if (flag_stack_arrays == -1)
395 flag_stack_arrays = 0;
396
397 /* Set default. */
398 if (flag_max_stack_var_size == -2)
399 flag_max_stack_var_size = 32768;
400
401 /* Implement -fno-automatic as -fmax-stack-var-size=0. */
402 if (!flag_automatic)
403 flag_max_stack_var_size = 0;
404
405 /* If the user did not specify an inline matmul limit, inline up to the BLAS
406 limit or up to 30 if no external BLAS is specified. */
407
408 if (flag_inline_matmul_limit < 0)
409 {
410 if (flag_external_blas)
411 flag_inline_matmul_limit = flag_blas_matmul_limit;
412 else
413 flag_inline_matmul_limit = 30;
414 }
415
416 /* Optimization implies front end optimization, unless the user
417 specified it directly. */
418
419 if (flag_frontend_optimize == -1)
420 flag_frontend_optimize = optimize;
421
422 /* Same for front end loop interchange. */
423
424 if (flag_frontend_loop_interchange == -1)
425 flag_frontend_loop_interchange = optimize;
426
427 if (flag_max_array_constructor < 65535)
428 flag_max_array_constructor = 65535;
429
430 if (flag_fixed_line_length != 0 && flag_fixed_line_length < 7)
431 gfc_fatal_error ("Fixed line length must be at least seven");
432
433 if (flag_free_line_length != 0 && flag_free_line_length < 4)
434 gfc_fatal_error ("Free line length must be at least three");
435
436 if (flag_max_subrecord_length > MAX_SUBRECORD_LENGTH)
437 gfc_fatal_error ("Maximum subrecord length cannot exceed %d",
438 MAX_SUBRECORD_LENGTH);
439
440 gfc_cpp_post_options ();
441
442 if (gfc_option.allow_std & GFC_STD_F2008)
443 lang_hooks.name = "GNU Fortran2008";
444 else if (gfc_option.allow_std & GFC_STD_F2003)
445 lang_hooks.name = "GNU Fortran2003";
446
447 return gfc_cpp_preprocess_only ();
448 }
449
450
451 static void
452 gfc_handle_module_path_options (const char *arg)
453 {
454
455 if (gfc_option.module_dir != NULL)
456 gfc_fatal_error ("gfortran: Only one %<-J%> option allowed");
457
458 gfc_option.module_dir = XCNEWVEC (char, strlen (arg) + 2);
459 strcpy (gfc_option.module_dir, arg);
460
461 gfc_add_include_path (gfc_option.module_dir, true, false, true);
462
463 strcat (gfc_option.module_dir, "/");
464 }
465
466
467 /* Handle options -ffpe-trap= and -ffpe-summary=. */
468
469 static void
470 gfc_handle_fpe_option (const char *arg, bool trap)
471 {
472 int result, pos = 0, n;
473 /* precision is a backwards compatibility alias for inexact. */
474 static const char * const exception[] = { "invalid", "denormal", "zero",
475 "overflow", "underflow",
476 "inexact", "precision", NULL };
477 static const int opt_exception[] = { GFC_FPE_INVALID, GFC_FPE_DENORMAL,
478 GFC_FPE_ZERO, GFC_FPE_OVERFLOW,
479 GFC_FPE_UNDERFLOW, GFC_FPE_INEXACT,
480 GFC_FPE_INEXACT,
481 0 };
482
483 /* As the default for -ffpe-summary= is nonzero, set it to 0. */
484 if (!trap)
485 gfc_option.fpe_summary = 0;
486
487 while (*arg)
488 {
489 while (*arg == ',')
490 arg++;
491
492 while (arg[pos] && arg[pos] != ',')
493 pos++;
494
495 result = 0;
496 if (!trap && strncmp ("none", arg, pos) == 0)
497 {
498 gfc_option.fpe_summary = 0;
499 arg += pos;
500 pos = 0;
501 continue;
502 }
503 else if (!trap && strncmp ("all", arg, pos) == 0)
504 {
505 gfc_option.fpe_summary = GFC_FPE_INVALID | GFC_FPE_DENORMAL
506 | GFC_FPE_ZERO | GFC_FPE_OVERFLOW
507 | GFC_FPE_UNDERFLOW | GFC_FPE_INEXACT;
508 arg += pos;
509 pos = 0;
510 continue;
511 }
512 else
513 for (n = 0; exception[n] != NULL; n++)
514 {
515 if (exception[n] && strncmp (exception[n], arg, pos) == 0)
516 {
517 if (trap)
518 gfc_option.fpe |= opt_exception[n];
519 else
520 gfc_option.fpe_summary |= opt_exception[n];
521 arg += pos;
522 pos = 0;
523 result = 1;
524 break;
525 }
526 }
527 if (!result && !trap)
528 gfc_fatal_error ("Argument to %<-ffpe-trap%> is not valid: %s", arg);
529 else if (!result)
530 gfc_fatal_error ("Argument to %<-ffpe-summary%> is not valid: %s", arg);
531
532 }
533 }
534
535
536 static void
537 gfc_handle_runtime_check_option (const char *arg)
538 {
539 int result, pos = 0, n;
540 static const char * const optname[] = { "all", "bounds", "array-temps",
541 "recursion", "do", "pointer",
542 "mem", NULL };
543 static const int optmask[] = { GFC_RTCHECK_ALL, GFC_RTCHECK_BOUNDS,
544 GFC_RTCHECK_ARRAY_TEMPS,
545 GFC_RTCHECK_RECURSION, GFC_RTCHECK_DO,
546 GFC_RTCHECK_POINTER, GFC_RTCHECK_MEM,
547 0 };
548
549 while (*arg)
550 {
551 while (*arg == ',')
552 arg++;
553
554 while (arg[pos] && arg[pos] != ',')
555 pos++;
556
557 result = 0;
558 for (n = 0; optname[n] != NULL; n++)
559 {
560 if (optname[n] && strncmp (optname[n], arg, pos) == 0)
561 {
562 gfc_option.rtcheck |= optmask[n];
563 arg += pos;
564 pos = 0;
565 result = 1;
566 break;
567 }
568 else if (optname[n] && pos > 3 && strncmp ("no-", arg, 3) == 0
569 && strncmp (optname[n], arg+3, pos-3) == 0)
570 {
571 gfc_option.rtcheck &= ~optmask[n];
572 arg += pos;
573 pos = 0;
574 result = 1;
575 break;
576 }
577 }
578 if (!result)
579 gfc_fatal_error ("Argument to %<-fcheck%> is not valid: %s", arg);
580 }
581 }
582
583
584 /* Handle command-line options. Returns 0 if unrecognized, 1 if
585 recognized and handled. */
586
587 bool
588 gfc_handle_option (size_t scode, const char *arg, int value,
589 int kind ATTRIBUTE_UNUSED, location_t loc ATTRIBUTE_UNUSED,
590 const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED)
591 {
592 bool result = true;
593 enum opt_code code = (enum opt_code) scode;
594
595 if (gfc_cpp_handle_option (scode, arg, value) == 1)
596 return true;
597
598 switch (code)
599 {
600 default:
601 if (cl_options[code].flags & gfc_option_lang_mask ())
602 break;
603 result = false;
604 break;
605
606 case OPT_fcheck_array_temporaries:
607 gfc_option.rtcheck |= GFC_RTCHECK_ARRAY_TEMPS;
608 break;
609
610 case OPT_fd_lines_as_code:
611 gfc_option.flag_d_lines = 1;
612 break;
613
614 case OPT_fd_lines_as_comments:
615 gfc_option.flag_d_lines = 0;
616 break;
617
618 case OPT_ffixed_form:
619 gfc_option.source_form = FORM_FIXED;
620 break;
621
622 case OPT_ffree_form:
623 gfc_option.source_form = FORM_FREE;
624 break;
625
626 case OPT_static_libgfortran:
627 #ifndef HAVE_LD_STATIC_DYNAMIC
628 gfc_fatal_error ("%<-static-libgfortran%> is not supported in this "
629 "configuration");
630 #endif
631 break;
632
633 case OPT_fintrinsic_modules_path:
634 case OPT_fintrinsic_modules_path_:
635
636 /* This is needed because omp_lib.h is in a directory together
637 with intrinsic modules. Do no warn because during testing
638 without an installed compiler, we would get lots of bogus
639 warnings for a missing include directory. */
640 gfc_add_include_path (arg, false, false, false);
641
642 gfc_add_intrinsic_modules_path (arg);
643 break;
644
645 case OPT_fpreprocessed:
646 gfc_option.flag_preprocessed = value;
647 break;
648
649 case OPT_fmax_identifier_length_:
650 if (value > GFC_MAX_SYMBOL_LEN)
651 gfc_fatal_error ("Maximum supported identifier length is %d",
652 GFC_MAX_SYMBOL_LEN);
653 gfc_option.max_identifier_length = value;
654 break;
655
656 case OPT_finit_local_zero:
657 gfc_option.flag_init_integer = GFC_INIT_INTEGER_ON;
658 gfc_option.flag_init_integer_value = 0;
659 flag_init_real = GFC_INIT_REAL_ZERO;
660 gfc_option.flag_init_logical = GFC_INIT_LOGICAL_FALSE;
661 gfc_option.flag_init_character = GFC_INIT_CHARACTER_ON;
662 gfc_option.flag_init_character_value = (char)0;
663 break;
664
665 case OPT_finit_logical_:
666 if (!strcasecmp (arg, "false"))
667 gfc_option.flag_init_logical = GFC_INIT_LOGICAL_FALSE;
668 else if (!strcasecmp (arg, "true"))
669 gfc_option.flag_init_logical = GFC_INIT_LOGICAL_TRUE;
670 else
671 gfc_fatal_error ("Unrecognized option to %<-finit-logical%>: %s",
672 arg);
673 break;
674
675 case OPT_finit_integer_:
676 gfc_option.flag_init_integer = GFC_INIT_INTEGER_ON;
677 gfc_option.flag_init_integer_value = atoi (arg);
678 break;
679
680 case OPT_finit_character_:
681 if (value >= 0 && value <= 127)
682 {
683 gfc_option.flag_init_character = GFC_INIT_CHARACTER_ON;
684 gfc_option.flag_init_character_value = (char)value;
685 }
686 else
687 gfc_fatal_error ("The value of n in %<-finit-character=n%> must be "
688 "between 0 and 127");
689 break;
690
691 case OPT_I:
692 gfc_add_include_path (arg, true, false, true);
693 break;
694
695 case OPT_J:
696 gfc_handle_module_path_options (arg);
697 break;
698
699 case OPT_ffpe_trap_:
700 gfc_handle_fpe_option (arg, true);
701 break;
702
703 case OPT_ffpe_summary_:
704 gfc_handle_fpe_option (arg, false);
705 break;
706
707 case OPT_std_f95:
708 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F95 | GFC_STD_F77
709 | GFC_STD_F2008_OBS;
710 gfc_option.warn_std = GFC_STD_F95_OBS;
711 gfc_option.max_continue_fixed = 19;
712 gfc_option.max_continue_free = 39;
713 gfc_option.max_identifier_length = 31;
714 warn_ampersand = 1;
715 warn_tabs = 1;
716 break;
717
718 case OPT_std_f2003:
719 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F77
720 | GFC_STD_F2003 | GFC_STD_F95 | GFC_STD_F2008_OBS;
721 gfc_option.warn_std = GFC_STD_F95_OBS;
722 gfc_option.max_identifier_length = 63;
723 warn_ampersand = 1;
724 warn_tabs = 1;
725 break;
726
727 case OPT_std_f2008:
728 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F77
729 | GFC_STD_F2003 | GFC_STD_F95 | GFC_STD_F2008 | GFC_STD_F2008_OBS;
730 gfc_option.warn_std = GFC_STD_F95_OBS | GFC_STD_F2008_OBS;
731 gfc_option.max_identifier_length = 63;
732 warn_ampersand = 1;
733 warn_tabs = 1;
734 break;
735
736 case OPT_std_f2008ts:
737 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F77
738 | GFC_STD_F2003 | GFC_STD_F95 | GFC_STD_F2008 | GFC_STD_F2008_OBS
739 | GFC_STD_F2008_TS;
740 gfc_option.warn_std = GFC_STD_F95_OBS | GFC_STD_F2008_OBS;
741 gfc_option.max_identifier_length = 63;
742 warn_ampersand = 1;
743 warn_tabs = 1;
744 break;
745
746 case OPT_std_f2018:
747 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F77
748 | GFC_STD_F2003 | GFC_STD_F95 | GFC_STD_F2008 | GFC_STD_F2008_OBS
749 | GFC_STD_F2008_TS | GFC_STD_F2018 | GFC_STD_F2018_OBS;
750 gfc_option.warn_std = GFC_STD_F95_OBS | GFC_STD_F2008_OBS
751 | GFC_STD_F2018_OBS;
752 gfc_option.max_identifier_length = 63;
753 warn_ampersand = 1;
754 warn_tabs = 1;
755 break;
756
757 case OPT_std_gnu:
758 set_default_std_flags ();
759 break;
760
761 case OPT_std_legacy:
762 set_default_std_flags ();
763 gfc_option.warn_std = 0;
764 break;
765
766 case OPT_fshort_enums:
767 /* Handled in language-independent code. */
768 break;
769
770 case OPT_fcheck_:
771 gfc_handle_runtime_check_option (arg);
772 break;
773
774 case OPT_fdec:
775 /* Enable all DEC extensions. */
776 set_dec_flags (1);
777 break;
778
779 case OPT_fdec_structure:
780 flag_dec_structure = 1;
781 break;
782 }
783
784 Fortran_handle_option_auto (&global_options, &global_options_set,
785 scode, arg, value,
786 gfc_option_lang_mask (), kind,
787 loc, handlers, global_dc);
788 return result;
789 }
790
791
792 /* Return a string with the options passed to the compiler; used for
793 Fortran's compiler_options() intrinsic. */
794
795 char *
796 gfc_get_option_string (void)
797 {
798 unsigned j;
799 size_t len, pos;
800 char *result;
801
802 /* Allocate and return a one-character string with '\0'. */
803 if (!save_decoded_options_count)
804 return XCNEWVEC (char, 1);
805
806 /* Determine required string length. */
807
808 len = 0;
809 for (j = 1; j < save_decoded_options_count; j++)
810 {
811 switch (save_decoded_options[j].opt_index)
812 {
813 case OPT_o:
814 case OPT_d:
815 case OPT_dumpbase:
816 case OPT_dumpdir:
817 case OPT_auxbase:
818 case OPT_quiet:
819 case OPT_version:
820 case OPT_fintrinsic_modules_path:
821 case OPT_fintrinsic_modules_path_:
822 /* Ignore these. */
823 break;
824 default:
825 /* Ignore file names. */
826 if (save_decoded_options[j].orig_option_with_args_text[0] == '-')
827 len += 1
828 + strlen (save_decoded_options[j].orig_option_with_args_text);
829 }
830 }
831
832 result = XCNEWVEC (char, len);
833
834 pos = 0;
835 for (j = 1; j < save_decoded_options_count; j++)
836 {
837 switch (save_decoded_options[j].opt_index)
838 {
839 case OPT_o:
840 case OPT_d:
841 case OPT_dumpbase:
842 case OPT_dumpdir:
843 case OPT_auxbase:
844 case OPT_quiet:
845 case OPT_version:
846 case OPT_fintrinsic_modules_path:
847 case OPT_fintrinsic_modules_path_:
848 /* Ignore these. */
849 continue;
850
851 case OPT_cpp_:
852 /* Use "-cpp" rather than "-cpp=<temporary file>". */
853 len = 4;
854 break;
855
856 default:
857 /* Ignore file names. */
858 if (save_decoded_options[j].orig_option_with_args_text[0] != '-')
859 continue;
860
861 len = strlen (save_decoded_options[j].orig_option_with_args_text);
862 }
863
864 memcpy (&result[pos], save_decoded_options[j].orig_option_with_args_text, len);
865 pos += len;
866 result[pos++] = ' ';
867 }
868
869 result[--pos] = '\0';
870 return result;
871 }