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