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