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