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