]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/fortran/options.c
PR c++/85662
[thirdparty/gcc.git] / gcc / fortran / options.c
CommitLineData
4ee9c684 1/* Parse and display command line options.
8e8f6434 2 Copyright (C) 2000-2018 Free Software Foundation, Inc.
4ee9c684 3 Contributed by Andy Vaught
4
c84b470d 5This file is part of GCC.
4ee9c684 6
c84b470d 7GCC is free software; you can redistribute it and/or modify it under
8the terms of the GNU General Public License as published by the Free
bdabe786 9Software Foundation; either version 3, or (at your option) any later
c84b470d 10version.
4ee9c684 11
c84b470d 12GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13WARRANTY; without even the implied warranty of MERCHANTABILITY or
14FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15for more details.
4ee9c684 16
17You should have received a copy of the GNU General Public License
bdabe786 18along with GCC; see the file COPYING3. If not see
19<http://www.gnu.org/licenses/>. */
4ee9c684 20
4ee9c684 21#include "config.h"
22#include "system.h"
23#include "coretypes.h"
4cba6f60 24#include "target.h"
4ee9c684 25#include "tree.h"
4cba6f60 26#include "gfortran.h"
27#include "diagnostic.h" /* For global_dc. */
4ee9c684 28#include "opts.h"
e3d1ab2b 29#include "toplev.h" /* For save_decoded_options. */
2ecc6bc5 30#include "cpp.h"
f36f9b8b 31#include "langhooks.h"
4ee9c684 32
33gfc_option_t gfc_option;
34
35
83a65a0d 36/* Set flags that control warnings and errors for different
82860817 37 Fortran standards to their default values. Keep in sync with
38 libgfortran/runtime/compile_options.c (init_compile_options). */
83a65a0d 39
40static void
41set_default_std_flags (void)
42{
43 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F95_DEL
ff4425cf 44 | GFC_STD_F2003 | GFC_STD_F2008 | GFC_STD_F95 | GFC_STD_F77
003e134b 45 | GFC_STD_F2008_OBS | GFC_STD_F2008_TS | GFC_STD_GNU | GFC_STD_LEGACY
46 | GFC_STD_F2018 | GFC_STD_F2018_DEL | GFC_STD_F2018_OBS;
83a65a0d 47 gfc_option.warn_std = GFC_STD_F95_DEL | GFC_STD_LEGACY;
48}
49
82860817 50
cf078427 51/* Set all the DEC extension flags. */
d7cd448a 52
53static void
54set_dec_flags (int value)
55{
a3b89816 56 if (value)
57 {
58 /* Allow legacy code without warnings. */
59 gfc_option.allow_std |= GFC_STD_F95_OBS | GFC_STD_F95_DEL
60 | GFC_STD_GNU | GFC_STD_LEGACY;
61 gfc_option.warn_std &= ~(GFC_STD_LEGACY | GFC_STD_F95_DEL);
62 }
cf078427 63
64 /* Set other DEC compatibility extensions. */
65 flag_dollar_ok |= value;
66 flag_cray_pointer |= value;
67 flag_dec_structure |= value;
68 flag_dec_intrinsic_ints |= value;
69 flag_dec_static |= value;
70 flag_dec_math |= value;
d7cd448a 71}
72
73
e88d34f6 74/* Return language mask for Fortran options. */
75
76unsigned int
77gfc_option_lang_mask (void)
78{
79 return CL_Fortran;
80}
81
f3f006ad 82/* Initialize options structure OPTS. */
83
84void
85gfc_init_options_struct (struct gcc_options *opts)
86{
87 opts->x_flag_errno_math = 0;
a5b628e2 88 opts->frontend_set_flag_errno_math = true;
f3f006ad 89 opts->x_flag_associative_math = -1;
a5b628e2 90 opts->frontend_set_flag_associative_math = true;
f3f006ad 91}
e88d34f6 92
82860817 93/* Get ready for options handling. Keep in sync with
293d72e0 94 libgfortran/runtime/compile_options.c (init_compile_options). */
4ee9c684 95
e88d34f6 96void
97gfc_init_options (unsigned int decoded_options_count,
98 struct cl_decoded_option *decoded_options)
4ee9c684 99{
8594da07 100 gfc_source_file = NULL;
4ee9c684 101 gfc_option.module_dir = NULL;
102 gfc_option.source_form = FORM_UNKNOWN;
766398ac 103 gfc_option.max_continue_fixed = 255;
104 gfc_option.max_continue_free = 255;
4ee9c684 105 gfc_option.max_identifier_length = GFC_MAX_SYMBOL_LEN;
b6be0ac5 106 gfc_option.max_errors = 25;
4ee9c684 107
9e3a9b8b 108 gfc_option.flag_preprocessed = 0;
8594da07 109 gfc_option.flag_d_lines = -1;
a28eb9a8 110 gfc_option.flag_init_integer = GFC_INIT_INTEGER_OFF;
111 gfc_option.flag_init_integer_value = 0;
a28eb9a8 112 gfc_option.flag_init_logical = GFC_INIT_LOGICAL_OFF;
113 gfc_option.flag_init_character = GFC_INIT_CHARACTER_OFF;
114 gfc_option.flag_init_character_value = (char)0;
115
8c84a5de 116 gfc_option.fpe = 0;
553e7cef 117 /* All except GFC_FPE_INEXACT. */
118 gfc_option.fpe_summary = GFC_FPE_INVALID | GFC_FPE_DENORMAL
119 | GFC_FPE_ZERO | GFC_FPE_OVERFLOW
120 | GFC_FPE_UNDERFLOW;
ad8ed98e 121 gfc_option.rtcheck = 0;
8c84a5de 122
45e6f6f0 123 /* ??? Wmissing-include-dirs is disabled by default in C/C++ but
124 enabled by default in Fortran. Ideally, we should express this
125 in .opt, but that is not supported yet. */
126 if (!global_options_set.x_cpp_warn_missing_include_dirs)
7082509e 127 global_options.x_cpp_warn_missing_include_dirs = 1;
45e6f6f0 128
d7cd448a 129 set_dec_flags (0);
130
83a65a0d 131 set_default_std_flags ();
4ee9c684 132
2ecc6bc5 133 /* Initialize cpp-related options. */
e88d34f6 134 gfc_cpp_init_options (decoded_options_count, decoded_options);
dc8078a3 135 gfc_diagnostics_init ();
4ee9c684 136}
137
138
8594da07 139/* Determine the source form from the filename extension. We assume
140 case insensitivity. */
141
142static gfc_source_form
143form_from_filename (const char *filename)
144{
8594da07 145 static const struct
146 {
147 const char *extension;
148 gfc_source_form form;
149 }
150 exttype[] =
151 {
152 {
153 ".f90", FORM_FREE}
154 ,
155 {
156 ".f95", FORM_FREE}
157 ,
158 {
f30a3c31 159 ".f03", FORM_FREE}
160 ,
161 {
ff4425cf 162 ".f08", FORM_FREE}
163 ,
164 {
8594da07 165 ".f", FORM_FIXED}
166 ,
167 {
168 ".for", FORM_FIXED}
169 ,
170 {
ed19cf5f 171 ".ftn", FORM_FIXED}
172 ,
173 {
8594da07 174 "", FORM_UNKNOWN}
175 }; /* sentinel value */
176
177 gfc_source_form f_form;
178 const char *fileext;
179 int i;
180
181 /* Find end of file name. Note, filename is either a NULL pointer or
182 a NUL terminated string. */
183 i = 0;
184 while (filename[i] != '\0')
185 i++;
186
187 /* Find last period. */
188 while (i >= 0 && (filename[i] != '.'))
189 i--;
190
191 /* Did we see a file extension? */
192 if (i < 0)
193 return FORM_UNKNOWN; /* Nope */
194
195 /* Get file extension and compare it to others. */
196 fileext = &(filename[i]);
197
198 i = -1;
199 f_form = FORM_UNKNOWN;
200 do
201 {
202 i++;
203 if (strcasecmp (fileext, exttype[i].extension) == 0)
204 {
205 f_form = exttype[i].form;
206 break;
207 }
208 }
209 while (exttype[i].form != FORM_UNKNOWN);
210
211 return f_form;
212}
213
214
4ee9c684 215/* Finalize commandline options. */
216
217bool
218gfc_post_options (const char **pfilename)
219{
9e3a9b8b 220 const char *filename = *pfilename, *canon_source_file = NULL;
a0d72493 221 char *source_path;
222 int i;
4ee9c684 223
c6418a4e 224 /* Excess precision other than "fast" requires front-end
225 support. */
4267ed07 226 if (flag_excess_precision_cmdline == EXCESS_PRECISION_STANDARD)
c6418a4e 227 sorry ("-fexcess-precision=standard for Fortran");
228 flag_excess_precision_cmdline = EXCESS_PRECISION_FAST;
229
fb063c92 230 /* Fortran allows associative math - but we cannot reassociate if
231 we want traps or signed zeros. Cf. also flag_protect_parens. */
232 if (flag_associative_math == -1)
233 flag_associative_math = (!flag_trapping_math && !flag_signed_zeros);
234
eb106faf 235 if (flag_protect_parens == -1)
236 flag_protect_parens = !optimize_fast;
9d4ede2c 237
b254210f 238 /* -Ofast sets implies -fstack-arrays unless an explicit size is set for
239 stack arrays. */
240 if (flag_stack_arrays == -1 && flag_max_stack_var_size == -2)
eb106faf 241 flag_stack_arrays = optimize_fast;
9e412fd2 242
929c6f45 243 /* By default, disable (re)allocation during assignment for -std=f95,
293d72e0 244 and enable it for F2003/F2008/GNU/Legacy. */
eb106faf 245 if (flag_realloc_lhs == -1)
929c6f45 246 {
247 if (gfc_option.allow_std & GFC_STD_F2003)
eb106faf 248 flag_realloc_lhs = 1;
929c6f45 249 else
eb106faf 250 flag_realloc_lhs = 0;
929c6f45 251 }
252
ad8ed98e 253 /* -fbounds-check is equivalent to -fcheck=bounds */
254 if (flag_bounds_check)
255 gfc_option.rtcheck |= GFC_RTCHECK_BOUNDS;
256
71278019 257 if (flag_compare_debug)
829d7a08 258 flag_dump_fortran_original = 0;
71278019 259
566d7c74 260 /* Make -fmax-errors visible to gfortran's diagnostic machinery. */
261 if (global_options_set.x_flag_max_errors)
262 gfc_option.max_errors = flag_max_errors;
263
4ee9c684 264 /* Verify the input file name. */
265 if (!filename || strcmp (filename, "-") == 0)
266 {
267 filename = "";
268 }
269
9e3a9b8b 270 if (gfc_option.flag_preprocessed)
271 {
272 /* For preprocessed files, if the first tokens are of the form # NUM.
273 handle the directives so we know the original file name. */
274 gfc_source_file = gfc_read_orig_filename (filename, &canon_source_file);
275 if (gfc_source_file == NULL)
276 gfc_source_file = filename;
277 else
278 *pfilename = gfc_source_file;
279 }
280 else
281 gfc_source_file = filename;
282
283 if (canon_source_file == NULL)
284 canon_source_file = gfc_source_file;
8594da07 285
a0d72493 286 /* Adds the path where the source file is to the list of include files. */
287
9e3a9b8b 288 i = strlen (canon_source_file);
289 while (i > 0 && !IS_DIR_SEPARATOR (canon_source_file[i]))
a0d72493 290 i--;
1bcc6eb8 291
a0d72493 292 if (i != 0)
293 {
48d8ad5a 294 source_path = (char *) alloca (i + 1);
9e3a9b8b 295 memcpy (source_path, canon_source_file, i);
a0d72493 296 source_path[i] = 0;
db24420f 297 gfc_add_include_path (source_path, true, true, true);
a0d72493 298 }
299 else
db24420f 300 gfc_add_include_path (".", true, true, true);
a0d72493 301
9e3a9b8b 302 if (canon_source_file != gfc_source_file)
434f0922 303 free (CONST_CAST (char *, canon_source_file));
9e3a9b8b 304
8594da07 305 /* Decide which form the file will be read in as. */
306
307 if (gfc_option.source_form != FORM_UNKNOWN)
308 gfc_current_form = gfc_option.source_form;
309 else
310 {
311 gfc_current_form = form_from_filename (filename);
312
313 if (gfc_current_form == FORM_UNKNOWN)
314 {
315 gfc_current_form = FORM_FREE;
6f521718 316 gfc_warning_now (0, "Reading file %qs as free form",
bf79c656 317 (filename[0] == '\0') ? "<stdin>" : filename);
8594da07 318 }
319 }
320
321 /* If the user specified -fd-lines-as-{code|comments} verify that we're
322 in fixed form. */
323 if (gfc_current_form == FORM_FREE)
324 {
325 if (gfc_option.flag_d_lines == 0)
6f521718 326 gfc_warning_now (0, "%<-fd-lines-as-comments%> has no effect "
399c003f 327 "in free form");
8594da07 328 else if (gfc_option.flag_d_lines == 1)
6f521718 329 gfc_warning_now (0, "%<-fd-lines-as-code%> has no effect in free form");
bf1857ff 330
331 if (warn_line_truncation == -1)
332 warn_line_truncation = 1;
333
334 /* Enable -Werror=line-truncation when -Werror and -Wno-error have
335 not been set. */
336 if (warn_line_truncation && !global_options_set.x_warnings_are_errors
337 && (global_dc->classify_diagnostic[OPT_Wline_truncation] ==
338 DK_UNSPECIFIED))
339 diagnostic_classify_diagnostic (global_dc, OPT_Wline_truncation,
340 DK_ERROR, UNKNOWN_LOCATION);
8594da07 341 }
63256634 342 else
343 {
344 /* With -fdec, set -fd-lines-as-comments by default in fixed form. */
345 if (flag_dec && gfc_option.flag_d_lines == -1)
346 gfc_option.flag_d_lines = 0;
347
348 if (warn_line_truncation == -1)
349 warn_line_truncation = 0;
350 }
4ee9c684 351
675e3934 352 /* If -pedantic, warn about the use of GNU extensions. */
353 if (pedantic && (gfc_option.allow_std & GFC_STD_GNU) != 0)
354 gfc_option.warn_std |= GFC_STD_GNU;
c667e11d 355 /* -std=legacy -pedantic is effectively -std=gnu. */
356 if (pedantic && (gfc_option.allow_std & GFC_STD_LEGACY) != 0)
357 gfc_option.warn_std |= GFC_STD_F95_OBS | GFC_STD_F95_DEL | GFC_STD_LEGACY;
675e3934 358
bdaed7d2 359 /* If the user didn't explicitly specify -f(no)-second-underscore we
360 use it if we're trying to be compatible with f2c, and not
361 otherwise. */
eb106faf 362 if (flag_second_underscore == -1)
829d7a08 363 flag_second_underscore = flag_f2c;
bdaed7d2 364
829d7a08 365 if (!flag_automatic && flag_max_stack_var_size != -2
eb106faf 366 && flag_max_stack_var_size != 0)
6f521718 367 gfc_warning_now (0, "Flag %<-fno-automatic%> overwrites %<-fmax-stack-var-size=%d%>",
eb106faf 368 flag_max_stack_var_size);
829d7a08 369 else if (!flag_automatic && flag_recursive)
6f521718 370 gfc_warning_now (0, "Flag %<-fno-automatic%> overwrites %<-frecursive%>");
829d7a08 371 else if (!flag_automatic && flag_openmp)
6f521718 372 gfc_warning_now (0, "Flag %<-fno-automatic%> overwrites %<-frecursive%> implied by "
eb106faf 373 "%<-fopenmp%>");
829d7a08 374 else if (flag_max_stack_var_size != -2 && flag_recursive)
6f521718 375 gfc_warning_now (0, "Flag %<-frecursive%> overwrites %<-fmax-stack-var-size=%d%>",
eb106faf 376 flag_max_stack_var_size);
829d7a08 377 else if (flag_max_stack_var_size != -2 && flag_openmp)
6f521718 378 gfc_warning_now (0, "Flag %<-fmax-stack-var-size=%d%> overwrites %<-frecursive%> "
eb106faf 379 "implied by %<-fopenmp%>", flag_max_stack_var_size);
14af4f75 380
a7bdd774 381 /* Implement -frecursive as -fmax-stack-var-size=-1. */
829d7a08 382 if (flag_recursive)
eb106faf 383 flag_max_stack_var_size = -1;
14af4f75 384
a7bdd774 385 /* Implied -frecursive; implemented as -fmax-stack-var-size=-1. */
829d7a08 386 if (flag_max_stack_var_size == -2 && flag_openmp && flag_automatic)
a7bdd774 387 {
829d7a08 388 flag_recursive = 1;
eb106faf 389 flag_max_stack_var_size = -1;
a7bdd774 390 }
391
b254210f 392 /* Set flag_stack_arrays correctly. */
393 if (flag_stack_arrays == -1)
394 flag_stack_arrays = 0;
395
14af4f75 396 /* Set default. */
eb106faf 397 if (flag_max_stack_var_size == -2)
398 flag_max_stack_var_size = 32768;
14af4f75 399
7f2e183b 400 /* Implement -fno-automatic as -fmax-stack-var-size=0. */
829d7a08 401 if (!flag_automatic)
eb106faf 402 flag_max_stack_var_size = 0;
e27238e0 403
c23d681b 404 /* If the user did not specify an inline matmul limit, inline up to the BLAS
405 limit or up to 30 if no external BLAS is specified. */
08f351fd 406
c23d681b 407 if (flag_inline_matmul_limit < 0)
408 {
409 if (flag_external_blas)
410 flag_inline_matmul_limit = flag_blas_matmul_limit;
411 else
412 flag_inline_matmul_limit = 30;
413 }
08f351fd 414
10b2bb30 415 /* Optimization implies front end optimization, unless the user
416 specified it directly. */
417
eb106faf 418 if (flag_frontend_optimize == -1)
419 flag_frontend_optimize = optimize;
420
44319903 421 /* Same for front end loop interchange. */
422
423 if (flag_frontend_loop_interchange == -1)
424 flag_frontend_loop_interchange = optimize;
425
829d7a08 426 if (flag_max_array_constructor < 65535)
427 flag_max_array_constructor = 65535;
428
eb106faf 429 if (flag_fixed_line_length != 0 && flag_fixed_line_length < 7)
430 gfc_fatal_error ("Fixed line length must be at least seven");
431
432 if (flag_free_line_length != 0 && flag_free_line_length < 4)
433 gfc_fatal_error ("Free line length must be at least three");
434
435 if (flag_max_subrecord_length > MAX_SUBRECORD_LENGTH)
436 gfc_fatal_error ("Maximum subrecord length cannot exceed %d",
437 MAX_SUBRECORD_LENGTH);
10b2bb30 438
2ecc6bc5 439 gfc_cpp_post_options ();
440
f36f9b8b 441 if (gfc_option.allow_std & GFC_STD_F2008)
442 lang_hooks.name = "GNU Fortran2008";
443 else if (gfc_option.allow_std & GFC_STD_F2003)
444 lang_hooks.name = "GNU Fortran2003";
445
c7a63538 446 return gfc_cpp_preprocess_only ();
4ee9c684 447}
448
449
4ee9c684 450static void
451gfc_handle_module_path_options (const char *arg)
452{
453
454 if (gfc_option.module_dir != NULL)
c4facd47 455 gfc_fatal_error ("gfortran: Only one %<-J%> option allowed");
4ee9c684 456
dfa3fb6a 457 gfc_option.module_dir = XCNEWVEC (char, strlen (arg) + 2);
4ee9c684 458 strcpy (gfc_option.module_dir, arg);
3dc083ce 459
db24420f 460 gfc_add_include_path (gfc_option.module_dir, true, false, true);
e500aeee 461
462 strcat (gfc_option.module_dir, "/");
4ee9c684 463}
464
1bcc6eb8 465
553e7cef 466/* Handle options -ffpe-trap= and -ffpe-summary=. */
467
8c84a5de 468static void
553e7cef 469gfc_handle_fpe_option (const char *arg, bool trap)
8c84a5de 470{
471 int result, pos = 0, n;
98b28ab6 472 /* precision is a backwards compatibility alias for inexact. */
8c84a5de 473 static const char * const exception[] = { "invalid", "denormal", "zero",
1bcc6eb8 474 "overflow", "underflow",
98b28ab6 475 "inexact", "precision", NULL };
8c84a5de 476 static const int opt_exception[] = { GFC_FPE_INVALID, GFC_FPE_DENORMAL,
477 GFC_FPE_ZERO, GFC_FPE_OVERFLOW,
98b28ab6 478 GFC_FPE_UNDERFLOW, GFC_FPE_INEXACT,
479 GFC_FPE_INEXACT,
8c84a5de 480 0 };
553e7cef 481
293d72e0 482 /* As the default for -ffpe-summary= is nonzero, set it to 0. */
553e7cef 483 if (!trap)
484 gfc_option.fpe_summary = 0;
485
8c84a5de 486 while (*arg)
487 {
488 while (*arg == ',')
489 arg++;
1bcc6eb8 490
8c84a5de 491 while (arg[pos] && arg[pos] != ',')
492 pos++;
1bcc6eb8 493
8c84a5de 494 result = 0;
553e7cef 495 if (!trap && strncmp ("none", arg, pos) == 0)
8c84a5de 496 {
553e7cef 497 gfc_option.fpe_summary = 0;
498 arg += pos;
499 pos = 0;
500 continue;
501 }
502 else if (!trap && strncmp ("all", arg, pos) == 0)
503 {
504 gfc_option.fpe_summary = GFC_FPE_INVALID | GFC_FPE_DENORMAL
505 | GFC_FPE_ZERO | GFC_FPE_OVERFLOW
506 | GFC_FPE_UNDERFLOW | GFC_FPE_INEXACT;
507 arg += pos;
508 pos = 0;
509 continue;
510 }
511 else
512 for (n = 0; exception[n] != NULL; n++)
513 {
8c84a5de 514 if (exception[n] && strncmp (exception[n], arg, pos) == 0)
515 {
553e7cef 516 if (trap)
517 gfc_option.fpe |= opt_exception[n];
518 else
519 gfc_option.fpe_summary |= opt_exception[n];
8c84a5de 520 arg += pos;
521 pos = 0;
522 result = 1;
523 break;
524 }
553e7cef 525 }
526 if (!result && !trap)
c4facd47 527 gfc_fatal_error ("Argument to %<-ffpe-trap%> is not valid: %s", arg);
553e7cef 528 else if (!result)
c4facd47 529 gfc_fatal_error ("Argument to %<-ffpe-summary%> is not valid: %s", arg);
553e7cef 530
8c84a5de 531 }
532}
533
1bcc6eb8 534
ad8ed98e 535static void
536gfc_handle_runtime_check_option (const char *arg)
537{
538 int result, pos = 0, n;
539 static const char * const optname[] = { "all", "bounds", "array-temps",
3a60b071 540 "recursion", "do", "pointer",
541 "mem", NULL };
ad8ed98e 542 static const int optmask[] = { GFC_RTCHECK_ALL, GFC_RTCHECK_BOUNDS,
543 GFC_RTCHECK_ARRAY_TEMPS,
7f1bd03f 544 GFC_RTCHECK_RECURSION, GFC_RTCHECK_DO,
3a60b071 545 GFC_RTCHECK_POINTER, GFC_RTCHECK_MEM,
ad8ed98e 546 0 };
547
548 while (*arg)
549 {
550 while (*arg == ',')
551 arg++;
552
553 while (arg[pos] && arg[pos] != ',')
554 pos++;
555
556 result = 0;
557 for (n = 0; optname[n] != NULL; n++)
558 {
559 if (optname[n] && strncmp (optname[n], arg, pos) == 0)
560 {
561 gfc_option.rtcheck |= optmask[n];
562 arg += pos;
563 pos = 0;
564 result = 1;
565 break;
566 }
e7fbac94 567 else if (optname[n] && pos > 3 && strncmp ("no-", arg, 3) == 0
568 && strncmp (optname[n], arg+3, pos-3) == 0)
569 {
570 gfc_option.rtcheck &= ~optmask[n];
571 arg += pos;
572 pos = 0;
573 result = 1;
574 break;
575 }
ad8ed98e 576 }
577 if (!result)
c4facd47 578 gfc_fatal_error ("Argument to %<-fcheck%> is not valid: %s", arg);
ad8ed98e 579 }
580}
581
582
4ee9c684 583/* Handle command-line options. Returns 0 if unrecognized, 1 if
584 recognized and handled. */
1bcc6eb8 585
b78351e5 586bool
1f3db819 587gfc_handle_option (size_t scode, const char *arg, int value,
3c6c0e40 588 int kind ATTRIBUTE_UNUSED, location_t loc ATTRIBUTE_UNUSED,
b78351e5 589 const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED)
4ee9c684 590{
b78351e5 591 bool result = true;
4ee9c684 592 enum opt_code code = (enum opt_code) scode;
593
2ecc6bc5 594 if (gfc_cpp_handle_option (scode, arg, value) == 1)
b78351e5 595 return true;
2ecc6bc5 596
4ee9c684 597 switch (code)
598 {
599 default:
45e6f6f0 600 if (cl_options[code].flags & gfc_option_lang_mask ())
601 break;
b78351e5 602 result = false;
4ee9c684 603 break;
604
da6ffc6d 605 case OPT_fcheck_array_temporaries:
ad8ed98e 606 gfc_option.rtcheck |= GFC_RTCHECK_ARRAY_TEMPS;
da6ffc6d 607 break;
608
8594da07 609 case OPT_fd_lines_as_code:
610 gfc_option.flag_d_lines = 1;
611 break;
612
613 case OPT_fd_lines_as_comments:
614 gfc_option.flag_d_lines = 0;
615 break;
616
4ee9c684 617 case OPT_ffixed_form:
618 gfc_option.source_form = FORM_FIXED;
619 break;
620
621 case OPT_ffree_form:
622 gfc_option.source_form = FORM_FREE;
623 break;
624
9a61fba1 625 case OPT_static_libgfortran:
626#ifndef HAVE_LD_STATIC_DYNAMIC
c4facd47 627 gfc_fatal_error ("%<-static-libgfortran%> is not supported in this "
9a61fba1 628 "configuration");
629#endif
630 break;
631
99227731 632 case OPT_fintrinsic_modules_path:
7cb1cb52 633 case OPT_fintrinsic_modules_path_:
db24420f 634
635 /* This is needed because omp_lib.h is in a directory together
636 with intrinsic modules. Do no warn because during testing
637 without an installed compiler, we would get lots of bogus
638 warnings for a missing include directory. */
639 gfc_add_include_path (arg, false, false, false);
640
99227731 641 gfc_add_intrinsic_modules_path (arg);
642 break;
643
9e3a9b8b 644 case OPT_fpreprocessed:
645 gfc_option.flag_preprocessed = value;
646 break;
647
4ee9c684 648 case OPT_fmax_identifier_length_:
649 if (value > GFC_MAX_SYMBOL_LEN)
b71883de 650 gfc_fatal_error ("Maximum supported identifier length is %d",
4ee9c684 651 GFC_MAX_SYMBOL_LEN);
652 gfc_option.max_identifier_length = value;
653 break;
654
a28eb9a8 655 case OPT_finit_local_zero:
656 gfc_option.flag_init_integer = GFC_INIT_INTEGER_ON;
657 gfc_option.flag_init_integer_value = 0;
4fe73152 658 flag_init_real = GFC_INIT_REAL_ZERO;
a28eb9a8 659 gfc_option.flag_init_logical = GFC_INIT_LOGICAL_FALSE;
660 gfc_option.flag_init_character = GFC_INIT_CHARACTER_ON;
661 gfc_option.flag_init_character_value = (char)0;
662 break;
663
664 case OPT_finit_logical_:
665 if (!strcasecmp (arg, "false"))
666 gfc_option.flag_init_logical = GFC_INIT_LOGICAL_FALSE;
667 else if (!strcasecmp (arg, "true"))
668 gfc_option.flag_init_logical = GFC_INIT_LOGICAL_TRUE;
669 else
c4facd47 670 gfc_fatal_error ("Unrecognized option to %<-finit-logical%>: %s",
a28eb9a8 671 arg);
672 break;
673
a28eb9a8 674 case OPT_finit_integer_:
675 gfc_option.flag_init_integer = GFC_INIT_INTEGER_ON;
676 gfc_option.flag_init_integer_value = atoi (arg);
677 break;
678
679 case OPT_finit_character_:
680 if (value >= 0 && value <= 127)
681 {
682 gfc_option.flag_init_character = GFC_INIT_CHARACTER_ON;
683 gfc_option.flag_init_character_value = (char)value;
684 }
685 else
c4facd47 686 gfc_fatal_error ("The value of n in %<-finit-character=n%> must be "
a28eb9a8 687 "between 0 and 127");
688 break;
689
4ee9c684 690 case OPT_I:
db24420f 691 gfc_add_include_path (arg, true, false, true);
4ee9c684 692 break;
693
694 case OPT_J:
4ee9c684 695 gfc_handle_module_path_options (arg);
ca9ccc0d 696 break;
db96818c 697
8c84a5de 698 case OPT_ffpe_trap_:
553e7cef 699 gfc_handle_fpe_option (arg, true);
700 break;
701
702 case OPT_ffpe_summary_:
703 gfc_handle_fpe_option (arg, false);
8c84a5de 704 break;
705
4ee9c684 706 case OPT_std_f95:
a3b81b0f 707 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F95 | GFC_STD_F77
708 | GFC_STD_F2008_OBS;
4ee9c684 709 gfc_option.warn_std = GFC_STD_F95_OBS;
766398ac 710 gfc_option.max_continue_fixed = 19;
711 gfc_option.max_continue_free = 39;
4ee9c684 712 gfc_option.max_identifier_length = 31;
8290d53f 713 warn_ampersand = 1;
638664b8 714 warn_tabs = 1;
4ee9c684 715 break;
716
717 case OPT_std_f2003:
d6583a5f 718 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F77
a3b81b0f 719 | GFC_STD_F2003 | GFC_STD_F95 | GFC_STD_F2008_OBS;
d6583a5f 720 gfc_option.warn_std = GFC_STD_F95_OBS;
4ee9c684 721 gfc_option.max_identifier_length = 63;
8290d53f 722 warn_ampersand = 1;
638664b8 723 warn_tabs = 1;
4ee9c684 724 break;
725
ff4425cf 726 case OPT_std_f2008:
727 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F77
a3b81b0f 728 | GFC_STD_F2003 | GFC_STD_F95 | GFC_STD_F2008 | GFC_STD_F2008_OBS;
729 gfc_option.warn_std = GFC_STD_F95_OBS | GFC_STD_F2008_OBS;
ff4425cf 730 gfc_option.max_identifier_length = 63;
8290d53f 731 warn_ampersand = 1;
638664b8 732 warn_tabs = 1;
ff4425cf 733 break;
734
d976af8e 735 case OPT_std_f2008ts:
495e197c 736 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F77
737 | GFC_STD_F2003 | GFC_STD_F95 | GFC_STD_F2008 | GFC_STD_F2008_OBS
d976af8e 738 | GFC_STD_F2008_TS;
495e197c 739 gfc_option.warn_std = GFC_STD_F95_OBS | GFC_STD_F2008_OBS;
740 gfc_option.max_identifier_length = 63;
8290d53f 741 warn_ampersand = 1;
638664b8 742 warn_tabs = 1;
495e197c 743 break;
744
003e134b 745 case OPT_std_f2018:
746 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F77
747 | GFC_STD_F2003 | GFC_STD_F95 | GFC_STD_F2008 | GFC_STD_F2008_OBS
748 | GFC_STD_F2008_TS | GFC_STD_F2018 | GFC_STD_F2018_OBS;
749 gfc_option.warn_std = GFC_STD_F95_OBS | GFC_STD_F2008_OBS
750 | GFC_STD_F2018_OBS;
751 gfc_option.max_identifier_length = 63;
752 warn_ampersand = 1;
753 warn_tabs = 1;
754 break;
755
4ee9c684 756 case OPT_std_gnu:
83a65a0d 757 set_default_std_flags ();
c667e11d 758 break;
759
760 case OPT_std_legacy:
83a65a0d 761 set_default_std_flags ();
c667e11d 762 gfc_option.warn_std = 0;
d6583a5f 763 break;
764
3b6a4b41 765 case OPT_fshort_enums:
4aafe913 766 /* Handled in language-independent code. */
3b6a4b41 767 break;
15774a8b 768
ad8ed98e 769 case OPT_fcheck_:
770 gfc_handle_runtime_check_option (arg);
771 break;
d7cd448a 772
773 case OPT_fdec:
774 /* Enable all DEC extensions. */
775 set_dec_flags (1);
776 break;
777
778 case OPT_fdec_structure:
cf078427 779 flag_dec_structure = 1;
d7cd448a 780 break;
4ee9c684 781 }
782
d3b7ee7c 783 Fortran_handle_option_auto (&global_options, &global_options_set,
784 scode, arg, value,
785 gfc_option_lang_mask (), kind,
786 loc, handlers, global_dc);
4ee9c684 787 return result;
788}
e3d1ab2b 789
790
791/* Return a string with the options passed to the compiler; used for
792 Fortran's compiler_options() intrinsic. */
793
794char *
795gfc_get_option_string (void)
796{
797 unsigned j;
798 size_t len, pos;
799 char *result;
800
90acbb6e 801 /* Allocate and return a one-character string with '\0'. */
802 if (!save_decoded_options_count)
803 return XCNEWVEC (char, 1);
804
e3d1ab2b 805 /* Determine required string length. */
806
807 len = 0;
808 for (j = 1; j < save_decoded_options_count; j++)
809 {
810 switch (save_decoded_options[j].opt_index)
811 {
812 case OPT_o:
813 case OPT_d:
814 case OPT_dumpbase:
815 case OPT_dumpdir:
816 case OPT_auxbase:
817 case OPT_quiet:
818 case OPT_version:
819 case OPT_fintrinsic_modules_path:
7cb1cb52 820 case OPT_fintrinsic_modules_path_:
e3d1ab2b 821 /* Ignore these. */
822 break;
823 default:
293d72e0 824 /* Ignore file names. */
e3d1ab2b 825 if (save_decoded_options[j].orig_option_with_args_text[0] == '-')
826 len += 1
827 + strlen (save_decoded_options[j].orig_option_with_args_text);
828 }
829 }
830
dfa3fb6a 831 result = XCNEWVEC (char, len);
e3d1ab2b 832
833 pos = 0;
834 for (j = 1; j < save_decoded_options_count; j++)
835 {
836 switch (save_decoded_options[j].opt_index)
837 {
838 case OPT_o:
839 case OPT_d:
840 case OPT_dumpbase:
841 case OPT_dumpdir:
842 case OPT_auxbase:
843 case OPT_quiet:
844 case OPT_version:
845 case OPT_fintrinsic_modules_path:
7cb1cb52 846 case OPT_fintrinsic_modules_path_:
e3d1ab2b 847 /* Ignore these. */
848 continue;
849
850 case OPT_cpp_:
851 /* Use "-cpp" rather than "-cpp=<temporary file>". */
852 len = 4;
853 break;
854
855 default:
293d72e0 856 /* Ignore file names. */
e3d1ab2b 857 if (save_decoded_options[j].orig_option_with_args_text[0] != '-')
858 continue;
859
860 len = strlen (save_decoded_options[j].orig_option_with_args_text);
861 }
862
863 memcpy (&result[pos], save_decoded_options[j].orig_option_with_args_text, len);
864 pos += len;
865 result[pos++] = ' ';
866 }
867
868 result[--pos] = '\0';
869 return result;
870}