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