181418a27Smrg /* Parse and display command line options.
2*dd083157Smrg Copyright (C) 2000-2020 Free Software Foundation, Inc.
381418a27Smrg Contributed by Andy Vaught
481418a27Smrg
581418a27Smrg This file is part of GCC.
681418a27Smrg
781418a27Smrg GCC is free software; you can redistribute it and/or modify it under
881418a27Smrg the terms of the GNU General Public License as published by the Free
981418a27Smrg Software Foundation; either version 3, or (at your option) any later
1081418a27Smrg version.
1181418a27Smrg
1281418a27Smrg GCC is distributed in the hope that it will be useful, but WITHOUT ANY
1381418a27Smrg WARRANTY; without even the implied warranty of MERCHANTABILITY or
1481418a27Smrg FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1581418a27Smrg for more details.
1681418a27Smrg
1781418a27Smrg You should have received a copy of the GNU General Public License
1881418a27Smrg along with GCC; see the file COPYING3. If not see
1981418a27Smrg <http://www.gnu.org/licenses/>. */
2081418a27Smrg
2181418a27Smrg #include "config.h"
2281418a27Smrg #include "system.h"
2381418a27Smrg #include "coretypes.h"
2481418a27Smrg #include "target.h"
2581418a27Smrg #include "tree.h"
2681418a27Smrg #include "gfortran.h"
2781418a27Smrg #include "diagnostic.h" /* For global_dc. */
2881418a27Smrg #include "opts.h"
2981418a27Smrg #include "toplev.h" /* For save_decoded_options. */
3081418a27Smrg #include "cpp.h"
3181418a27Smrg #include "langhooks.h"
3281418a27Smrg
3381418a27Smrg gfc_option_t gfc_option;
3481418a27Smrg
3581418a27Smrg #define SET_FLAG(flag, condition, on_value, off_value) \
3681418a27Smrg do \
3781418a27Smrg { \
3881418a27Smrg if (condition) \
3981418a27Smrg flag = (on_value); \
4081418a27Smrg else \
4181418a27Smrg flag = (off_value); \
4281418a27Smrg } while (0)
4381418a27Smrg
4481418a27Smrg #define SET_BITFLAG2(m) m
4581418a27Smrg
4681418a27Smrg #define SET_BITFLAG(flag, condition, value) \
4781418a27Smrg SET_BITFLAG2 (SET_FLAG (flag, condition, (flag | (value)), (flag & ~(value))))
4881418a27Smrg
4981418a27Smrg
5081418a27Smrg /* Set flags that control warnings and errors for different
5181418a27Smrg Fortran standards to their default values. Keep in sync with
5281418a27Smrg libgfortran/runtime/compile_options.c (init_compile_options). */
5381418a27Smrg
5481418a27Smrg static void
set_default_std_flags(void)5581418a27Smrg set_default_std_flags (void)
5681418a27Smrg {
5781418a27Smrg gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F95_DEL
5881418a27Smrg | GFC_STD_F2003 | GFC_STD_F2008 | GFC_STD_F95 | GFC_STD_F77
5981418a27Smrg | GFC_STD_F2008_OBS | GFC_STD_GNU | GFC_STD_LEGACY
6081418a27Smrg | GFC_STD_F2018 | GFC_STD_F2018_DEL | GFC_STD_F2018_OBS;
6181418a27Smrg gfc_option.warn_std = GFC_STD_F2018_DEL | GFC_STD_F95_DEL | GFC_STD_LEGACY;
6281418a27Smrg }
6381418a27Smrg
6481418a27Smrg /* Set (or unset) the DEC extension flags. */
6581418a27Smrg
6681418a27Smrg static void
set_dec_flags(int value)6781418a27Smrg set_dec_flags (int value)
6881418a27Smrg {
6981418a27Smrg /* Set (or unset) other DEC compatibility extensions. */
7081418a27Smrg SET_BITFLAG (flag_dollar_ok, value, value);
7181418a27Smrg SET_BITFLAG (flag_cray_pointer, value, value);
7281418a27Smrg SET_BITFLAG (flag_dec_structure, value, value);
7381418a27Smrg SET_BITFLAG (flag_dec_intrinsic_ints, value, value);
7481418a27Smrg SET_BITFLAG (flag_dec_static, value, value);
7581418a27Smrg SET_BITFLAG (flag_dec_math, value, value);
7681418a27Smrg SET_BITFLAG (flag_dec_include, value, value);
77*dd083157Smrg SET_BITFLAG (flag_dec_format_defaults, value, value);
78*dd083157Smrg SET_BITFLAG (flag_dec_blank_format_item, value, value);
79*dd083157Smrg SET_BITFLAG (flag_dec_char_conversions, value, value);
8081418a27Smrg }
8181418a27Smrg
8281418a27Smrg /* Finalize DEC flags. */
8381418a27Smrg
8481418a27Smrg static void
post_dec_flags(int value)8581418a27Smrg post_dec_flags (int value)
8681418a27Smrg {
8781418a27Smrg /* Don't warn for legacy code if -fdec is given; however, setting -fno-dec
8881418a27Smrg does not force these warnings. We make one final determination on this
8981418a27Smrg at the end because -std= is always set first; thus, we can avoid
9081418a27Smrg clobbering the user's desired standard settings in gfc_handle_option
9181418a27Smrg e.g. when -fdec and -fno-dec are both given. */
9281418a27Smrg if (value)
9381418a27Smrg {
9481418a27Smrg gfc_option.allow_std |= GFC_STD_F95_OBS | GFC_STD_F95_DEL
9581418a27Smrg | GFC_STD_GNU | GFC_STD_LEGACY;
9681418a27Smrg gfc_option.warn_std &= ~(GFC_STD_LEGACY | GFC_STD_F95_DEL);
9781418a27Smrg }
9881418a27Smrg }
9981418a27Smrg
10081418a27Smrg /* Enable (or disable) -finit-local-zero. */
10181418a27Smrg
10281418a27Smrg static void
set_init_local_zero(int value)10381418a27Smrg set_init_local_zero (int value)
10481418a27Smrg {
10581418a27Smrg gfc_option.flag_init_integer_value = 0;
10681418a27Smrg gfc_option.flag_init_character_value = (char)0;
10781418a27Smrg
10881418a27Smrg SET_FLAG (gfc_option.flag_init_integer, value, GFC_INIT_INTEGER_ON,
10981418a27Smrg GFC_INIT_INTEGER_OFF);
11081418a27Smrg SET_FLAG (gfc_option.flag_init_logical, value, GFC_INIT_LOGICAL_FALSE,
11181418a27Smrg GFC_INIT_LOGICAL_OFF);
11281418a27Smrg SET_FLAG (gfc_option.flag_init_character, value, GFC_INIT_CHARACTER_ON,
11381418a27Smrg GFC_INIT_CHARACTER_OFF);
11481418a27Smrg SET_FLAG (flag_init_real, value, GFC_INIT_REAL_ZERO, GFC_INIT_REAL_OFF);
11581418a27Smrg }
11681418a27Smrg
11781418a27Smrg /* Return language mask for Fortran options. */
11881418a27Smrg
11981418a27Smrg unsigned int
gfc_option_lang_mask(void)12081418a27Smrg gfc_option_lang_mask (void)
12181418a27Smrg {
12281418a27Smrg return CL_Fortran;
12381418a27Smrg }
12481418a27Smrg
12581418a27Smrg /* Initialize options structure OPTS. */
12681418a27Smrg
12781418a27Smrg void
gfc_init_options_struct(struct gcc_options * opts)12881418a27Smrg gfc_init_options_struct (struct gcc_options *opts)
12981418a27Smrg {
13081418a27Smrg opts->x_flag_errno_math = 0;
13181418a27Smrg opts->frontend_set_flag_errno_math = true;
13281418a27Smrg opts->x_flag_associative_math = -1;
13381418a27Smrg opts->frontend_set_flag_associative_math = true;
13481418a27Smrg }
13581418a27Smrg
13681418a27Smrg /* Get ready for options handling. Keep in sync with
13781418a27Smrg libgfortran/runtime/compile_options.c (init_compile_options). */
13881418a27Smrg
13981418a27Smrg void
gfc_init_options(unsigned int decoded_options_count,struct cl_decoded_option * decoded_options)14081418a27Smrg gfc_init_options (unsigned int decoded_options_count,
14181418a27Smrg struct cl_decoded_option *decoded_options)
14281418a27Smrg {
14381418a27Smrg gfc_source_file = NULL;
14481418a27Smrg gfc_option.module_dir = NULL;
14581418a27Smrg gfc_option.source_form = FORM_UNKNOWN;
14681418a27Smrg gfc_option.max_continue_fixed = 255;
14781418a27Smrg gfc_option.max_continue_free = 255;
14881418a27Smrg gfc_option.max_identifier_length = GFC_MAX_SYMBOL_LEN;
14981418a27Smrg gfc_option.max_errors = 25;
15081418a27Smrg
15181418a27Smrg gfc_option.flag_preprocessed = 0;
15281418a27Smrg gfc_option.flag_d_lines = -1;
15381418a27Smrg set_init_local_zero (0);
15481418a27Smrg
15581418a27Smrg gfc_option.fpe = 0;
15681418a27Smrg /* All except GFC_FPE_INEXACT. */
15781418a27Smrg gfc_option.fpe_summary = GFC_FPE_INVALID | GFC_FPE_DENORMAL
15881418a27Smrg | GFC_FPE_ZERO | GFC_FPE_OVERFLOW
15981418a27Smrg | GFC_FPE_UNDERFLOW;
16081418a27Smrg gfc_option.rtcheck = 0;
16181418a27Smrg
16281418a27Smrg /* ??? Wmissing-include-dirs is disabled by default in C/C++ but
16381418a27Smrg enabled by default in Fortran. Ideally, we should express this
16481418a27Smrg in .opt, but that is not supported yet. */
165*dd083157Smrg SET_OPTION_IF_UNSET (&global_options, &global_options_set,
166*dd083157Smrg cpp_warn_missing_include_dirs, 1);
16781418a27Smrg
16881418a27Smrg set_dec_flags (0);
16981418a27Smrg
17081418a27Smrg set_default_std_flags ();
17181418a27Smrg
17281418a27Smrg /* Initialize cpp-related options. */
17381418a27Smrg gfc_cpp_init_options (decoded_options_count, decoded_options);
17481418a27Smrg gfc_diagnostics_init ();
17581418a27Smrg }
17681418a27Smrg
17781418a27Smrg
17881418a27Smrg /* Determine the source form from the filename extension. We assume
17981418a27Smrg case insensitivity. */
18081418a27Smrg
18181418a27Smrg static gfc_source_form
form_from_filename(const char * filename)18281418a27Smrg form_from_filename (const char *filename)
18381418a27Smrg {
18481418a27Smrg static const struct
18581418a27Smrg {
18681418a27Smrg const char *extension;
18781418a27Smrg gfc_source_form form;
18881418a27Smrg }
18981418a27Smrg exttype[] =
19081418a27Smrg {
19181418a27Smrg {
19281418a27Smrg ".f90", FORM_FREE}
19381418a27Smrg ,
19481418a27Smrg {
19581418a27Smrg ".f95", FORM_FREE}
19681418a27Smrg ,
19781418a27Smrg {
19881418a27Smrg ".f03", FORM_FREE}
19981418a27Smrg ,
20081418a27Smrg {
20181418a27Smrg ".f08", FORM_FREE}
20281418a27Smrg ,
20381418a27Smrg {
20481418a27Smrg ".f", FORM_FIXED}
20581418a27Smrg ,
20681418a27Smrg {
20781418a27Smrg ".for", FORM_FIXED}
20881418a27Smrg ,
20981418a27Smrg {
21081418a27Smrg ".ftn", FORM_FIXED}
21181418a27Smrg ,
21281418a27Smrg {
21381418a27Smrg "", FORM_UNKNOWN}
21481418a27Smrg }; /* sentinel value */
21581418a27Smrg
21681418a27Smrg gfc_source_form f_form;
21781418a27Smrg const char *fileext;
21881418a27Smrg int i;
21981418a27Smrg
22081418a27Smrg /* Find end of file name. Note, filename is either a NULL pointer or
22181418a27Smrg a NUL terminated string. */
22281418a27Smrg i = 0;
22381418a27Smrg while (filename[i] != '\0')
22481418a27Smrg i++;
22581418a27Smrg
22681418a27Smrg /* Find last period. */
22781418a27Smrg while (i >= 0 && (filename[i] != '.'))
22881418a27Smrg i--;
22981418a27Smrg
23081418a27Smrg /* Did we see a file extension? */
23181418a27Smrg if (i < 0)
23281418a27Smrg return FORM_UNKNOWN; /* Nope */
23381418a27Smrg
23481418a27Smrg /* Get file extension and compare it to others. */
23581418a27Smrg fileext = &(filename[i]);
23681418a27Smrg
23781418a27Smrg i = -1;
23881418a27Smrg f_form = FORM_UNKNOWN;
23981418a27Smrg do
24081418a27Smrg {
24181418a27Smrg i++;
24281418a27Smrg if (strcasecmp (fileext, exttype[i].extension) == 0)
24381418a27Smrg {
24481418a27Smrg f_form = exttype[i].form;
24581418a27Smrg break;
24681418a27Smrg }
24781418a27Smrg }
24881418a27Smrg while (exttype[i].form != FORM_UNKNOWN);
24981418a27Smrg
25081418a27Smrg return f_form;
25181418a27Smrg }
25281418a27Smrg
25381418a27Smrg
25481418a27Smrg /* Finalize commandline options. */
25581418a27Smrg
25681418a27Smrg bool
gfc_post_options(const char ** pfilename)25781418a27Smrg gfc_post_options (const char **pfilename)
25881418a27Smrg {
25981418a27Smrg const char *filename = *pfilename, *canon_source_file = NULL;
26081418a27Smrg char *source_path;
26181418a27Smrg int i;
26281418a27Smrg
26381418a27Smrg /* Finalize DEC flags. */
26481418a27Smrg post_dec_flags (flag_dec);
26581418a27Smrg
26681418a27Smrg /* Excess precision other than "fast" requires front-end
26781418a27Smrg support. */
268*dd083157Smrg if (flag_excess_precision == EXCESS_PRECISION_STANDARD)
26981418a27Smrg sorry ("%<-fexcess-precision=standard%> for Fortran");
270*dd083157Smrg flag_excess_precision = EXCESS_PRECISION_FAST;
27181418a27Smrg
27281418a27Smrg /* Fortran allows associative math - but we cannot reassociate if
27381418a27Smrg we want traps or signed zeros. Cf. also flag_protect_parens. */
27481418a27Smrg if (flag_associative_math == -1)
27581418a27Smrg flag_associative_math = (!flag_trapping_math && !flag_signed_zeros);
27681418a27Smrg
27781418a27Smrg if (flag_protect_parens == -1)
27881418a27Smrg flag_protect_parens = !optimize_fast;
27981418a27Smrg
28081418a27Smrg /* -Ofast sets implies -fstack-arrays unless an explicit size is set for
28181418a27Smrg stack arrays. */
28281418a27Smrg if (flag_stack_arrays == -1 && flag_max_stack_var_size == -2)
28381418a27Smrg flag_stack_arrays = optimize_fast;
28481418a27Smrg
28581418a27Smrg /* By default, disable (re)allocation during assignment for -std=f95,
28681418a27Smrg and enable it for F2003/F2008/GNU/Legacy. */
28781418a27Smrg if (flag_realloc_lhs == -1)
28881418a27Smrg {
28981418a27Smrg if (gfc_option.allow_std & GFC_STD_F2003)
29081418a27Smrg flag_realloc_lhs = 1;
29181418a27Smrg else
29281418a27Smrg flag_realloc_lhs = 0;
29381418a27Smrg }
29481418a27Smrg
29581418a27Smrg /* -fbounds-check is equivalent to -fcheck=bounds */
29681418a27Smrg if (flag_bounds_check)
29781418a27Smrg gfc_option.rtcheck |= GFC_RTCHECK_BOUNDS;
29881418a27Smrg
29981418a27Smrg if (flag_compare_debug)
30081418a27Smrg flag_dump_fortran_original = 0;
30181418a27Smrg
30281418a27Smrg /* Make -fmax-errors visible to gfortran's diagnostic machinery. */
30381418a27Smrg if (global_options_set.x_flag_max_errors)
30481418a27Smrg gfc_option.max_errors = flag_max_errors;
30581418a27Smrg
30681418a27Smrg /* Verify the input file name. */
30781418a27Smrg if (!filename || strcmp (filename, "-") == 0)
30881418a27Smrg {
30981418a27Smrg filename = "";
31081418a27Smrg }
31181418a27Smrg
31281418a27Smrg if (gfc_option.flag_preprocessed)
31381418a27Smrg {
31481418a27Smrg /* For preprocessed files, if the first tokens are of the form # NUM.
31581418a27Smrg handle the directives so we know the original file name. */
31681418a27Smrg gfc_source_file = gfc_read_orig_filename (filename, &canon_source_file);
31781418a27Smrg if (gfc_source_file == NULL)
31881418a27Smrg gfc_source_file = filename;
31981418a27Smrg else
32081418a27Smrg *pfilename = gfc_source_file;
32181418a27Smrg }
32281418a27Smrg else
32381418a27Smrg gfc_source_file = filename;
32481418a27Smrg
32581418a27Smrg if (canon_source_file == NULL)
32681418a27Smrg canon_source_file = gfc_source_file;
32781418a27Smrg
32881418a27Smrg /* Adds the path where the source file is to the list of include files. */
32981418a27Smrg
33081418a27Smrg i = strlen (canon_source_file);
33181418a27Smrg while (i > 0 && !IS_DIR_SEPARATOR (canon_source_file[i]))
33281418a27Smrg i--;
33381418a27Smrg
33481418a27Smrg if (i != 0)
33581418a27Smrg {
33681418a27Smrg source_path = (char *) alloca (i + 1);
33781418a27Smrg memcpy (source_path, canon_source_file, i);
33881418a27Smrg source_path[i] = 0;
33981418a27Smrg gfc_add_include_path (source_path, true, true, true);
34081418a27Smrg }
34181418a27Smrg else
34281418a27Smrg gfc_add_include_path (".", true, true, true);
34381418a27Smrg
34481418a27Smrg if (canon_source_file != gfc_source_file)
34581418a27Smrg free (CONST_CAST (char *, canon_source_file));
34681418a27Smrg
34781418a27Smrg /* Decide which form the file will be read in as. */
34881418a27Smrg
34981418a27Smrg if (gfc_option.source_form != FORM_UNKNOWN)
35081418a27Smrg gfc_current_form = gfc_option.source_form;
35181418a27Smrg else
35281418a27Smrg {
35381418a27Smrg gfc_current_form = form_from_filename (filename);
35481418a27Smrg
35581418a27Smrg if (gfc_current_form == FORM_UNKNOWN)
35681418a27Smrg {
35781418a27Smrg gfc_current_form = FORM_FREE;
35881418a27Smrg main_input_filename = filename;
35981418a27Smrg gfc_warning_now (0, "Reading file %qs as free form",
36081418a27Smrg (filename[0] == '\0') ? "<stdin>" : filename);
36181418a27Smrg }
36281418a27Smrg }
36381418a27Smrg
36481418a27Smrg /* If the user specified -fd-lines-as-{code|comments} verify that we're
36581418a27Smrg in fixed form. */
36681418a27Smrg if (gfc_current_form == FORM_FREE)
36781418a27Smrg {
36881418a27Smrg if (gfc_option.flag_d_lines == 0)
36981418a27Smrg gfc_warning_now (0, "%<-fd-lines-as-comments%> has no effect "
37081418a27Smrg "in free form");
37181418a27Smrg else if (gfc_option.flag_d_lines == 1)
37281418a27Smrg gfc_warning_now (0, "%<-fd-lines-as-code%> has no effect in free form");
37381418a27Smrg
37481418a27Smrg if (warn_line_truncation == -1)
37581418a27Smrg warn_line_truncation = 1;
37681418a27Smrg
37781418a27Smrg /* Enable -Werror=line-truncation when -Werror and -Wno-error have
37881418a27Smrg not been set. */
37981418a27Smrg if (warn_line_truncation && !global_options_set.x_warnings_are_errors
38081418a27Smrg && (global_dc->classify_diagnostic[OPT_Wline_truncation] ==
38181418a27Smrg DK_UNSPECIFIED))
38281418a27Smrg diagnostic_classify_diagnostic (global_dc, OPT_Wline_truncation,
38381418a27Smrg DK_ERROR, UNKNOWN_LOCATION);
38481418a27Smrg }
38581418a27Smrg else
38681418a27Smrg {
38781418a27Smrg /* With -fdec, set -fd-lines-as-comments by default in fixed form. */
38881418a27Smrg if (flag_dec && gfc_option.flag_d_lines == -1)
38981418a27Smrg gfc_option.flag_d_lines = 0;
39081418a27Smrg
39181418a27Smrg if (warn_line_truncation == -1)
39281418a27Smrg warn_line_truncation = 0;
39381418a27Smrg }
39481418a27Smrg
39581418a27Smrg /* If -pedantic, warn about the use of GNU extensions. */
39681418a27Smrg if (pedantic && (gfc_option.allow_std & GFC_STD_GNU) != 0)
39781418a27Smrg gfc_option.warn_std |= GFC_STD_GNU;
39881418a27Smrg /* -std=legacy -pedantic is effectively -std=gnu. */
39981418a27Smrg if (pedantic && (gfc_option.allow_std & GFC_STD_LEGACY) != 0)
40081418a27Smrg gfc_option.warn_std |= GFC_STD_F95_OBS | GFC_STD_F95_DEL | GFC_STD_LEGACY;
40181418a27Smrg
40281418a27Smrg /* If the user didn't explicitly specify -f(no)-second-underscore we
40381418a27Smrg use it if we're trying to be compatible with f2c, and not
40481418a27Smrg otherwise. */
40581418a27Smrg if (flag_second_underscore == -1)
40681418a27Smrg flag_second_underscore = flag_f2c;
40781418a27Smrg
40881418a27Smrg if (!flag_automatic && flag_max_stack_var_size != -2
40981418a27Smrg && flag_max_stack_var_size != 0)
41081418a27Smrg gfc_warning_now (0, "Flag %<-fno-automatic%> overwrites %<-fmax-stack-var-size=%d%>",
41181418a27Smrg flag_max_stack_var_size);
41281418a27Smrg else if (!flag_automatic && flag_recursive)
413*dd083157Smrg gfc_warning_now (OPT_Woverwrite_recursive, "Flag %<-fno-automatic%> "
414*dd083157Smrg "overwrites %<-frecursive%>");
41581418a27Smrg else if (!flag_automatic && flag_openmp)
41681418a27Smrg gfc_warning_now (0, "Flag %<-fno-automatic%> overwrites %<-frecursive%> implied by "
41781418a27Smrg "%<-fopenmp%>");
41881418a27Smrg else if (flag_max_stack_var_size != -2 && flag_recursive)
41981418a27Smrg gfc_warning_now (0, "Flag %<-frecursive%> overwrites %<-fmax-stack-var-size=%d%>",
42081418a27Smrg flag_max_stack_var_size);
42181418a27Smrg else if (flag_max_stack_var_size != -2 && flag_openmp)
42281418a27Smrg gfc_warning_now (0, "Flag %<-fmax-stack-var-size=%d%> overwrites %<-frecursive%> "
42381418a27Smrg "implied by %<-fopenmp%>", flag_max_stack_var_size);
42481418a27Smrg
42581418a27Smrg /* Implement -frecursive as -fmax-stack-var-size=-1. */
42681418a27Smrg if (flag_recursive)
42781418a27Smrg flag_max_stack_var_size = -1;
42881418a27Smrg
42981418a27Smrg /* Implied -frecursive; implemented as -fmax-stack-var-size=-1. */
43081418a27Smrg if (flag_max_stack_var_size == -2 && flag_openmp && flag_automatic)
43181418a27Smrg {
43281418a27Smrg flag_recursive = 1;
43381418a27Smrg flag_max_stack_var_size = -1;
43481418a27Smrg }
43581418a27Smrg
43681418a27Smrg /* Set flag_stack_arrays correctly. */
43781418a27Smrg if (flag_stack_arrays == -1)
43881418a27Smrg flag_stack_arrays = 0;
43981418a27Smrg
44081418a27Smrg /* Set default. */
44181418a27Smrg if (flag_max_stack_var_size == -2)
442*dd083157Smrg flag_max_stack_var_size = 65536;
44381418a27Smrg
44481418a27Smrg /* Implement -fno-automatic as -fmax-stack-var-size=0. */
44581418a27Smrg if (!flag_automatic)
44681418a27Smrg flag_max_stack_var_size = 0;
44781418a27Smrg
44881418a27Smrg /* If the user did not specify an inline matmul limit, inline up to the BLAS
44981418a27Smrg limit or up to 30 if no external BLAS is specified. */
45081418a27Smrg
45181418a27Smrg if (flag_inline_matmul_limit < 0)
45281418a27Smrg {
45381418a27Smrg if (flag_external_blas)
45481418a27Smrg flag_inline_matmul_limit = flag_blas_matmul_limit;
45581418a27Smrg else
45681418a27Smrg flag_inline_matmul_limit = 30;
45781418a27Smrg }
45881418a27Smrg
45981418a27Smrg /* Optimization implies front end optimization, unless the user
46081418a27Smrg specified it directly. */
46181418a27Smrg
46281418a27Smrg if (flag_frontend_optimize == -1)
46381418a27Smrg flag_frontend_optimize = optimize && !optimize_debug;
46481418a27Smrg
46581418a27Smrg /* Same for front end loop interchange. */
46681418a27Smrg
46781418a27Smrg if (flag_frontend_loop_interchange == -1)
46881418a27Smrg flag_frontend_loop_interchange = optimize;
46981418a27Smrg
470*dd083157Smrg /* Do inline packing by default if optimizing, but not if
471*dd083157Smrg optimizing for size. */
472*dd083157Smrg if (flag_inline_arg_packing == -1)
473*dd083157Smrg flag_inline_arg_packing = optimize && !optimize_size;
474*dd083157Smrg
47581418a27Smrg if (flag_max_array_constructor < 65535)
47681418a27Smrg flag_max_array_constructor = 65535;
47781418a27Smrg
47881418a27Smrg if (flag_fixed_line_length != 0 && flag_fixed_line_length < 7)
47981418a27Smrg gfc_fatal_error ("Fixed line length must be at least seven");
48081418a27Smrg
48181418a27Smrg if (flag_free_line_length != 0 && flag_free_line_length < 4)
48281418a27Smrg gfc_fatal_error ("Free line length must be at least three");
48381418a27Smrg
48481418a27Smrg if (flag_max_subrecord_length > MAX_SUBRECORD_LENGTH)
48581418a27Smrg gfc_fatal_error ("Maximum subrecord length cannot exceed %d",
48681418a27Smrg MAX_SUBRECORD_LENGTH);
48781418a27Smrg
48881418a27Smrg gfc_cpp_post_options ();
48981418a27Smrg
49081418a27Smrg if (gfc_option.allow_std & GFC_STD_F2008)
49181418a27Smrg lang_hooks.name = "GNU Fortran2008";
49281418a27Smrg else if (gfc_option.allow_std & GFC_STD_F2003)
49381418a27Smrg lang_hooks.name = "GNU Fortran2003";
49481418a27Smrg
49581418a27Smrg return gfc_cpp_preprocess_only ();
49681418a27Smrg }
49781418a27Smrg
49881418a27Smrg
49981418a27Smrg static void
gfc_handle_module_path_options(const char * arg)50081418a27Smrg gfc_handle_module_path_options (const char *arg)
50181418a27Smrg {
50281418a27Smrg
50381418a27Smrg if (gfc_option.module_dir != NULL)
50481418a27Smrg gfc_fatal_error ("gfortran: Only one %<-J%> option allowed");
50581418a27Smrg
50681418a27Smrg gfc_option.module_dir = XCNEWVEC (char, strlen (arg) + 2);
50781418a27Smrg strcpy (gfc_option.module_dir, arg);
50881418a27Smrg
50981418a27Smrg gfc_add_include_path (gfc_option.module_dir, true, false, true);
51081418a27Smrg
51181418a27Smrg strcat (gfc_option.module_dir, "/");
51281418a27Smrg }
51381418a27Smrg
51481418a27Smrg
51581418a27Smrg /* Handle options -ffpe-trap= and -ffpe-summary=. */
51681418a27Smrg
51781418a27Smrg static void
gfc_handle_fpe_option(const char * arg,bool trap)51881418a27Smrg gfc_handle_fpe_option (const char *arg, bool trap)
51981418a27Smrg {
52081418a27Smrg int result, pos = 0, n;
52181418a27Smrg /* precision is a backwards compatibility alias for inexact. */
52281418a27Smrg static const char * const exception[] = { "invalid", "denormal", "zero",
52381418a27Smrg "overflow", "underflow",
52481418a27Smrg "inexact", "precision", NULL };
52581418a27Smrg static const int opt_exception[] = { GFC_FPE_INVALID, GFC_FPE_DENORMAL,
52681418a27Smrg GFC_FPE_ZERO, GFC_FPE_OVERFLOW,
52781418a27Smrg GFC_FPE_UNDERFLOW, GFC_FPE_INEXACT,
52881418a27Smrg GFC_FPE_INEXACT,
52981418a27Smrg 0 };
53081418a27Smrg
53181418a27Smrg /* As the default for -ffpe-summary= is nonzero, set it to 0. */
53281418a27Smrg if (!trap)
53381418a27Smrg gfc_option.fpe_summary = 0;
53481418a27Smrg
53581418a27Smrg while (*arg)
53681418a27Smrg {
53781418a27Smrg while (*arg == ',')
53881418a27Smrg arg++;
53981418a27Smrg
54081418a27Smrg while (arg[pos] && arg[pos] != ',')
54181418a27Smrg pos++;
54281418a27Smrg
54381418a27Smrg result = 0;
54481418a27Smrg if (!trap && strncmp ("none", arg, pos) == 0)
54581418a27Smrg {
54681418a27Smrg gfc_option.fpe_summary = 0;
54781418a27Smrg arg += pos;
54881418a27Smrg pos = 0;
54981418a27Smrg continue;
55081418a27Smrg }
55181418a27Smrg else if (!trap && strncmp ("all", arg, pos) == 0)
55281418a27Smrg {
55381418a27Smrg gfc_option.fpe_summary = GFC_FPE_INVALID | GFC_FPE_DENORMAL
55481418a27Smrg | GFC_FPE_ZERO | GFC_FPE_OVERFLOW
55581418a27Smrg | GFC_FPE_UNDERFLOW | GFC_FPE_INEXACT;
55681418a27Smrg arg += pos;
55781418a27Smrg pos = 0;
55881418a27Smrg continue;
55981418a27Smrg }
56081418a27Smrg else
56181418a27Smrg for (n = 0; exception[n] != NULL; n++)
56281418a27Smrg {
56381418a27Smrg if (exception[n] && strncmp (exception[n], arg, pos) == 0)
56481418a27Smrg {
56581418a27Smrg if (trap)
56681418a27Smrg gfc_option.fpe |= opt_exception[n];
56781418a27Smrg else
56881418a27Smrg gfc_option.fpe_summary |= opt_exception[n];
56981418a27Smrg arg += pos;
57081418a27Smrg pos = 0;
57181418a27Smrg result = 1;
57281418a27Smrg break;
57381418a27Smrg }
57481418a27Smrg }
57581418a27Smrg if (!result && !trap)
57681418a27Smrg gfc_fatal_error ("Argument to %<-ffpe-trap%> is not valid: %s", arg);
57781418a27Smrg else if (!result)
57881418a27Smrg gfc_fatal_error ("Argument to %<-ffpe-summary%> is not valid: %s", arg);
57981418a27Smrg
58081418a27Smrg }
58181418a27Smrg }
58281418a27Smrg
58381418a27Smrg
58481418a27Smrg static void
gfc_handle_runtime_check_option(const char * arg)58581418a27Smrg gfc_handle_runtime_check_option (const char *arg)
58681418a27Smrg {
58781418a27Smrg int result, pos = 0, n;
58881418a27Smrg static const char * const optname[] = { "all", "bounds", "array-temps",
58981418a27Smrg "recursion", "do", "pointer",
590*dd083157Smrg "mem", "bits", NULL };
59181418a27Smrg static const int optmask[] = { GFC_RTCHECK_ALL, GFC_RTCHECK_BOUNDS,
59281418a27Smrg GFC_RTCHECK_ARRAY_TEMPS,
59381418a27Smrg GFC_RTCHECK_RECURSION, GFC_RTCHECK_DO,
59481418a27Smrg GFC_RTCHECK_POINTER, GFC_RTCHECK_MEM,
595*dd083157Smrg GFC_RTCHECK_BITS, 0 };
59681418a27Smrg
59781418a27Smrg while (*arg)
59881418a27Smrg {
59981418a27Smrg while (*arg == ',')
60081418a27Smrg arg++;
60181418a27Smrg
60281418a27Smrg while (arg[pos] && arg[pos] != ',')
60381418a27Smrg pos++;
60481418a27Smrg
60581418a27Smrg result = 0;
60681418a27Smrg for (n = 0; optname[n] != NULL; n++)
60781418a27Smrg {
60881418a27Smrg if (optname[n] && strncmp (optname[n], arg, pos) == 0)
60981418a27Smrg {
61081418a27Smrg gfc_option.rtcheck |= optmask[n];
61181418a27Smrg arg += pos;
61281418a27Smrg pos = 0;
61381418a27Smrg result = 1;
61481418a27Smrg break;
61581418a27Smrg }
61681418a27Smrg else if (optname[n] && pos > 3 && gfc_str_startswith (arg, "no-")
61781418a27Smrg && strncmp (optname[n], arg+3, pos-3) == 0)
61881418a27Smrg {
61981418a27Smrg gfc_option.rtcheck &= ~optmask[n];
62081418a27Smrg arg += pos;
62181418a27Smrg pos = 0;
62281418a27Smrg result = 1;
62381418a27Smrg break;
62481418a27Smrg }
62581418a27Smrg }
62681418a27Smrg if (!result)
62781418a27Smrg gfc_fatal_error ("Argument to %<-fcheck%> is not valid: %s", arg);
62881418a27Smrg }
62981418a27Smrg }
63081418a27Smrg
63181418a27Smrg
63281418a27Smrg /* Handle command-line options. Returns 0 if unrecognized, 1 if
63381418a27Smrg recognized and handled. */
63481418a27Smrg
63581418a27Smrg bool
gfc_handle_option(size_t scode,const char * arg,HOST_WIDE_INT value,int kind ATTRIBUTE_UNUSED,location_t loc ATTRIBUTE_UNUSED,const struct cl_option_handlers * handlers ATTRIBUTE_UNUSED)63681418a27Smrg gfc_handle_option (size_t scode, const char *arg, HOST_WIDE_INT value,
63781418a27Smrg int kind ATTRIBUTE_UNUSED, location_t loc ATTRIBUTE_UNUSED,
63881418a27Smrg const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED)
63981418a27Smrg {
64081418a27Smrg bool result = true;
64181418a27Smrg enum opt_code code = (enum opt_code) scode;
64281418a27Smrg
64381418a27Smrg if (gfc_cpp_handle_option (scode, arg, value) == 1)
64481418a27Smrg return true;
64581418a27Smrg
64681418a27Smrg switch (code)
64781418a27Smrg {
64881418a27Smrg default:
64981418a27Smrg if (cl_options[code].flags & gfc_option_lang_mask ())
65081418a27Smrg break;
65181418a27Smrg result = false;
65281418a27Smrg break;
65381418a27Smrg
65481418a27Smrg case OPT_fcheck_array_temporaries:
65581418a27Smrg SET_BITFLAG (gfc_option.rtcheck, value, GFC_RTCHECK_ARRAY_TEMPS);
65681418a27Smrg break;
65781418a27Smrg
65881418a27Smrg case OPT_fd_lines_as_code:
65981418a27Smrg gfc_option.flag_d_lines = 1;
66081418a27Smrg break;
66181418a27Smrg
66281418a27Smrg case OPT_fd_lines_as_comments:
66381418a27Smrg gfc_option.flag_d_lines = 0;
66481418a27Smrg break;
66581418a27Smrg
66681418a27Smrg case OPT_ffixed_form:
66781418a27Smrg gfc_option.source_form = FORM_FIXED;
66881418a27Smrg break;
66981418a27Smrg
67081418a27Smrg case OPT_ffree_form:
67181418a27Smrg gfc_option.source_form = FORM_FREE;
67281418a27Smrg break;
67381418a27Smrg
67481418a27Smrg case OPT_static_libgfortran:
67581418a27Smrg #ifndef HAVE_LD_STATIC_DYNAMIC
67681418a27Smrg gfc_fatal_error ("%<-static-libgfortran%> is not supported in this "
67781418a27Smrg "configuration");
67881418a27Smrg #endif
67981418a27Smrg break;
68081418a27Smrg
68181418a27Smrg case OPT_fintrinsic_modules_path:
68281418a27Smrg case OPT_fintrinsic_modules_path_:
68381418a27Smrg
68481418a27Smrg /* This is needed because omp_lib.h is in a directory together
68581418a27Smrg with intrinsic modules. Do no warn because during testing
68681418a27Smrg without an installed compiler, we would get lots of bogus
68781418a27Smrg warnings for a missing include directory. */
68881418a27Smrg gfc_add_include_path (arg, false, false, false);
68981418a27Smrg
69081418a27Smrg gfc_add_intrinsic_modules_path (arg);
69181418a27Smrg break;
69281418a27Smrg
69381418a27Smrg case OPT_fpreprocessed:
69481418a27Smrg gfc_option.flag_preprocessed = value;
69581418a27Smrg break;
69681418a27Smrg
69781418a27Smrg case OPT_fmax_identifier_length_:
69881418a27Smrg if (value > GFC_MAX_SYMBOL_LEN)
69981418a27Smrg gfc_fatal_error ("Maximum supported identifier length is %d",
70081418a27Smrg GFC_MAX_SYMBOL_LEN);
70181418a27Smrg gfc_option.max_identifier_length = value;
70281418a27Smrg break;
70381418a27Smrg
70481418a27Smrg case OPT_finit_local_zero:
70581418a27Smrg set_init_local_zero (value);
70681418a27Smrg break;
70781418a27Smrg
70881418a27Smrg case OPT_finit_logical_:
70981418a27Smrg if (!strcasecmp (arg, "false"))
71081418a27Smrg gfc_option.flag_init_logical = GFC_INIT_LOGICAL_FALSE;
71181418a27Smrg else if (!strcasecmp (arg, "true"))
71281418a27Smrg gfc_option.flag_init_logical = GFC_INIT_LOGICAL_TRUE;
71381418a27Smrg else
71481418a27Smrg gfc_fatal_error ("Unrecognized option to %<-finit-logical%>: %s",
71581418a27Smrg arg);
71681418a27Smrg break;
71781418a27Smrg
71881418a27Smrg case OPT_finit_integer_:
71981418a27Smrg gfc_option.flag_init_integer = GFC_INIT_INTEGER_ON;
72081418a27Smrg gfc_option.flag_init_integer_value = strtol (arg, NULL, 10);
72181418a27Smrg break;
72281418a27Smrg
72381418a27Smrg case OPT_finit_character_:
72481418a27Smrg if (value >= 0 && value <= 127)
72581418a27Smrg {
72681418a27Smrg gfc_option.flag_init_character = GFC_INIT_CHARACTER_ON;
72781418a27Smrg gfc_option.flag_init_character_value = (char)value;
72881418a27Smrg }
72981418a27Smrg else
73081418a27Smrg gfc_fatal_error ("The value of n in %<-finit-character=n%> must be "
73181418a27Smrg "between 0 and 127");
73281418a27Smrg break;
73381418a27Smrg
73481418a27Smrg case OPT_I:
73581418a27Smrg gfc_add_include_path (arg, true, false, true);
73681418a27Smrg break;
73781418a27Smrg
73881418a27Smrg case OPT_J:
73981418a27Smrg gfc_handle_module_path_options (arg);
74081418a27Smrg break;
74181418a27Smrg
74281418a27Smrg case OPT_ffpe_trap_:
74381418a27Smrg gfc_handle_fpe_option (arg, true);
74481418a27Smrg break;
74581418a27Smrg
74681418a27Smrg case OPT_ffpe_summary_:
74781418a27Smrg gfc_handle_fpe_option (arg, false);
74881418a27Smrg break;
74981418a27Smrg
75081418a27Smrg case OPT_std_f95:
75181418a27Smrg gfc_option.allow_std = GFC_STD_OPT_F95;
75281418a27Smrg gfc_option.warn_std = GFC_STD_F95_OBS;
75381418a27Smrg gfc_option.max_continue_fixed = 19;
75481418a27Smrg gfc_option.max_continue_free = 39;
75581418a27Smrg gfc_option.max_identifier_length = 31;
75681418a27Smrg warn_ampersand = 1;
75781418a27Smrg warn_tabs = 1;
75881418a27Smrg break;
75981418a27Smrg
76081418a27Smrg case OPT_std_f2003:
76181418a27Smrg gfc_option.allow_std = GFC_STD_OPT_F03;
76281418a27Smrg gfc_option.warn_std = GFC_STD_F95_OBS;
76381418a27Smrg gfc_option.max_identifier_length = 63;
76481418a27Smrg warn_ampersand = 1;
76581418a27Smrg warn_tabs = 1;
76681418a27Smrg break;
76781418a27Smrg
76881418a27Smrg case OPT_std_f2008:
76981418a27Smrg gfc_option.allow_std = GFC_STD_OPT_F08;
77081418a27Smrg gfc_option.warn_std = GFC_STD_F95_OBS | GFC_STD_F2008_OBS;
77181418a27Smrg gfc_option.max_identifier_length = 63;
77281418a27Smrg warn_ampersand = 1;
77381418a27Smrg warn_tabs = 1;
77481418a27Smrg break;
77581418a27Smrg
77681418a27Smrg case OPT_std_f2008ts:
77781418a27Smrg case OPT_std_f2018:
77881418a27Smrg gfc_option.allow_std = GFC_STD_OPT_F18;
77981418a27Smrg gfc_option.warn_std = GFC_STD_F95_OBS | GFC_STD_F2008_OBS
78081418a27Smrg | GFC_STD_F2018_OBS;
78181418a27Smrg gfc_option.max_identifier_length = 63;
78281418a27Smrg warn_ampersand = 1;
78381418a27Smrg warn_tabs = 1;
78481418a27Smrg break;
78581418a27Smrg
78681418a27Smrg case OPT_std_gnu:
78781418a27Smrg set_default_std_flags ();
78881418a27Smrg break;
78981418a27Smrg
79081418a27Smrg case OPT_std_legacy:
79181418a27Smrg set_default_std_flags ();
79281418a27Smrg gfc_option.warn_std = 0;
79381418a27Smrg break;
79481418a27Smrg
79581418a27Smrg case OPT_fshort_enums:
79681418a27Smrg /* Handled in language-independent code. */
79781418a27Smrg break;
79881418a27Smrg
79981418a27Smrg case OPT_fcheck_:
80081418a27Smrg gfc_handle_runtime_check_option (arg);
80181418a27Smrg break;
80281418a27Smrg
80381418a27Smrg case OPT_fdec:
80481418a27Smrg /* Set (or unset) the DEC extension flags. */
80581418a27Smrg set_dec_flags (value);
80681418a27Smrg break;
80781418a27Smrg }
80881418a27Smrg
80981418a27Smrg Fortran_handle_option_auto (&global_options, &global_options_set,
81081418a27Smrg scode, arg, value,
81181418a27Smrg gfc_option_lang_mask (), kind,
81281418a27Smrg loc, handlers, global_dc);
81381418a27Smrg return result;
81481418a27Smrg }
81581418a27Smrg
81681418a27Smrg
81781418a27Smrg /* Return a string with the options passed to the compiler; used for
81881418a27Smrg Fortran's compiler_options() intrinsic. */
81981418a27Smrg
82081418a27Smrg char *
gfc_get_option_string(void)82181418a27Smrg gfc_get_option_string (void)
82281418a27Smrg {
82381418a27Smrg unsigned j;
82481418a27Smrg size_t len, pos;
82581418a27Smrg char *result;
82681418a27Smrg
82781418a27Smrg /* Allocate and return a one-character string with '\0'. */
82881418a27Smrg if (!save_decoded_options_count)
82981418a27Smrg return XCNEWVEC (char, 1);
83081418a27Smrg
83181418a27Smrg /* Determine required string length. */
83281418a27Smrg
83381418a27Smrg len = 0;
83481418a27Smrg for (j = 1; j < save_decoded_options_count; j++)
83581418a27Smrg {
83681418a27Smrg switch (save_decoded_options[j].opt_index)
83781418a27Smrg {
83881418a27Smrg case OPT_o:
83981418a27Smrg case OPT_d:
84081418a27Smrg case OPT_dumpbase:
84181418a27Smrg case OPT_dumpdir:
84281418a27Smrg case OPT_auxbase:
84381418a27Smrg case OPT_quiet:
84481418a27Smrg case OPT_version:
84581418a27Smrg case OPT_fintrinsic_modules_path:
84681418a27Smrg case OPT_fintrinsic_modules_path_:
84781418a27Smrg /* Ignore these. */
84881418a27Smrg break;
84981418a27Smrg default:
85081418a27Smrg /* Ignore file names. */
85181418a27Smrg if (save_decoded_options[j].orig_option_with_args_text[0] == '-')
85281418a27Smrg len += 1
85381418a27Smrg + strlen (save_decoded_options[j].orig_option_with_args_text);
85481418a27Smrg }
85581418a27Smrg }
85681418a27Smrg
85781418a27Smrg result = XCNEWVEC (char, len);
85881418a27Smrg
85981418a27Smrg pos = 0;
86081418a27Smrg for (j = 1; j < save_decoded_options_count; j++)
86181418a27Smrg {
86281418a27Smrg switch (save_decoded_options[j].opt_index)
86381418a27Smrg {
86481418a27Smrg case OPT_o:
86581418a27Smrg case OPT_d:
86681418a27Smrg case OPT_dumpbase:
86781418a27Smrg case OPT_dumpdir:
86881418a27Smrg case OPT_auxbase:
86981418a27Smrg case OPT_quiet:
87081418a27Smrg case OPT_version:
87181418a27Smrg case OPT_fintrinsic_modules_path:
87281418a27Smrg case OPT_fintrinsic_modules_path_:
87381418a27Smrg /* Ignore these. */
87481418a27Smrg continue;
87581418a27Smrg
87681418a27Smrg case OPT_cpp_:
87781418a27Smrg /* Use "-cpp" rather than "-cpp=<temporary file>". */
87881418a27Smrg len = 4;
87981418a27Smrg break;
88081418a27Smrg
88181418a27Smrg default:
88281418a27Smrg /* Ignore file names. */
88381418a27Smrg if (save_decoded_options[j].orig_option_with_args_text[0] != '-')
88481418a27Smrg continue;
88581418a27Smrg
88681418a27Smrg len = strlen (save_decoded_options[j].orig_option_with_args_text);
88781418a27Smrg }
88881418a27Smrg
88981418a27Smrg memcpy (&result[pos], save_decoded_options[j].orig_option_with_args_text, len);
89081418a27Smrg pos += len;
89181418a27Smrg result[pos++] = ' ';
89281418a27Smrg }
89381418a27Smrg
89481418a27Smrg result[--pos] = '\0';
89581418a27Smrg return result;
89681418a27Smrg }
89781418a27Smrg
89881418a27Smrg #undef SET_BITFLAG
89981418a27Smrg #undef SET_BITFLAG2
90081418a27Smrg #undef SET_FLAG
901