Branch data Line data Source code
1 : : /* Parse and display command line options.
2 : : Copyright (C) 2000-2025 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 "target.h"
25 : : #include "tree.h"
26 : : #include "gfortran.h"
27 : : #include "diagnostic.h" /* For global_dc. */
28 : : #include "opts.h"
29 : : #include "toplev.h" /* For save_decoded_options. */
30 : : #include "cpp.h"
31 : : #include "langhooks.h"
32 : :
33 : : gfc_option_t gfc_option;
34 : :
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 : :
49 : :
50 : : /* Set flags that control warnings and errors for different
51 : : Fortran standards to their default values. Keep in sync with
52 : : libgfortran/runtime/compile_options.c (init_compile_options). */
53 : :
54 : : static void
55 : 31802 : set_default_std_flags (void)
56 : : {
57 : 31802 : gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F95_DEL
58 : : | GFC_STD_F2003 | GFC_STD_F2008 | GFC_STD_F95 | GFC_STD_F77
59 : : | GFC_STD_F2008_OBS | GFC_STD_GNU | GFC_STD_LEGACY
60 : : | GFC_STD_F2018 | GFC_STD_F2018_DEL | GFC_STD_F2018_OBS | GFC_STD_F2023
61 : : | GFC_STD_F2023_DEL;
62 : 31802 : gfc_option.warn_std = GFC_STD_F2018_DEL | GFC_STD_F95_DEL | GFC_STD_LEGACY
63 : : | GFC_STD_F2023_DEL;
64 : 365 : }
65 : :
66 : : /* Set (or unset) the DEC extension flags. */
67 : :
68 : : static void
69 : 30843 : set_dec_flags (int value)
70 : : {
71 : : /* Set (or unset) other DEC compatibility extensions. */
72 : 30843 : SET_BITFLAG (flag_dollar_ok, value, value);
73 : 30843 : SET_BITFLAG (flag_cray_pointer, value, value);
74 : 30843 : SET_BITFLAG (flag_dec_structure, value, value);
75 : 30843 : SET_BITFLAG (flag_dec_intrinsic_ints, value, value);
76 : 30843 : SET_BITFLAG (flag_dec_static, value, value);
77 : 30843 : SET_BITFLAG (flag_dec_math, value, value);
78 : 30843 : SET_BITFLAG (flag_dec_include, value, value);
79 : 30843 : SET_BITFLAG (flag_dec_format_defaults, value, value);
80 : 30843 : SET_BITFLAG (flag_dec_blank_format_item, value, value);
81 : 30843 : SET_BITFLAG (flag_dec_char_conversions, value, value);
82 : 30843 : }
83 : :
84 : : /* Finalize DEC flags. */
85 : :
86 : : static void
87 : 30632 : post_dec_flags (int value)
88 : : {
89 : : /* Don't warn for legacy code if -fdec is given; however, setting -fno-dec
90 : : does not force these warnings. We make one final determination on this
91 : : at the end because -std= is always set first; thus, we can avoid
92 : : clobbering the user's desired standard settings in gfc_handle_option
93 : : e.g. when -fdec and -fno-dec are both given. */
94 : 0 : if (value)
95 : : {
96 : 199 : gfc_option.allow_std |= GFC_STD_F95_OBS | GFC_STD_F95_DEL
97 : : | GFC_STD_GNU | GFC_STD_LEGACY;
98 : 199 : gfc_option.warn_std &= ~(GFC_STD_LEGACY | GFC_STD_F95_DEL);
99 : : }
100 : 0 : }
101 : :
102 : : /* Enable (or disable) -finit-local-zero. */
103 : :
104 : : static void
105 : 30686 : set_init_local_zero (int value)
106 : : {
107 : 30686 : gfc_option.flag_init_integer_value = 0;
108 : 30686 : gfc_option.flag_init_character_value = (char)0;
109 : :
110 : 53 : SET_FLAG (gfc_option.flag_init_integer, value, GFC_INIT_INTEGER_ON,
111 : : GFC_INIT_INTEGER_OFF);
112 : 30686 : SET_FLAG (gfc_option.flag_init_logical, value, GFC_INIT_LOGICAL_FALSE,
113 : : GFC_INIT_LOGICAL_OFF);
114 : 30686 : SET_FLAG (gfc_option.flag_init_character, value, GFC_INIT_CHARACTER_ON,
115 : : GFC_INIT_CHARACTER_OFF);
116 : 53 : SET_FLAG (flag_init_real, value, GFC_INIT_REAL_ZERO, GFC_INIT_REAL_OFF);
117 : 53 : }
118 : :
119 : : /* Return language mask for Fortran options. */
120 : :
121 : : unsigned int
122 : 342965 : gfc_option_lang_mask (void)
123 : : {
124 : 342965 : return CL_Fortran;
125 : : }
126 : :
127 : : /* Initialize options structure OPTS. */
128 : :
129 : : void
130 : 30880 : gfc_init_options_struct (struct gcc_options *opts)
131 : : {
132 : 30880 : opts->x_flag_errno_math = 0;
133 : 30880 : opts->frontend_set_flag_errno_math = true;
134 : 30880 : opts->x_flag_associative_math = -1;
135 : 30880 : opts->frontend_set_flag_associative_math = true;
136 : 30880 : }
137 : :
138 : : /* Get ready for options handling. Keep in sync with
139 : : libgfortran/runtime/compile_options.c (init_compile_options). */
140 : :
141 : : void
142 : 30633 : gfc_init_options (unsigned int decoded_options_count,
143 : : struct cl_decoded_option *decoded_options)
144 : : {
145 : 30633 : gfc_source_file = NULL;
146 : 30633 : gfc_option.module_dir = NULL;
147 : 30633 : gfc_option.source_form = FORM_UNKNOWN;
148 : : /* The following is not quite right as Fortran since 2023 has: "A statement
149 : : shall not have more than one million characters." This can already be
150 : : reached by 'just' 100 lines with 10,000 characters each. */
151 : 30633 : gfc_option.max_continue_fixed = 1000000;
152 : 30633 : gfc_option.max_continue_free = 1000000;
153 : 30633 : gfc_option.max_identifier_length = GFC_MAX_SYMBOL_LEN;
154 : 30633 : gfc_option.max_errors = 25;
155 : :
156 : 30633 : gfc_option.flag_preprocessed = 0;
157 : 30633 : gfc_option.flag_d_lines = -1;
158 : 30633 : set_init_local_zero (0);
159 : :
160 : 30633 : gfc_option.fpe = 0;
161 : : /* All except GFC_FPE_INEXACT. */
162 : 30633 : gfc_option.fpe_summary = GFC_FPE_INVALID | GFC_FPE_DENORMAL
163 : : | GFC_FPE_ZERO | GFC_FPE_OVERFLOW
164 : : | GFC_FPE_UNDERFLOW;
165 : 30633 : gfc_option.rtcheck = 0;
166 : :
167 : 30633 : set_dec_flags (0);
168 : 30633 : set_default_std_flags ();
169 : :
170 : : /* Initialize cpp-related options. */
171 : 30633 : gfc_cpp_init_options (decoded_options_count, decoded_options);
172 : 30633 : gfc_diagnostics_init ();
173 : 30633 : }
174 : :
175 : :
176 : : /* Determine the source form from the filename extension. We assume
177 : : case insensitivity. */
178 : :
179 : : static gfc_source_form
180 : 28846 : form_from_filename (const char *filename)
181 : : {
182 : 28846 : static const struct
183 : : {
184 : : const char *extension;
185 : : gfc_source_form form;
186 : : }
187 : : exttype[] =
188 : : {
189 : : {
190 : : ".f90", FORM_FREE}
191 : : ,
192 : : {
193 : : ".f95", FORM_FREE}
194 : : ,
195 : : {
196 : : ".f03", FORM_FREE}
197 : : ,
198 : : {
199 : : ".f08", FORM_FREE}
200 : : ,
201 : : {
202 : : ".fii", FORM_FREE}
203 : : ,
204 : : {
205 : : ".fi", FORM_FIXED}
206 : : ,
207 : : {
208 : : ".f", FORM_FIXED}
209 : : ,
210 : : {
211 : : ".for", FORM_FIXED}
212 : : ,
213 : : {
214 : : ".ftn", FORM_FIXED}
215 : : ,
216 : : {
217 : : "", FORM_UNKNOWN}
218 : : }; /* sentinel value */
219 : :
220 : 28846 : gfc_source_form f_form;
221 : 28846 : const char *fileext;
222 : 28846 : int i;
223 : :
224 : : /* Find end of file name. Note, filename is either a NULL pointer or
225 : : a NUL terminated string. */
226 : 28846 : i = 0;
227 : 2579280 : while (filename[i] != '\0')
228 : 2550434 : i++;
229 : :
230 : : /* Find last period. */
231 : 144230 : while (i >= 0 && (filename[i] != '.'))
232 : 115384 : i--;
233 : :
234 : : /* Did we see a file extension? */
235 : 28846 : if (i < 0)
236 : : return FORM_UNKNOWN; /* Nope */
237 : :
238 : : /* Get file extension and compare it to others. */
239 : 28846 : fileext = &(filename[i]);
240 : :
241 : 28846 : i = -1;
242 : 28846 : f_form = FORM_UNKNOWN;
243 : 34375 : do
244 : : {
245 : 34375 : i++;
246 : 34375 : if (strcasecmp (fileext, exttype[i].extension) == 0)
247 : : {
248 : 28846 : f_form = exttype[i].form;
249 : 28846 : break;
250 : : }
251 : : }
252 : 5529 : while (exttype[i].form != FORM_UNKNOWN);
253 : :
254 : : return f_form;
255 : : }
256 : :
257 : :
258 : : /* Finalize commandline options. */
259 : :
260 : : bool
261 : 30633 : gfc_post_options (const char **pfilename)
262 : : {
263 : 30633 : const char *filename = *pfilename, *canon_source_file = NULL;
264 : 30633 : char *source_path;
265 : 30633 : bool verbose_missing_dir_warn;
266 : 30633 : int i;
267 : :
268 : : /* This needs to be after the commandline has been processed.
269 : : In Fortran, the options is by default enabled, in C/C++
270 : : by default disabled.
271 : : If not enabled explicitly by the user, only warn for -I
272 : : and -J, otherwise warn for all include paths. */
273 : 30633 : verbose_missing_dir_warn
274 : 61266 : = (OPTION_SET_P (cpp_warn_missing_include_dirs)
275 : 30633 : && global_options.x_cpp_warn_missing_include_dirs);
276 : 30633 : SET_OPTION_IF_UNSET (&global_options, &global_options_set,
277 : : cpp_warn_missing_include_dirs, 1);
278 : 30633 : gfc_check_include_dirs (verbose_missing_dir_warn);
279 : :
280 : 31333 : SET_OPTION_IF_UNSET (&global_options, &global_options_set,
281 : : flag_free_line_length,
282 : : (gfc_option.allow_std & GFC_STD_F2023) ? 10000 : 132);
283 : :
284 : : /* Finalize DEC flags. */
285 : 30632 : post_dec_flags (flag_dec);
286 : :
287 : : /* Excess precision other than "fast" requires front-end
288 : : support. */
289 : 30632 : if (flag_excess_precision == EXCESS_PRECISION_STANDARD)
290 : 0 : sorry ("%<-fexcess-precision=standard%> for Fortran");
291 : 30632 : else if (flag_excess_precision == EXCESS_PRECISION_FLOAT16)
292 : 0 : sorry ("%<-fexcess-precision=16%> for Fortran");
293 : :
294 : 30632 : flag_excess_precision = EXCESS_PRECISION_FAST;
295 : :
296 : : /* Fortran allows associative math - but we cannot reassociate if
297 : : we want traps or signed zeros. Cf. also flag_protect_parens. */
298 : 30632 : if (flag_associative_math == -1)
299 : 61117 : flag_associative_math = (!flag_trapping_math && !flag_signed_zeros);
300 : :
301 : 30632 : if (flag_protect_parens == -1)
302 : 30631 : flag_protect_parens = !optimize_fast;
303 : :
304 : : /* -Ofast sets implies -fstack-arrays unless an explicit size is set for
305 : : stack arrays. */
306 : 30632 : if (flag_stack_arrays == -1 && flag_max_stack_var_size == -2)
307 : 30612 : flag_stack_arrays = optimize_fast;
308 : :
309 : : /* By default, disable (re)allocation during assignment for -std=f95,
310 : : and enable it for F2003/F2008/GNU/Legacy. */
311 : 30632 : if (flag_realloc_lhs == -1)
312 : : {
313 : 30574 : if (gfc_option.allow_std & GFC_STD_F2003)
314 : 30432 : flag_realloc_lhs = 1;
315 : : else
316 : 142 : flag_realloc_lhs = 0;
317 : : }
318 : :
319 : : /* -fbounds-check is equivalent to -fcheck=bounds */
320 : 30632 : if (flag_bounds_check)
321 : 1026 : gfc_option.rtcheck |= GFC_RTCHECK_BOUNDS;
322 : :
323 : 30632 : if (flag_compare_debug)
324 : 9 : flag_dump_fortran_original = 0;
325 : :
326 : : /* Make -fmax-errors visible to gfortran's diagnostic machinery. */
327 : 30632 : if (OPTION_SET_P (flag_max_errors))
328 : 34 : gfc_option.max_errors = flag_max_errors;
329 : :
330 : : /* Verify the input file name. */
331 : 30632 : if (!filename || strcmp (filename, "-") == 0)
332 : : {
333 : 0 : filename = "";
334 : : }
335 : :
336 : 30632 : if (gfc_option.flag_preprocessed)
337 : : {
338 : : /* For preprocessed files, if the first tokens are of the form # NUM.
339 : : handle the directives so we know the original file name. */
340 : 3 : gfc_source_file = gfc_read_orig_filename (filename, &canon_source_file);
341 : 3 : if (gfc_source_file == NULL)
342 : 0 : gfc_source_file = filename;
343 : : else
344 : 3 : *pfilename = gfc_source_file;
345 : : }
346 : : else
347 : 30629 : gfc_source_file = filename;
348 : :
349 : 30632 : if (canon_source_file == NULL)
350 : 30630 : canon_source_file = gfc_source_file;
351 : :
352 : : /* Adds the path where the source file is to the list of include files. */
353 : :
354 : 30632 : i = strlen (canon_source_file);
355 : 575377 : while (i > 0 && !IS_DIR_SEPARATOR (canon_source_file[i]))
356 : 544745 : i--;
357 : :
358 : 30632 : if (i != 0)
359 : : {
360 : 30478 : source_path = (char *) alloca (i + 1);
361 : 30478 : memcpy (source_path, canon_source_file, i);
362 : 30478 : source_path[i] = 0;
363 : : /* Only warn if the directory is different from the input file as
364 : : if that one is not found, already an error is shown. */
365 : 30478 : bool warn = gfc_option.flag_preprocessed && gfc_source_file != filename;
366 : 30478 : gfc_add_include_path (source_path, true, true, warn, false);
367 : : }
368 : : else
369 : 154 : gfc_add_include_path (".", true, true, false, false);
370 : :
371 : 30632 : if (canon_source_file != gfc_source_file)
372 : 2 : free (CONST_CAST (char *, canon_source_file));
373 : :
374 : : /* Decide which form the file will be read in as. */
375 : :
376 : 30632 : if (gfc_option.source_form != FORM_UNKNOWN)
377 : 1786 : gfc_current_form = gfc_option.source_form;
378 : : else
379 : : {
380 : 28846 : gfc_current_form = form_from_filename (filename);
381 : :
382 : 28846 : if (gfc_current_form == FORM_UNKNOWN)
383 : : {
384 : 0 : gfc_current_form = FORM_FREE;
385 : 0 : main_input_filename = filename;
386 : 0 : gfc_warning_now (0, "Reading file %qs as free form",
387 : 0 : (filename[0] == '\0') ? "<stdin>" : filename);
388 : : }
389 : : }
390 : :
391 : : /* If the user specified -fd-lines-as-{code|comments} verify that we're
392 : : in fixed form. */
393 : 30632 : if (gfc_current_form == FORM_FREE)
394 : : {
395 : 28861 : if (gfc_option.flag_d_lines == 0)
396 : 0 : gfc_warning_now (0, "%<-fd-lines-as-comments%> has no effect "
397 : : "in free form");
398 : 28861 : else if (gfc_option.flag_d_lines == 1)
399 : 0 : gfc_warning_now (0, "%<-fd-lines-as-code%> has no effect in free form");
400 : :
401 : 28861 : if (warn_line_truncation == -1)
402 : 27951 : warn_line_truncation = 1;
403 : :
404 : : /* Enable -Werror=line-truncation when -Werror and -Wno-error have
405 : : not been set. */
406 : 28853 : if (warn_line_truncation && !OPTION_SET_P (warnings_are_errors)
407 : 57714 : && option_unspecified_p (OPT_Wline_truncation))
408 : 27500 : diagnostic_classify_diagnostic (global_dc, OPT_Wline_truncation,
409 : : diagnostics::kind::error,
410 : : UNKNOWN_LOCATION);
411 : : }
412 : : else
413 : : {
414 : : /* With -fdec, set -fd-lines-as-comments by default in fixed form. */
415 : 1771 : if (flag_dec && gfc_option.flag_d_lines == -1)
416 : 9 : gfc_option.flag_d_lines = 0;
417 : :
418 : 1771 : if (warn_line_truncation == -1)
419 : 1765 : warn_line_truncation = 0;
420 : : }
421 : :
422 : : /* If -pedantic, warn about the use of GNU extensions. */
423 : 30632 : if (pedantic && (gfc_option.allow_std & GFC_STD_GNU) != 0)
424 : 15406 : gfc_option.warn_std |= GFC_STD_GNU;
425 : : /* -std=legacy -pedantic is effectively -std=gnu. */
426 : 30632 : if (pedantic && (gfc_option.allow_std & GFC_STD_LEGACY) != 0)
427 : 15406 : gfc_option.warn_std |= GFC_STD_F95_OBS | GFC_STD_F95_DEL | GFC_STD_LEGACY;
428 : :
429 : : /* If the user didn't explicitly specify -f(no)-second-underscore we
430 : : use it if we're trying to be compatible with f2c, and not
431 : : otherwise. */
432 : 30632 : if (flag_second_underscore == -1)
433 : 30621 : flag_second_underscore = flag_f2c;
434 : :
435 : 30632 : if (!flag_automatic && flag_max_stack_var_size != -2
436 : 0 : && flag_max_stack_var_size != 0)
437 : 0 : gfc_warning_now (0, "Flag %<-fno-automatic%> overwrites %<-fmax-stack-var-size=%d%>",
438 : : flag_max_stack_var_size);
439 : 30632 : else if (!flag_automatic && flag_recursive)
440 : 8 : gfc_warning_now (OPT_Woverwrite_recursive, "Flag %<-fno-automatic%> "
441 : : "overwrites %<-frecursive%>");
442 : 30624 : else if (!flag_automatic && (flag_openmp || flag_openacc))
443 : 0 : gfc_warning_now (0, "Flag %<-fno-automatic%> overwrites %<-frecursive%> "
444 : : "implied by %qs", flag_openmp ? "-fopenmp" : "-fopenacc");
445 : 30624 : else if (flag_max_stack_var_size != -2 && flag_recursive)
446 : 0 : gfc_warning_now (0, "Flag %<-frecursive%> overwrites %<-fmax-stack-var-size=%d%>",
447 : : flag_max_stack_var_size);
448 : 30624 : else if (flag_max_stack_var_size != -2 && (flag_openmp || flag_openacc))
449 : 0 : gfc_warning_now (0, "Flag %<-fmax-stack-var-size=%d%> overwrites "
450 : : "%<-frecursive%> implied by %qs", flag_max_stack_var_size,
451 : : flag_openmp ? "-fopenmp" : "-fopenacc");
452 : :
453 : : /* Implement -frecursive as -fmax-stack-var-size=-1. */
454 : 30632 : if (flag_recursive)
455 : 21 : flag_max_stack_var_size = -1;
456 : :
457 : : /* Implied -frecursive; implemented as -fmax-stack-var-size=-1. */
458 : 30632 : if (flag_max_stack_var_size == -2 && flag_automatic
459 : 30554 : && (flag_openmp || flag_openacc))
460 : : {
461 : 4364 : flag_recursive = 1;
462 : 4364 : flag_max_stack_var_size = -1;
463 : : }
464 : :
465 : : /* Set flag_stack_arrays correctly. */
466 : 30632 : if (flag_stack_arrays == -1)
467 : 15 : flag_stack_arrays = 0;
468 : :
469 : : /* Set default. */
470 : 30632 : if (flag_max_stack_var_size == -2)
471 : 26232 : flag_max_stack_var_size = 65536;
472 : :
473 : : /* Implement -fno-automatic as -fmax-stack-var-size=0. */
474 : 30632 : if (!flag_automatic)
475 : 50 : flag_max_stack_var_size = 0;
476 : :
477 : : /* Decide inlining preference depending on optimization if nothing was
478 : : specified on the command line. */
479 : 30632 : if ((flag_inline_intrinsics & GFC_FLAG_INLINE_INTRINSIC_MAXLOC)
480 : : == GFC_FLAG_INLINE_INTRINSIC_MAXLOC_UNSET)
481 : : {
482 : 30630 : if (optimize == 0 || optimize_size != 0)
483 : 7935 : flag_inline_intrinsics &= ~GFC_FLAG_INLINE_INTRINSIC_MAXLOC;
484 : : else
485 : 22695 : flag_inline_intrinsics |= GFC_FLAG_INLINE_INTRINSIC_MAXLOC;
486 : : }
487 : 30632 : if ((flag_inline_intrinsics & GFC_FLAG_INLINE_INTRINSIC_MINLOC)
488 : : == GFC_FLAG_INLINE_INTRINSIC_MINLOC_UNSET)
489 : : {
490 : 30631 : if (optimize == 0 || optimize_size != 0)
491 : 7936 : flag_inline_intrinsics &= ~GFC_FLAG_INLINE_INTRINSIC_MINLOC;
492 : : else
493 : 22695 : flag_inline_intrinsics |= GFC_FLAG_INLINE_INTRINSIC_MINLOC;
494 : : }
495 : :
496 : : /* If the user did not specify an inline matmul limit, inline up to the BLAS
497 : : limit or up to 30 if no external BLAS is specified. */
498 : :
499 : 30632 : if (flag_inline_matmul_limit < 0)
500 : : {
501 : 30599 : if (flag_external_blas)
502 : 9 : flag_inline_matmul_limit = flag_blas_matmul_limit;
503 : : else
504 : 30590 : flag_inline_matmul_limit = 30;
505 : : }
506 : :
507 : : /* Optimization implies front end optimization, unless the user
508 : : specified it directly. */
509 : :
510 : 30632 : if (flag_frontend_optimize == -1)
511 : 34531 : flag_frontend_optimize = optimize && !optimize_debug;
512 : :
513 : : /* Same for front end loop interchange. */
514 : :
515 : 30632 : if (flag_frontend_loop_interchange == -1)
516 : 30628 : flag_frontend_loop_interchange = optimize;
517 : :
518 : : /* Do inline packing by default if optimizing, but not if
519 : : optimizing for size. */
520 : 30632 : if (flag_inline_arg_packing == -1)
521 : 38567 : flag_inline_arg_packing = optimize && !optimize_size;
522 : :
523 : 30632 : if (flag_max_array_constructor < 65535)
524 : 0 : flag_max_array_constructor = 65535;
525 : :
526 : 30632 : if (flag_fixed_line_length != 0 && flag_fixed_line_length < 7)
527 : 0 : gfc_fatal_error ("Fixed line length must be at least seven");
528 : :
529 : 30632 : if (flag_free_line_length != 0 && flag_free_line_length < 4)
530 : 0 : gfc_fatal_error ("Free line length must be at least three");
531 : :
532 : 30632 : if (flag_max_subrecord_length > MAX_SUBRECORD_LENGTH)
533 : 0 : gfc_fatal_error ("Maximum subrecord length cannot exceed %d",
534 : : MAX_SUBRECORD_LENGTH);
535 : :
536 : 30632 : gfc_cpp_post_options (verbose_missing_dir_warn);
537 : :
538 : 30632 : if (gfc_option.allow_std & GFC_STD_F2008)
539 : 30238 : lang_hooks.name = "GNU Fortran2008";
540 : 394 : else if (gfc_option.allow_std & GFC_STD_F2003)
541 : 252 : lang_hooks.name = "GNU Fortran2003";
542 : :
543 : : /* Set the unsigned "standard". */
544 : 30632 : if (flag_unsigned)
545 : 245 : gfc_option.allow_std |= GFC_STD_UNSIGNED;
546 : :
547 : 30632 : return gfc_cpp_preprocess_only ();
548 : : }
549 : :
550 : :
551 : : static void
552 : 8 : gfc_handle_module_path_options (const char *arg)
553 : : {
554 : :
555 : 8 : if (gfc_option.module_dir != NULL)
556 : 0 : gfc_fatal_error ("gfortran: Only one %<-J%> option allowed");
557 : :
558 : 8 : gfc_option.module_dir = XCNEWVEC (char, strlen (arg) + 2);
559 : 8 : strcpy (gfc_option.module_dir, arg);
560 : :
561 : 8 : gfc_add_include_path (gfc_option.module_dir, true, false, true, true);
562 : :
563 : 8 : strcat (gfc_option.module_dir, "/");
564 : 8 : }
565 : :
566 : :
567 : : /* Handle options -ffpe-trap= and -ffpe-summary=. */
568 : :
569 : : static void
570 : 6 : gfc_handle_fpe_option (const char *arg, bool trap)
571 : : {
572 : 6 : int result, pos = 0, n;
573 : : /* precision is a backwards compatibility alias for inexact. */
574 : 6 : static const char * const exception[] = { "invalid", "denormal", "zero",
575 : : "overflow", "underflow",
576 : : "inexact", "precision", NULL };
577 : 6 : static const int opt_exception[] = { GFC_FPE_INVALID, GFC_FPE_DENORMAL,
578 : : GFC_FPE_ZERO, GFC_FPE_OVERFLOW,
579 : : GFC_FPE_UNDERFLOW, GFC_FPE_INEXACT,
580 : : GFC_FPE_INEXACT,
581 : : 0 };
582 : :
583 : : /* As the default for -ffpe-summary= is nonzero, set it to 0. */
584 : 6 : if (!trap)
585 : 0 : gfc_option.fpe_summary = 0;
586 : :
587 : 18 : while (*arg)
588 : : {
589 : 18 : while (*arg == ',')
590 : 6 : arg++;
591 : :
592 : 102 : while (arg[pos] && arg[pos] != ',')
593 : 90 : pos++;
594 : :
595 : 12 : result = 0;
596 : 12 : if (strncmp ("none", arg, pos) == 0)
597 : : {
598 : 0 : if (trap)
599 : 0 : gfc_option.fpe = 0;
600 : : else
601 : 0 : gfc_option.fpe_summary = 0;
602 : 0 : arg += pos;
603 : 0 : pos = 0;
604 : 0 : continue;
605 : : }
606 : 12 : else if (!trap && strncmp ("all", arg, pos) == 0)
607 : : {
608 : 0 : gfc_option.fpe_summary = GFC_FPE_INVALID | GFC_FPE_DENORMAL
609 : : | GFC_FPE_ZERO | GFC_FPE_OVERFLOW
610 : : | GFC_FPE_UNDERFLOW | GFC_FPE_INEXACT;
611 : 0 : arg += pos;
612 : 0 : pos = 0;
613 : 0 : continue;
614 : : }
615 : : else
616 : 30 : for (n = 0; exception[n] != NULL; n++)
617 : : {
618 : 30 : if (exception[n] && strncmp (exception[n], arg, pos) == 0)
619 : : {
620 : 12 : if (trap)
621 : 12 : gfc_option.fpe |= opt_exception[n];
622 : : else
623 : 0 : gfc_option.fpe_summary |= opt_exception[n];
624 : : arg += pos;
625 : : pos = 0;
626 : : result = 1;
627 : : break;
628 : : }
629 : : }
630 : 12 : if (!result && trap)
631 : 0 : gfc_fatal_error ("Argument to %<-ffpe-trap%> is not valid: %s", arg);
632 : 12 : else if (!result)
633 : 0 : gfc_fatal_error ("Argument to %<-ffpe-summary%> is not valid: %s", arg);
634 : :
635 : : }
636 : 6 : }
637 : :
638 : :
639 : : static void
640 : 386 : gfc_handle_runtime_check_option (const char *arg)
641 : : {
642 : 386 : int result, pos = 0, n;
643 : 386 : static const char * const optname[] = { "all", "bounds", "array-temps",
644 : : "recursion", "do", "pointer",
645 : : "mem", "bits", NULL };
646 : 386 : static const int optmask[] = { GFC_RTCHECK_ALL, GFC_RTCHECK_BOUNDS,
647 : : GFC_RTCHECK_ARRAY_TEMPS,
648 : : GFC_RTCHECK_RECURSION, GFC_RTCHECK_DO,
649 : : GFC_RTCHECK_POINTER, GFC_RTCHECK_MEM,
650 : : GFC_RTCHECK_BITS, 0 };
651 : :
652 : 772 : while (*arg)
653 : : {
654 : 386 : while (*arg == ',')
655 : 0 : arg++;
656 : :
657 : 2290 : while (arg[pos] && arg[pos] != ',')
658 : 1904 : pos++;
659 : :
660 : 1329 : result = 0;
661 : 1329 : for (n = 0; optname[n] != NULL; n++)
662 : : {
663 : 1329 : if (optname[n] && strncmp (optname[n], arg, pos) == 0)
664 : : {
665 : 380 : gfc_option.rtcheck |= optmask[n];
666 : 380 : arg += pos;
667 : 380 : pos = 0;
668 : 380 : result = 1;
669 : 380 : break;
670 : : }
671 : 949 : else if (optname[n] && pos > 3 && startswith (arg, "no-")
672 : 12 : && strncmp (optname[n], arg+3, pos-3) == 0)
673 : : {
674 : 6 : gfc_option.rtcheck &= ~optmask[n];
675 : 6 : arg += pos;
676 : 6 : pos = 0;
677 : 6 : result = 1;
678 : 6 : break;
679 : : }
680 : : }
681 : 386 : if (!result)
682 : 0 : gfc_fatal_error ("Argument to %<-fcheck%> is not valid: %s", arg);
683 : : }
684 : 386 : }
685 : :
686 : :
687 : : /* Handle command-line options. Returns 0 if unrecognized, 1 if
688 : : recognized and handled. */
689 : :
690 : : bool
691 : 205823 : gfc_handle_option (size_t scode, const char *arg, HOST_WIDE_INT value,
692 : : int kind ATTRIBUTE_UNUSED, location_t loc ATTRIBUTE_UNUSED,
693 : : const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED)
694 : : {
695 : 205823 : bool result = true;
696 : 205823 : enum opt_code code = (enum opt_code) scode;
697 : :
698 : 205823 : if (gfc_cpp_handle_option (scode, arg, value) == 1)
699 : : return true;
700 : :
701 : 166522 : switch (code)
702 : : {
703 : 109778 : default:
704 : 109778 : if (cl_options[code].flags & gfc_option_lang_mask ())
705 : : break;
706 : 166522 : result = false;
707 : : break;
708 : :
709 : 12 : case OPT_fcheck_array_temporaries:
710 : 12 : SET_BITFLAG (gfc_option.rtcheck, value, GFC_RTCHECK_ARRAY_TEMPS);
711 : : break;
712 : :
713 : 4 : case OPT_fd_lines_as_code:
714 : 4 : gfc_option.flag_d_lines = 1;
715 : 4 : break;
716 : :
717 : 1 : case OPT_fd_lines_as_comments:
718 : 1 : gfc_option.flag_d_lines = 0;
719 : 1 : break;
720 : :
721 : 1785 : case OPT_ffixed_form:
722 : 1785 : gfc_option.source_form = FORM_FIXED;
723 : 1785 : break;
724 : :
725 : 15 : case OPT_ffree_form:
726 : 15 : gfc_option.source_form = FORM_FREE;
727 : 15 : break;
728 : :
729 : 34292 : case OPT_fintrinsic_modules_path:
730 : 34292 : case OPT_fintrinsic_modules_path_:
731 : :
732 : : /* This is needed because omp_lib.h is in a directory together
733 : : with intrinsic modules. Do no warn because during testing
734 : : without an installed compiler, we would get lots of bogus
735 : : warnings for a missing include directory. */
736 : 34292 : gfc_add_include_path (arg, false, false, false, true);
737 : :
738 : 34292 : gfc_add_intrinsic_modules_path (arg);
739 : 34292 : break;
740 : :
741 : 3 : case OPT_fpreprocessed:
742 : 3 : gfc_option.flag_preprocessed = value;
743 : 3 : break;
744 : :
745 : 0 : case OPT_fmax_identifier_length_:
746 : 0 : if (value > GFC_MAX_SYMBOL_LEN)
747 : 0 : gfc_fatal_error ("Maximum supported identifier length is %d",
748 : : GFC_MAX_SYMBOL_LEN);
749 : 0 : gfc_option.max_identifier_length = value;
750 : 0 : break;
751 : :
752 : 53 : case OPT_finit_local_zero:
753 : 53 : set_init_local_zero (value);
754 : 53 : break;
755 : :
756 : 19 : case OPT_finit_logical_:
757 : 19 : if (!strcasecmp (arg, "false"))
758 : 6 : gfc_option.flag_init_logical = GFC_INIT_LOGICAL_FALSE;
759 : 13 : else if (!strcasecmp (arg, "true"))
760 : 13 : gfc_option.flag_init_logical = GFC_INIT_LOGICAL_TRUE;
761 : : else
762 : 0 : gfc_fatal_error ("Unrecognized option to %<-finit-logical%>: %s",
763 : : arg);
764 : : break;
765 : :
766 : 38 : case OPT_finit_integer_:
767 : 38 : gfc_option.flag_init_integer = GFC_INIT_INTEGER_ON;
768 : 38 : gfc_option.flag_init_integer_value = strtol (arg, NULL, 10);
769 : 38 : break;
770 : :
771 : 19 : case OPT_finit_character_:
772 : 19 : if (value >= 0 && value <= 127)
773 : : {
774 : 19 : gfc_option.flag_init_character = GFC_INIT_CHARACTER_ON;
775 : 19 : gfc_option.flag_init_character_value = (char)value;
776 : : }
777 : : else
778 : 0 : gfc_fatal_error ("The value of n in %<-finit-character=n%> must be "
779 : : "between 0 and 127");
780 : 19 : break;
781 : :
782 : 17960 : case OPT_I:
783 : 17960 : gfc_add_include_path (arg, true, false, true, true);
784 : 17960 : break;
785 : :
786 : 8 : case OPT_J:
787 : 8 : gfc_handle_module_path_options (arg);
788 : 8 : break;
789 : :
790 : 6 : case OPT_ffpe_trap_:
791 : 6 : gfc_handle_fpe_option (arg, true);
792 : 6 : break;
793 : :
794 : 0 : case OPT_ffpe_summary_:
795 : 0 : gfc_handle_fpe_option (arg, false);
796 : 0 : break;
797 : :
798 : 142 : case OPT_std_f95:
799 : 142 : gfc_option.allow_std = GFC_STD_OPT_F95;
800 : 142 : gfc_option.warn_std = GFC_STD_F95_OBS;
801 : 142 : gfc_option.max_continue_fixed = 19;
802 : 142 : gfc_option.max_continue_free = 39;
803 : 142 : gfc_option.max_identifier_length = 31;
804 : 142 : warn_ampersand = 1;
805 : 142 : warn_tabs = 1;
806 : 142 : break;
807 : :
808 : 252 : case OPT_std_f2003:
809 : 252 : gfc_option.allow_std = GFC_STD_OPT_F03;
810 : 252 : gfc_option.warn_std = GFC_STD_F95_OBS;
811 : 252 : gfc_option.max_continue_fixed = 255;
812 : 252 : gfc_option.max_continue_free = 255;
813 : 252 : gfc_option.max_identifier_length = 63;
814 : 252 : warn_ampersand = 1;
815 : 252 : warn_tabs = 1;
816 : 252 : break;
817 : :
818 : 242 : case OPT_std_f2008:
819 : 242 : gfc_option.allow_std = GFC_STD_OPT_F08;
820 : 242 : gfc_option.warn_std = GFC_STD_F95_OBS | GFC_STD_F2008_OBS;
821 : 242 : gfc_option.max_continue_free = 255;
822 : 242 : gfc_option.max_continue_fixed = 255;
823 : 242 : gfc_option.max_identifier_length = 63;
824 : 242 : warn_ampersand = 1;
825 : 242 : warn_tabs = 1;
826 : 242 : break;
827 : :
828 : 66 : case OPT_std_f2008ts:
829 : 66 : case OPT_std_f2018:
830 : 66 : gfc_option.allow_std = GFC_STD_OPT_F18;
831 : 66 : gfc_option.warn_std = GFC_STD_F95_OBS | GFC_STD_F2008_OBS
832 : : | GFC_STD_F2018_OBS;
833 : 66 : gfc_option.max_continue_free = 255;
834 : 66 : gfc_option.max_continue_fixed = 255;
835 : 66 : gfc_option.max_identifier_length = 63;
836 : 66 : warn_ampersand = 1;
837 : 66 : warn_tabs = 1;
838 : 66 : break;
839 : :
840 : 10 : case OPT_std_f2023:
841 : 10 : gfc_option.allow_std = GFC_STD_OPT_F23;
842 : 10 : gfc_option.warn_std = GFC_STD_F95_OBS | GFC_STD_F2008_OBS
843 : : | GFC_STD_F2018_OBS;
844 : 10 : gfc_option.max_identifier_length = 63;
845 : 10 : warn_ampersand = 1;
846 : 10 : warn_tabs = 1;
847 : 10 : break;
848 : :
849 : 19 : case OPT_std_f202y:
850 : 19 : gfc_option.allow_std = GFC_STD_OPT_F23 | GFC_STD_F202Y;
851 : 19 : gfc_option.warn_std = GFC_STD_F95_OBS | GFC_STD_F2008_OBS
852 : : | GFC_STD_F2018_OBS;
853 : 19 : gfc_option.max_identifier_length = 63;
854 : 19 : warn_ampersand = 1;
855 : 19 : warn_tabs = 1;
856 : 19 : break;
857 : :
858 : 365 : case OPT_std_gnu:
859 : 365 : set_default_std_flags ();
860 : 365 : break;
861 : :
862 : 804 : case OPT_std_legacy:
863 : 804 : set_default_std_flags ();
864 : 804 : gfc_option.warn_std = 0;
865 : 804 : break;
866 : :
867 : : case OPT_fshort_enums:
868 : : /* Handled in language-independent code. */
869 : : break;
870 : :
871 : 386 : case OPT_fcheck_:
872 : 386 : gfc_handle_runtime_check_option (arg);
873 : 386 : break;
874 : :
875 : 210 : case OPT_fdec:
876 : : /* Set (or unset) the DEC extension flags. */
877 : 210 : set_dec_flags (value);
878 : 210 : break;
879 : :
880 : 21 : case OPT_fbuiltin_:
881 : : /* We only handle -fno-builtin-omp_is_initial_device
882 : : and -fno-builtin-acc_on_device. */
883 : 21 : if (value)
884 : : return false; /* Not supported. */
885 : 21 : if (!strcmp ("omp_is_initial_device", arg))
886 : 1 : gfc_option.disable_omp_is_initial_device = true;
887 : 20 : else if (!strcmp ("omp_get_initial_device", arg))
888 : 1 : gfc_option.disable_omp_get_initial_device = true;
889 : 19 : else if (!strcmp ("omp_get_num_devices", arg))
890 : 1 : gfc_option.disable_omp_get_num_devices = true;
891 : 18 : else if (!strcmp ("acc_on_device", arg))
892 : 18 : gfc_option.disable_acc_on_device = true;
893 : : else
894 : 0 : warning (0, "command-line option %<-fno-builtin-%s%> is not valid for "
895 : : "Fortran", arg);
896 : : break;
897 : :
898 : : }
899 : :
900 : 166522 : Fortran_handle_option_auto (&global_options, &global_options_set,
901 : : scode, arg, value,
902 : : gfc_option_lang_mask (), kind,
903 : : loc, handlers, global_dc);
904 : 166522 : return result;
905 : : }
906 : :
907 : :
908 : : /* Return a string with the options passed to the compiler; used for
909 : : Fortran's compiler_options() intrinsic. */
910 : :
911 : : char *
912 : 8 : gfc_get_option_string (void)
913 : : {
914 : 8 : unsigned j;
915 : 8 : size_t len, pos;
916 : 8 : char *result;
917 : :
918 : : /* Allocate and return a one-character string with '\0'. */
919 : 8 : if (!save_decoded_options_count)
920 : 0 : return XCNEWVEC (char, 1);
921 : :
922 : : /* Determine required string length. */
923 : :
924 : : len = 0;
925 : 180 : for (j = 1; j < save_decoded_options_count; j++)
926 : : {
927 : 172 : switch (save_decoded_options[j].opt_index)
928 : : {
929 : : case OPT_o:
930 : : case OPT_d:
931 : : case OPT_dumpbase:
932 : : case OPT_dumpbase_ext:
933 : : case OPT_dumpdir:
934 : : case OPT_quiet:
935 : : case OPT_version:
936 : : case OPT_fintrinsic_modules_path:
937 : : case OPT_fintrinsic_modules_path_:
938 : : /* Ignore these. */
939 : : break;
940 : 126 : default:
941 : : /* Ignore file names. */
942 : 126 : if (save_decoded_options[j].orig_option_with_args_text[0] == '-')
943 : 118 : len += 1
944 : 118 : + strlen (save_decoded_options[j].orig_option_with_args_text);
945 : : }
946 : : }
947 : :
948 : 8 : result = XCNEWVEC (char, len);
949 : :
950 : 8 : pos = 0;
951 : 188 : for (j = 1; j < save_decoded_options_count; j++)
952 : : {
953 : 172 : switch (save_decoded_options[j].opt_index)
954 : : {
955 : 46 : case OPT_o:
956 : 46 : case OPT_d:
957 : 46 : case OPT_dumpbase:
958 : 46 : case OPT_dumpbase_ext:
959 : 46 : case OPT_dumpdir:
960 : 46 : case OPT_quiet:
961 : 46 : case OPT_version:
962 : 46 : case OPT_fintrinsic_modules_path:
963 : 46 : case OPT_fintrinsic_modules_path_:
964 : : /* Ignore these. */
965 : 46 : continue;
966 : :
967 : : case OPT_cpp_:
968 : : /* Use "-cpp" rather than "-cpp=<temporary file>". */
969 : : len = 4;
970 : : break;
971 : :
972 : 126 : default:
973 : : /* Ignore file names. */
974 : 126 : if (save_decoded_options[j].orig_option_with_args_text[0] != '-')
975 : 8 : continue;
976 : :
977 : 118 : len = strlen (save_decoded_options[j].orig_option_with_args_text);
978 : : }
979 : :
980 : 118 : memcpy (&result[pos], save_decoded_options[j].orig_option_with_args_text, len);
981 : 118 : pos += len;
982 : 118 : result[pos++] = ' ';
983 : : }
984 : :
985 : 8 : result[--pos] = '\0';
986 : 8 : return result;
987 : : }
988 : :
989 : : #undef SET_BITFLAG
990 : : #undef SET_BITFLAG2
991 : : #undef SET_FLAG
|