]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/fortran/options.c
re PR fortran/60447 (Empty .s file created when using -E flag)
[thirdparty/gcc.git] / gcc / fortran / options.c
1 /* Parse and display command line options.
2 Copyright (C) 2000-2014 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 "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"
37
38 gfc_option_t gfc_option;
39
40
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). */
44
45 static void
46 set_default_std_flags (void)
47 {
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;
52 }
53
54
55 /* Return language mask for Fortran options. */
56
57 unsigned int
58 gfc_option_lang_mask (void)
59 {
60 return CL_Fortran;
61 }
62
63 /* Initialize options structure OPTS. */
64
65 void
66 gfc_init_options_struct (struct gcc_options *opts)
67 {
68 opts->x_flag_errno_math = 0;
69 opts->x_flag_associative_math = -1;
70 }
71
72 /* Get ready for options handling. Keep in sync with
73 libgfortran/runtime/compile_options.c (init_compile_options). */
74
75 void
76 gfc_init_options (unsigned int decoded_options_count,
77 struct cl_decoded_option *decoded_options)
78 {
79 gfc_source_file = NULL;
80 gfc_option.module_dir = NULL;
81 gfc_option.source_form = FORM_UNKNOWN;
82 gfc_option.fixed_line_length = 72;
83 gfc_option.free_line_length = 132;
84 gfc_option.max_continue_fixed = 255;
85 gfc_option.max_continue_free = 255;
86 gfc_option.max_identifier_length = GFC_MAX_SYMBOL_LEN;
87 gfc_option.max_subrecord_length = 0;
88 gfc_option.flag_max_array_constructor = 65535;
89 gfc_option.convert = GFC_CONVERT_NATIVE;
90 gfc_option.record_marker = 0;
91 gfc_option.dump_fortran_original = 0;
92 gfc_option.dump_fortran_optimized = 0;
93
94 gfc_option.warn_aliasing = 0;
95 gfc_option.warn_ampersand = 0;
96 gfc_option.warn_character_truncation = 0;
97 gfc_option.warn_array_temp = 0;
98 gfc_option.warn_c_binding_type = 0;
99 gfc_option.gfc_warn_conversion = 0;
100 gfc_option.warn_conversion_extra = 0;
101 gfc_option.warn_function_elimination = 0;
102 gfc_option.warn_implicit_interface = 0;
103 gfc_option.warn_line_truncation = 0;
104 gfc_option.warn_surprising = 0;
105 gfc_option.warn_tabs = 1;
106 gfc_option.warn_underflow = 1;
107 gfc_option.warn_intrinsic_shadow = 0;
108 gfc_option.warn_intrinsics_std = 0;
109 gfc_option.warn_align_commons = 1;
110 gfc_option.warn_real_q_constant = 0;
111 gfc_option.warn_unused_dummy_argument = 0;
112 gfc_option.warn_zerotrip = 0;
113 gfc_option.warn_realloc_lhs = 0;
114 gfc_option.warn_realloc_lhs_all = 0;
115 gfc_option.warn_compare_reals = 0;
116 gfc_option.warn_target_lifetime = 0;
117 gfc_option.max_errors = 25;
118
119 gfc_option.flag_all_intrinsics = 0;
120 gfc_option.flag_default_double = 0;
121 gfc_option.flag_default_integer = 0;
122 gfc_option.flag_default_real = 0;
123 gfc_option.flag_integer4_kind = 0;
124 gfc_option.flag_real4_kind = 0;
125 gfc_option.flag_real8_kind = 0;
126 gfc_option.flag_dollar_ok = 0;
127 gfc_option.flag_underscoring = 1;
128 gfc_option.flag_f2c = 0;
129 gfc_option.flag_second_underscore = -1;
130 gfc_option.flag_implicit_none = 0;
131
132 /* Default value of flag_max_stack_var_size is set in gfc_post_options. */
133 gfc_option.flag_max_stack_var_size = -2;
134 gfc_option.flag_stack_arrays = -1;
135
136 gfc_option.flag_range_check = 1;
137 gfc_option.flag_pack_derived = 0;
138 gfc_option.flag_repack_arrays = 0;
139 gfc_option.flag_preprocessed = 0;
140 gfc_option.flag_automatic = 1;
141 gfc_option.flag_backslash = 0;
142 gfc_option.flag_module_private = 0;
143 gfc_option.flag_backtrace = 1;
144 gfc_option.flag_allow_leading_underscore = 0;
145 gfc_option.flag_external_blas = 0;
146 gfc_option.blas_matmul_limit = 30;
147 gfc_option.flag_cray_pointer = 0;
148 gfc_option.flag_d_lines = -1;
149 gfc_option.gfc_flag_openmp = 0;
150 gfc_option.flag_sign_zero = 1;
151 gfc_option.flag_recursive = 0;
152 gfc_option.flag_init_integer = GFC_INIT_INTEGER_OFF;
153 gfc_option.flag_init_integer_value = 0;
154 gfc_option.flag_init_real = GFC_INIT_REAL_OFF;
155 gfc_option.flag_init_logical = GFC_INIT_LOGICAL_OFF;
156 gfc_option.flag_init_character = GFC_INIT_CHARACTER_OFF;
157 gfc_option.flag_init_character_value = (char)0;
158 gfc_option.flag_align_commons = 1;
159 gfc_option.flag_protect_parens = -1;
160 gfc_option.flag_realloc_lhs = -1;
161 gfc_option.flag_aggressive_function_elimination = 0;
162 gfc_option.flag_frontend_optimize = -1;
163
164 gfc_option.fpe = 0;
165 /* All except GFC_FPE_INEXACT. */
166 gfc_option.fpe_summary = GFC_FPE_INVALID | GFC_FPE_DENORMAL
167 | GFC_FPE_ZERO | GFC_FPE_OVERFLOW
168 | GFC_FPE_UNDERFLOW;
169 gfc_option.rtcheck = 0;
170 gfc_option.coarray = GFC_FCOARRAY_NONE;
171
172 set_default_std_flags ();
173
174 /* Initialize cpp-related options. */
175 gfc_cpp_init_options (decoded_options_count, decoded_options);
176 }
177
178
179 /* Determine the source form from the filename extension. We assume
180 case insensitivity. */
181
182 static gfc_source_form
183 form_from_filename (const char *filename)
184 {
185 static const struct
186 {
187 const char *extension;
188 gfc_source_form form;
189 }
190 exttype[] =
191 {
192 {
193 ".f90", FORM_FREE}
194 ,
195 {
196 ".f95", FORM_FREE}
197 ,
198 {
199 ".f03", FORM_FREE}
200 ,
201 {
202 ".f08", FORM_FREE}
203 ,
204 {
205 ".f", FORM_FIXED}
206 ,
207 {
208 ".for", FORM_FIXED}
209 ,
210 {
211 ".ftn", FORM_FIXED}
212 ,
213 {
214 "", FORM_UNKNOWN}
215 }; /* sentinel value */
216
217 gfc_source_form f_form;
218 const char *fileext;
219 int i;
220
221 /* Find end of file name. Note, filename is either a NULL pointer or
222 a NUL terminated string. */
223 i = 0;
224 while (filename[i] != '\0')
225 i++;
226
227 /* Find last period. */
228 while (i >= 0 && (filename[i] != '.'))
229 i--;
230
231 /* Did we see a file extension? */
232 if (i < 0)
233 return FORM_UNKNOWN; /* Nope */
234
235 /* Get file extension and compare it to others. */
236 fileext = &(filename[i]);
237
238 i = -1;
239 f_form = FORM_UNKNOWN;
240 do
241 {
242 i++;
243 if (strcasecmp (fileext, exttype[i].extension) == 0)
244 {
245 f_form = exttype[i].form;
246 break;
247 }
248 }
249 while (exttype[i].form != FORM_UNKNOWN);
250
251 return f_form;
252 }
253
254
255 /* Finalize commandline options. */
256
257 bool
258 gfc_post_options (const char **pfilename)
259 {
260 const char *filename = *pfilename, *canon_source_file = NULL;
261 char *source_path;
262 int i;
263
264 /* Excess precision other than "fast" requires front-end
265 support. */
266 if (flag_excess_precision_cmdline == EXCESS_PRECISION_STANDARD
267 && TARGET_FLT_EVAL_METHOD_NON_DEFAULT)
268 sorry ("-fexcess-precision=standard for Fortran");
269 flag_excess_precision_cmdline = EXCESS_PRECISION_FAST;
270
271 /* Fortran allows associative math - but we cannot reassociate if
272 we want traps or signed zeros. Cf. also flag_protect_parens. */
273 if (flag_associative_math == -1)
274 flag_associative_math = (!flag_trapping_math && !flag_signed_zeros);
275
276 if (gfc_option.flag_protect_parens == -1)
277 gfc_option.flag_protect_parens = !optimize_fast;
278
279 if (gfc_option.flag_stack_arrays == -1)
280 gfc_option.flag_stack_arrays = optimize_fast;
281
282 /* By default, disable (re)allocation during assignment for -std=f95,
283 and enable it for F2003/F2008/GNU/Legacy. */
284 if (gfc_option.flag_realloc_lhs == -1)
285 {
286 if (gfc_option.allow_std & GFC_STD_F2003)
287 gfc_option.flag_realloc_lhs = 1;
288 else
289 gfc_option.flag_realloc_lhs = 0;
290 }
291
292 /* -fbounds-check is equivalent to -fcheck=bounds */
293 if (flag_bounds_check)
294 gfc_option.rtcheck |= GFC_RTCHECK_BOUNDS;
295
296 if (flag_compare_debug)
297 gfc_option.dump_fortran_original = 0;
298
299 /* Make -fmax-errors visible to gfortran's diagnostic machinery. */
300 if (global_options_set.x_flag_max_errors)
301 gfc_option.max_errors = flag_max_errors;
302
303 /* Verify the input file name. */
304 if (!filename || strcmp (filename, "-") == 0)
305 {
306 filename = "";
307 }
308
309 if (gfc_option.flag_preprocessed)
310 {
311 /* For preprocessed files, if the first tokens are of the form # NUM.
312 handle the directives so we know the original file name. */
313 gfc_source_file = gfc_read_orig_filename (filename, &canon_source_file);
314 if (gfc_source_file == NULL)
315 gfc_source_file = filename;
316 else
317 *pfilename = gfc_source_file;
318 }
319 else
320 gfc_source_file = filename;
321
322 if (canon_source_file == NULL)
323 canon_source_file = gfc_source_file;
324
325 /* Adds the path where the source file is to the list of include files. */
326
327 i = strlen (canon_source_file);
328 while (i > 0 && !IS_DIR_SEPARATOR (canon_source_file[i]))
329 i--;
330
331 if (i != 0)
332 {
333 source_path = (char *) alloca (i + 1);
334 memcpy (source_path, canon_source_file, i);
335 source_path[i] = 0;
336 gfc_add_include_path (source_path, true, true, true);
337 }
338 else
339 gfc_add_include_path (".", true, true, true);
340
341 if (canon_source_file != gfc_source_file)
342 free (CONST_CAST (char *, canon_source_file));
343
344 /* Decide which form the file will be read in as. */
345
346 if (gfc_option.source_form != FORM_UNKNOWN)
347 gfc_current_form = gfc_option.source_form;
348 else
349 {
350 gfc_current_form = form_from_filename (filename);
351
352 if (gfc_current_form == FORM_UNKNOWN)
353 {
354 gfc_current_form = FORM_FREE;
355 gfc_warning_now ("Reading file '%s' as free form",
356 (filename[0] == '\0') ? "<stdin>" : filename);
357 }
358 }
359
360 /* If the user specified -fd-lines-as-{code|comments} verify that we're
361 in fixed form. */
362 if (gfc_current_form == FORM_FREE)
363 {
364 if (gfc_option.flag_d_lines == 0)
365 gfc_warning_now ("'-fd-lines-as-comments' has no effect "
366 "in free form");
367 else if (gfc_option.flag_d_lines == 1)
368 gfc_warning_now ("'-fd-lines-as-code' has no effect in free form");
369 }
370
371 /* If -pedantic, warn about the use of GNU extensions. */
372 if (pedantic && (gfc_option.allow_std & GFC_STD_GNU) != 0)
373 gfc_option.warn_std |= GFC_STD_GNU;
374 /* -std=legacy -pedantic is effectively -std=gnu. */
375 if (pedantic && (gfc_option.allow_std & GFC_STD_LEGACY) != 0)
376 gfc_option.warn_std |= GFC_STD_F95_OBS | GFC_STD_F95_DEL | GFC_STD_LEGACY;
377
378 /* If the user didn't explicitly specify -f(no)-second-underscore we
379 use it if we're trying to be compatible with f2c, and not
380 otherwise. */
381 if (gfc_option.flag_second_underscore == -1)
382 gfc_option.flag_second_underscore = gfc_option.flag_f2c;
383
384 if (!gfc_option.flag_automatic && gfc_option.flag_max_stack_var_size != -2
385 && gfc_option.flag_max_stack_var_size != 0)
386 gfc_warning_now ("Flag -fno-automatic overwrites -fmax-stack-var-size=%d",
387 gfc_option.flag_max_stack_var_size);
388 else if (!gfc_option.flag_automatic && gfc_option.flag_recursive)
389 gfc_warning_now ("Flag -fno-automatic overwrites -frecursive");
390 else if (!gfc_option.flag_automatic && gfc_option.gfc_flag_openmp)
391 gfc_warning_now ("Flag -fno-automatic overwrites -frecursive implied by "
392 "-fopenmp");
393 else if (gfc_option.flag_max_stack_var_size != -2
394 && gfc_option.flag_recursive)
395 gfc_warning_now ("Flag -frecursive overwrites -fmax-stack-var-size=%d",
396 gfc_option.flag_max_stack_var_size);
397 else if (gfc_option.flag_max_stack_var_size != -2
398 && gfc_option.gfc_flag_openmp)
399 gfc_warning_now ("Flag -fmax-stack-var-size=%d overwrites -frecursive "
400 "implied by -fopenmp",
401 gfc_option.flag_max_stack_var_size);
402
403 /* Implement -frecursive as -fmax-stack-var-size=-1. */
404 if (gfc_option.flag_recursive)
405 gfc_option.flag_max_stack_var_size = -1;
406
407 /* Implied -frecursive; implemented as -fmax-stack-var-size=-1. */
408 if (gfc_option.flag_max_stack_var_size == -2 && gfc_option.gfc_flag_openmp
409 && gfc_option.flag_automatic)
410 {
411 gfc_option.flag_recursive = 1;
412 gfc_option.flag_max_stack_var_size = -1;
413 }
414
415 /* Set default. */
416 if (gfc_option.flag_max_stack_var_size == -2)
417 gfc_option.flag_max_stack_var_size = 32768;
418
419 /* Implement -fno-automatic as -fmax-stack-var-size=0. */
420 if (!gfc_option.flag_automatic)
421 gfc_option.flag_max_stack_var_size = 0;
422
423 if (pedantic)
424 {
425 gfc_option.warn_ampersand = 1;
426 gfc_option.warn_tabs = 0;
427 }
428
429 /* Optimization implies front end optimization, unless the user
430 specified it directly. */
431
432 if (gfc_option.flag_frontend_optimize == -1)
433 gfc_option.flag_frontend_optimize = optimize;
434
435 if (gfc_option.warn_realloc_lhs_all)
436 gfc_option.warn_realloc_lhs = 1;
437
438 gfc_cpp_post_options ();
439
440 return gfc_cpp_preprocess_only ();
441 }
442
443
444 /* Set the options for -Wall. */
445
446 static void
447 set_Wall (int setting)
448 {
449 gfc_option.warn_aliasing = setting;
450 gfc_option.warn_ampersand = setting;
451 gfc_option.warn_c_binding_type = setting;
452 gfc_option.gfc_warn_conversion = setting;
453 gfc_option.warn_line_truncation = setting;
454 gfc_option.warn_surprising = setting;
455 gfc_option.warn_tabs = !setting;
456 gfc_option.warn_underflow = setting;
457 gfc_option.warn_intrinsic_shadow = setting;
458 gfc_option.warn_intrinsics_std = setting;
459 gfc_option.warn_character_truncation = setting;
460 gfc_option.warn_real_q_constant = setting;
461 gfc_option.warn_unused_dummy_argument = setting;
462 gfc_option.warn_target_lifetime = setting;
463 gfc_option.warn_zerotrip = setting;
464
465 warn_return_type = setting;
466 warn_uninitialized = setting;
467 warn_maybe_uninitialized = setting;
468 }
469
470 /* Set the options for -Wextra. */
471
472 static void
473 set_Wextra (int setting)
474 {
475 gfc_option.warn_compare_reals = setting;
476 }
477
478 static void
479 gfc_handle_module_path_options (const char *arg)
480 {
481
482 if (gfc_option.module_dir != NULL)
483 gfc_fatal_error ("gfortran: Only one -J option allowed");
484
485 gfc_option.module_dir = XCNEWVEC (char, strlen (arg) + 2);
486 strcpy (gfc_option.module_dir, arg);
487
488 gfc_add_include_path (gfc_option.module_dir, true, false, true);
489
490 strcat (gfc_option.module_dir, "/");
491 }
492
493
494 /* Handle options -ffpe-trap= and -ffpe-summary=. */
495
496 static void
497 gfc_handle_fpe_option (const char *arg, bool trap)
498 {
499 int result, pos = 0, n;
500 /* precision is a backwards compatibility alias for inexact. */
501 static const char * const exception[] = { "invalid", "denormal", "zero",
502 "overflow", "underflow",
503 "inexact", "precision", NULL };
504 static const int opt_exception[] = { GFC_FPE_INVALID, GFC_FPE_DENORMAL,
505 GFC_FPE_ZERO, GFC_FPE_OVERFLOW,
506 GFC_FPE_UNDERFLOW, GFC_FPE_INEXACT,
507 GFC_FPE_INEXACT,
508 0 };
509
510 /* As the default for -ffpe-summary= is nonzero, set it to 0. */
511 if (!trap)
512 gfc_option.fpe_summary = 0;
513
514 while (*arg)
515 {
516 while (*arg == ',')
517 arg++;
518
519 while (arg[pos] && arg[pos] != ',')
520 pos++;
521
522 result = 0;
523 if (!trap && strncmp ("none", arg, pos) == 0)
524 {
525 gfc_option.fpe_summary = 0;
526 arg += pos;
527 pos = 0;
528 continue;
529 }
530 else if (!trap && strncmp ("all", arg, pos) == 0)
531 {
532 gfc_option.fpe_summary = GFC_FPE_INVALID | GFC_FPE_DENORMAL
533 | GFC_FPE_ZERO | GFC_FPE_OVERFLOW
534 | GFC_FPE_UNDERFLOW | GFC_FPE_INEXACT;
535 arg += pos;
536 pos = 0;
537 continue;
538 }
539 else
540 for (n = 0; exception[n] != NULL; n++)
541 {
542 if (exception[n] && strncmp (exception[n], arg, pos) == 0)
543 {
544 if (trap)
545 gfc_option.fpe |= opt_exception[n];
546 else
547 gfc_option.fpe_summary |= opt_exception[n];
548 arg += pos;
549 pos = 0;
550 result = 1;
551 break;
552 }
553 }
554 if (!result && !trap)
555 gfc_fatal_error ("Argument to -ffpe-trap is not valid: %s", arg);
556 else if (!result)
557 gfc_fatal_error ("Argument to -ffpe-summary is not valid: %s", arg);
558
559 }
560 }
561
562
563 static void
564 gfc_handle_coarray_option (const char *arg)
565 {
566 if (strcmp (arg, "none") == 0)
567 gfc_option.coarray = GFC_FCOARRAY_NONE;
568 else if (strcmp (arg, "single") == 0)
569 gfc_option.coarray = GFC_FCOARRAY_SINGLE;
570 else if (strcmp (arg, "lib") == 0)
571 gfc_option.coarray = GFC_FCOARRAY_LIB;
572 else
573 gfc_fatal_error ("Argument to -fcoarray is not valid: %s", arg);
574 }
575
576
577 static void
578 gfc_handle_runtime_check_option (const char *arg)
579 {
580 int result, pos = 0, n;
581 static const char * const optname[] = { "all", "bounds", "array-temps",
582 "recursion", "do", "pointer",
583 "mem", NULL };
584 static const int optmask[] = { GFC_RTCHECK_ALL, GFC_RTCHECK_BOUNDS,
585 GFC_RTCHECK_ARRAY_TEMPS,
586 GFC_RTCHECK_RECURSION, GFC_RTCHECK_DO,
587 GFC_RTCHECK_POINTER, GFC_RTCHECK_MEM,
588 0 };
589
590 while (*arg)
591 {
592 while (*arg == ',')
593 arg++;
594
595 while (arg[pos] && arg[pos] != ',')
596 pos++;
597
598 result = 0;
599 for (n = 0; optname[n] != NULL; n++)
600 {
601 if (optname[n] && strncmp (optname[n], arg, pos) == 0)
602 {
603 gfc_option.rtcheck |= optmask[n];
604 arg += pos;
605 pos = 0;
606 result = 1;
607 break;
608 }
609 }
610 if (!result)
611 gfc_fatal_error ("Argument to -fcheck is not valid: %s", arg);
612 }
613 }
614
615
616 /* Handle command-line options. Returns 0 if unrecognized, 1 if
617 recognized and handled. */
618
619 bool
620 gfc_handle_option (size_t scode, const char *arg, int value,
621 int kind ATTRIBUTE_UNUSED, location_t loc ATTRIBUTE_UNUSED,
622 const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED)
623 {
624 bool result = true;
625 enum opt_code code = (enum opt_code) scode;
626
627 if (gfc_cpp_handle_option (scode, arg, value) == 1)
628 return true;
629
630 switch (code)
631 {
632 default:
633 result = false;
634 break;
635
636 case OPT_Wall:
637 handle_generated_option (&global_options, &global_options_set,
638 OPT_Wunused, NULL, value,
639 gfc_option_lang_mask (), kind, loc,
640 handlers, global_dc);
641 set_Wall (value);
642 break;
643
644 case OPT_Waliasing:
645 gfc_option.warn_aliasing = value;
646 break;
647
648 case OPT_Wampersand:
649 gfc_option.warn_ampersand = value;
650 break;
651
652 case OPT_Warray_temporaries:
653 gfc_option.warn_array_temp = value;
654 break;
655
656 case OPT_Wc_binding_type:
657 gfc_option.warn_c_binding_type = value;
658 break;
659
660 case OPT_Wcharacter_truncation:
661 gfc_option.warn_character_truncation = value;
662 break;
663
664 case OPT_Wcompare_reals:
665 gfc_option.warn_compare_reals = value;
666 break;
667
668 case OPT_Wconversion:
669 gfc_option.gfc_warn_conversion = value;
670 break;
671
672 case OPT_Wconversion_extra:
673 gfc_option.warn_conversion_extra = value;
674 break;
675
676 case OPT_Wextra:
677 handle_generated_option (&global_options, &global_options_set,
678 OPT_Wunused_parameter, NULL, value,
679 gfc_option_lang_mask (), kind, loc,
680 handlers, global_dc);
681 set_Wextra (value);
682
683 break;
684
685 case OPT_Wfunction_elimination:
686 gfc_option.warn_function_elimination = value;
687 break;
688
689 case OPT_Wimplicit_interface:
690 gfc_option.warn_implicit_interface = value;
691 break;
692
693 case OPT_Wimplicit_procedure:
694 gfc_option.warn_implicit_procedure = value;
695 break;
696
697 case OPT_Wline_truncation:
698 gfc_option.warn_line_truncation = value;
699 break;
700
701 case OPT_Wrealloc_lhs:
702 gfc_option.warn_realloc_lhs = value;
703 break;
704
705 case OPT_Wrealloc_lhs_all:
706 gfc_option.warn_realloc_lhs_all = value;
707 break;
708
709 case OPT_Wreturn_type:
710 warn_return_type = value;
711 break;
712
713 case OPT_Wsurprising:
714 gfc_option.warn_surprising = value;
715 break;
716
717 case OPT_Wtabs:
718 gfc_option.warn_tabs = value;
719 break;
720
721 case OPT_Wtarget_lifetime:
722 gfc_option.warn_target_lifetime = value;
723 break;
724
725 case OPT_Wunderflow:
726 gfc_option.warn_underflow = value;
727 break;
728
729 case OPT_Wintrinsic_shadow:
730 gfc_option.warn_intrinsic_shadow = value;
731 break;
732
733 case OPT_Walign_commons:
734 gfc_option.warn_align_commons = value;
735 break;
736
737 case OPT_Wreal_q_constant:
738 gfc_option.warn_real_q_constant = value;
739 break;
740
741 case OPT_Wunused_dummy_argument:
742 gfc_option.warn_unused_dummy_argument = value;
743 break;
744
745 case OPT_Wzerotrip:
746 gfc_option.warn_zerotrip = value;
747 break;
748
749 case OPT_fall_intrinsics:
750 gfc_option.flag_all_intrinsics = 1;
751 break;
752
753 case OPT_fautomatic:
754 gfc_option.flag_automatic = value;
755 break;
756
757 case OPT_fallow_leading_underscore:
758 gfc_option.flag_allow_leading_underscore = value;
759 break;
760
761 case OPT_fbackslash:
762 gfc_option.flag_backslash = value;
763 break;
764
765 case OPT_fbacktrace:
766 gfc_option.flag_backtrace = value;
767 break;
768
769 case OPT_fcheck_array_temporaries:
770 gfc_option.rtcheck |= GFC_RTCHECK_ARRAY_TEMPS;
771 break;
772
773 case OPT_fcray_pointer:
774 gfc_option.flag_cray_pointer = value;
775 break;
776
777 case OPT_ff2c:
778 gfc_option.flag_f2c = value;
779 break;
780
781 case OPT_fdollar_ok:
782 gfc_option.flag_dollar_ok = value;
783 break;
784
785 case OPT_fexternal_blas:
786 gfc_option.flag_external_blas = value;
787 break;
788
789 case OPT_fblas_matmul_limit_:
790 gfc_option.blas_matmul_limit = value;
791 break;
792
793 case OPT_fd_lines_as_code:
794 gfc_option.flag_d_lines = 1;
795 break;
796
797 case OPT_fd_lines_as_comments:
798 gfc_option.flag_d_lines = 0;
799 break;
800
801 case OPT_fdump_fortran_original:
802 case OPT_fdump_parse_tree:
803 gfc_option.dump_fortran_original = value;
804 break;
805
806 case OPT_fdump_fortran_optimized:
807 gfc_option.dump_fortran_optimized = value;
808 break;
809
810 case OPT_ffixed_form:
811 gfc_option.source_form = FORM_FIXED;
812 break;
813
814 case OPT_ffixed_line_length_none:
815 gfc_option.fixed_line_length = 0;
816 break;
817
818 case OPT_ffixed_line_length_:
819 if (value != 0 && value < 7)
820 gfc_fatal_error ("Fixed line length must be at least seven.");
821 gfc_option.fixed_line_length = value;
822 break;
823
824 case OPT_ffree_form:
825 gfc_option.source_form = FORM_FREE;
826 break;
827
828 case OPT_fopenmp:
829 gfc_option.gfc_flag_openmp = value;
830 break;
831
832 case OPT_fopenmp_simd:
833 gfc_option.gfc_flag_openmp_simd = value;
834 break;
835
836 case OPT_ffree_line_length_none:
837 gfc_option.free_line_length = 0;
838 break;
839
840 case OPT_ffree_line_length_:
841 if (value != 0 && value < 4)
842 gfc_fatal_error ("Free line length must be at least three.");
843 gfc_option.free_line_length = value;
844 break;
845
846 case OPT_funderscoring:
847 gfc_option.flag_underscoring = value;
848 break;
849
850 case OPT_fsecond_underscore:
851 gfc_option.flag_second_underscore = value;
852 break;
853
854 case OPT_static_libgfortran:
855 #ifndef HAVE_LD_STATIC_DYNAMIC
856 gfc_fatal_error ("-static-libgfortran is not supported in this "
857 "configuration");
858 #endif
859 break;
860
861 case OPT_fimplicit_none:
862 gfc_option.flag_implicit_none = value;
863 break;
864
865 case OPT_fintrinsic_modules_path:
866 case OPT_fintrinsic_modules_path_:
867
868 /* This is needed because omp_lib.h is in a directory together
869 with intrinsic modules. Do no warn because during testing
870 without an installed compiler, we would get lots of bogus
871 warnings for a missing include directory. */
872 gfc_add_include_path (arg, false, false, false);
873
874 gfc_add_intrinsic_modules_path (arg);
875 break;
876
877 case OPT_fmax_array_constructor_:
878 gfc_option.flag_max_array_constructor = value > 65535 ? value : 65535;
879 break;
880
881 case OPT_fmax_stack_var_size_:
882 gfc_option.flag_max_stack_var_size = value;
883 break;
884
885 case OPT_fstack_arrays:
886 gfc_option.flag_stack_arrays = value;
887 break;
888
889 case OPT_fmodule_private:
890 gfc_option.flag_module_private = value;
891 break;
892
893 case OPT_frange_check:
894 gfc_option.flag_range_check = value;
895 break;
896
897 case OPT_fpack_derived:
898 gfc_option.flag_pack_derived = value;
899 break;
900
901 case OPT_frepack_arrays:
902 gfc_option.flag_repack_arrays = value;
903 break;
904
905 case OPT_fpreprocessed:
906 gfc_option.flag_preprocessed = value;
907 break;
908
909 case OPT_fmax_identifier_length_:
910 if (value > GFC_MAX_SYMBOL_LEN)
911 gfc_fatal_error ("Maximum supported identifier length is %d",
912 GFC_MAX_SYMBOL_LEN);
913 gfc_option.max_identifier_length = value;
914 break;
915
916 case OPT_fdefault_integer_8:
917 gfc_option.flag_default_integer = value;
918 break;
919
920 case OPT_fdefault_real_8:
921 gfc_option.flag_default_real = value;
922 break;
923
924 case OPT_fdefault_double_8:
925 gfc_option.flag_default_double = value;
926 break;
927
928 case OPT_finteger_4_integer_8:
929 gfc_option.flag_integer4_kind = 8;
930 break;
931
932 case OPT_freal_4_real_8:
933 gfc_option.flag_real4_kind = 8;
934 break;
935
936 case OPT_freal_4_real_10:
937 gfc_option.flag_real4_kind = 10;
938 break;
939
940 case OPT_freal_4_real_16:
941 gfc_option.flag_real4_kind = 16;
942 break;
943
944 case OPT_freal_8_real_4:
945 gfc_option.flag_real8_kind = 4;
946 break;
947
948 case OPT_freal_8_real_10:
949 gfc_option.flag_real8_kind = 10;
950 break;
951
952 case OPT_freal_8_real_16:
953 gfc_option.flag_real8_kind = 16;
954 break;
955
956 case OPT_finit_local_zero:
957 gfc_option.flag_init_integer = GFC_INIT_INTEGER_ON;
958 gfc_option.flag_init_integer_value = 0;
959 gfc_option.flag_init_real = GFC_INIT_REAL_ZERO;
960 gfc_option.flag_init_logical = GFC_INIT_LOGICAL_FALSE;
961 gfc_option.flag_init_character = GFC_INIT_CHARACTER_ON;
962 gfc_option.flag_init_character_value = (char)0;
963 break;
964
965 case OPT_finit_logical_:
966 if (!strcasecmp (arg, "false"))
967 gfc_option.flag_init_logical = GFC_INIT_LOGICAL_FALSE;
968 else if (!strcasecmp (arg, "true"))
969 gfc_option.flag_init_logical = GFC_INIT_LOGICAL_TRUE;
970 else
971 gfc_fatal_error ("Unrecognized option to -finit-logical: %s",
972 arg);
973 break;
974
975 case OPT_finit_real_:
976 if (!strcasecmp (arg, "zero"))
977 gfc_option.flag_init_real = GFC_INIT_REAL_ZERO;
978 else if (!strcasecmp (arg, "nan"))
979 gfc_option.flag_init_real = GFC_INIT_REAL_NAN;
980 else if (!strcasecmp (arg, "snan"))
981 gfc_option.flag_init_real = GFC_INIT_REAL_SNAN;
982 else if (!strcasecmp (arg, "inf"))
983 gfc_option.flag_init_real = GFC_INIT_REAL_INF;
984 else if (!strcasecmp (arg, "-inf"))
985 gfc_option.flag_init_real = GFC_INIT_REAL_NEG_INF;
986 else
987 gfc_fatal_error ("Unrecognized option to -finit-real: %s",
988 arg);
989 break;
990
991 case OPT_finit_integer_:
992 gfc_option.flag_init_integer = GFC_INIT_INTEGER_ON;
993 gfc_option.flag_init_integer_value = atoi (arg);
994 break;
995
996 case OPT_finit_character_:
997 if (value >= 0 && value <= 127)
998 {
999 gfc_option.flag_init_character = GFC_INIT_CHARACTER_ON;
1000 gfc_option.flag_init_character_value = (char)value;
1001 }
1002 else
1003 gfc_fatal_error ("The value of n in -finit-character=n must be "
1004 "between 0 and 127");
1005 break;
1006
1007 case OPT_I:
1008 gfc_add_include_path (arg, true, false, true);
1009 break;
1010
1011 case OPT_J:
1012 gfc_handle_module_path_options (arg);
1013 break;
1014
1015 case OPT_fsign_zero:
1016 gfc_option.flag_sign_zero = value;
1017 break;
1018
1019 case OPT_ffpe_trap_:
1020 gfc_handle_fpe_option (arg, true);
1021 break;
1022
1023 case OPT_ffpe_summary_:
1024 gfc_handle_fpe_option (arg, false);
1025 break;
1026
1027 case OPT_std_f95:
1028 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F95 | GFC_STD_F77
1029 | GFC_STD_F2008_OBS;
1030 gfc_option.warn_std = GFC_STD_F95_OBS;
1031 gfc_option.max_continue_fixed = 19;
1032 gfc_option.max_continue_free = 39;
1033 gfc_option.max_identifier_length = 31;
1034 gfc_option.warn_ampersand = 1;
1035 gfc_option.warn_tabs = 0;
1036 break;
1037
1038 case OPT_std_f2003:
1039 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F77
1040 | GFC_STD_F2003 | GFC_STD_F95 | GFC_STD_F2008_OBS;
1041 gfc_option.warn_std = GFC_STD_F95_OBS;
1042 gfc_option.max_identifier_length = 63;
1043 gfc_option.warn_ampersand = 1;
1044 gfc_option.warn_tabs = 0;
1045 break;
1046
1047 case OPT_std_f2008:
1048 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F77
1049 | GFC_STD_F2003 | GFC_STD_F95 | GFC_STD_F2008 | GFC_STD_F2008_OBS;
1050 gfc_option.warn_std = GFC_STD_F95_OBS | GFC_STD_F2008_OBS;
1051 gfc_option.max_identifier_length = 63;
1052 gfc_option.warn_ampersand = 1;
1053 gfc_option.warn_tabs = 0;
1054 break;
1055
1056 case OPT_std_f2008ts:
1057 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F77
1058 | GFC_STD_F2003 | GFC_STD_F95 | GFC_STD_F2008 | GFC_STD_F2008_OBS
1059 | GFC_STD_F2008_TS;
1060 gfc_option.warn_std = GFC_STD_F95_OBS | GFC_STD_F2008_OBS;
1061 gfc_option.max_identifier_length = 63;
1062 gfc_option.warn_ampersand = 1;
1063 gfc_option.warn_tabs = 0;
1064 break;
1065
1066 case OPT_std_gnu:
1067 set_default_std_flags ();
1068 break;
1069
1070 case OPT_std_legacy:
1071 set_default_std_flags ();
1072 gfc_option.warn_std = 0;
1073 break;
1074
1075 case OPT_Wintrinsics_std:
1076 gfc_option.warn_intrinsics_std = value;
1077 break;
1078
1079 case OPT_fshort_enums:
1080 /* Handled in language-independent code. */
1081 break;
1082
1083 case OPT_fconvert_little_endian:
1084 gfc_option.convert = GFC_CONVERT_LITTLE;
1085 break;
1086
1087 case OPT_fconvert_big_endian:
1088 gfc_option.convert = GFC_CONVERT_BIG;
1089 break;
1090
1091 case OPT_fconvert_native:
1092 gfc_option.convert = GFC_CONVERT_NATIVE;
1093 break;
1094
1095 case OPT_fconvert_swap:
1096 gfc_option.convert = GFC_CONVERT_SWAP;
1097 break;
1098
1099 case OPT_frecord_marker_4:
1100 gfc_option.record_marker = 4;
1101 break;
1102
1103 case OPT_frecord_marker_8:
1104 gfc_option.record_marker = 8;
1105 break;
1106
1107 case OPT_fmax_subrecord_length_:
1108 if (value > MAX_SUBRECORD_LENGTH)
1109 gfc_fatal_error ("Maximum subrecord length cannot exceed %d",
1110 MAX_SUBRECORD_LENGTH);
1111
1112 gfc_option.max_subrecord_length = value;
1113 break;
1114
1115 case OPT_frecursive:
1116 gfc_option.flag_recursive = value;
1117 break;
1118
1119 case OPT_falign_commons:
1120 gfc_option.flag_align_commons = value;
1121 break;
1122
1123 case OPT_faggressive_function_elimination:
1124 gfc_option.flag_aggressive_function_elimination = value;
1125 break;
1126
1127 case OPT_ffrontend_optimize:
1128 gfc_option.flag_frontend_optimize = value;
1129 break;
1130
1131 case OPT_fprotect_parens:
1132 gfc_option.flag_protect_parens = value;
1133 break;
1134
1135 case OPT_frealloc_lhs:
1136 gfc_option.flag_realloc_lhs = value;
1137 break;
1138
1139 case OPT_fcheck_:
1140 gfc_handle_runtime_check_option (arg);
1141 break;
1142
1143 case OPT_fcoarray_:
1144 gfc_handle_coarray_option (arg);
1145 break;
1146 }
1147
1148 Fortran_handle_option_auto (&global_options, &global_options_set,
1149 scode, arg, value,
1150 gfc_option_lang_mask (), kind,
1151 loc, handlers, global_dc);
1152 return result;
1153 }
1154
1155
1156 /* Return a string with the options passed to the compiler; used for
1157 Fortran's compiler_options() intrinsic. */
1158
1159 char *
1160 gfc_get_option_string (void)
1161 {
1162 unsigned j;
1163 size_t len, pos;
1164 char *result;
1165
1166 /* Allocate and return a one-character string with '\0'. */
1167 if (!save_decoded_options_count)
1168 return XCNEWVEC (char, 1);
1169
1170 /* Determine required string length. */
1171
1172 len = 0;
1173 for (j = 1; j < save_decoded_options_count; j++)
1174 {
1175 switch (save_decoded_options[j].opt_index)
1176 {
1177 case OPT_o:
1178 case OPT_d:
1179 case OPT_dumpbase:
1180 case OPT_dumpdir:
1181 case OPT_auxbase:
1182 case OPT_quiet:
1183 case OPT_version:
1184 case OPT_fintrinsic_modules_path:
1185 case OPT_fintrinsic_modules_path_:
1186 /* Ignore these. */
1187 break;
1188 default:
1189 /* Ignore file names. */
1190 if (save_decoded_options[j].orig_option_with_args_text[0] == '-')
1191 len += 1
1192 + strlen (save_decoded_options[j].orig_option_with_args_text);
1193 }
1194 }
1195
1196 result = XCNEWVEC (char, len);
1197
1198 pos = 0;
1199 for (j = 1; j < save_decoded_options_count; j++)
1200 {
1201 switch (save_decoded_options[j].opt_index)
1202 {
1203 case OPT_o:
1204 case OPT_d:
1205 case OPT_dumpbase:
1206 case OPT_dumpdir:
1207 case OPT_auxbase:
1208 case OPT_quiet:
1209 case OPT_version:
1210 case OPT_fintrinsic_modules_path:
1211 case OPT_fintrinsic_modules_path_:
1212 /* Ignore these. */
1213 continue;
1214
1215 case OPT_cpp_:
1216 /* Use "-cpp" rather than "-cpp=<temporary file>". */
1217 len = 4;
1218 break;
1219
1220 default:
1221 /* Ignore file names. */
1222 if (save_decoded_options[j].orig_option_with_args_text[0] != '-')
1223 continue;
1224
1225 len = strlen (save_decoded_options[j].orig_option_with_args_text);
1226 }
1227
1228 memcpy (&result[pos], save_decoded_options[j].orig_option_with_args_text, len);
1229 pos += len;
1230 result[pos++] = ' ';
1231 }
1232
1233 result[--pos] = '\0';
1234 return result;
1235 }