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