/* Parse and display command line options.
- Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
+ Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
+ 2009, 2010
Free Software Foundation, Inc.
Contributed by Andy Vaught
#include "gfortran.h"
#include "target.h"
#include "cpp.h"
+#include "toplev.h"
+#include "tm.h"
gfc_option_t gfc_option;
/* Set flags that control warnings and errors for different
- Fortran standards to their default values. */
+ Fortran standards to their default values. Keep in sync with
+ libgfortran/runtime/compile_options.c (init_compile_options). */
static void
set_default_std_flags (void)
gfc_option.warn_std = GFC_STD_F95_DEL | GFC_STD_LEGACY;
}
-/* Get ready for options handling. */
+
+/* Get ready for options handling. Keep in sync with
+ libgfortran/runtime/compile_options.c (init_compile_options). */
unsigned int
gfc_init_options (unsigned int argc, const char **argv)
gfc_option.max_continue_free = 255;
gfc_option.max_identifier_length = GFC_MAX_SYMBOL_LEN;
gfc_option.max_subrecord_length = 0;
+ gfc_option.flag_max_array_constructor = 65535;
gfc_option.convert = GFC_CONVERT_NATIVE;
gfc_option.record_marker = 0;
gfc_option.dump_parse_tree = 0;
gfc_option.warn_underflow = 1;
gfc_option.warn_intrinsic_shadow = 0;
gfc_option.warn_intrinsics_std = 0;
+ gfc_option.warn_align_commons = 1;
gfc_option.max_errors = 25;
gfc_option.flag_all_intrinsics = 0;
gfc_option.flag_default_real = 0;
gfc_option.flag_dollar_ok = 0;
gfc_option.flag_underscoring = 1;
+ gfc_option.flag_whole_file = 0;
gfc_option.flag_f2c = 0;
gfc_option.flag_second_underscore = -1;
gfc_option.flag_implicit_none = 0;
gfc_option.flag_backslash = 0;
gfc_option.flag_module_private = 0;
gfc_option.flag_backtrace = 0;
- gfc_option.flag_check_array_temporaries = 0;
gfc_option.flag_allow_leading_underscore = 0;
gfc_option.flag_dump_core = 0;
gfc_option.flag_external_blas = 0;
gfc_option.flag_init_logical = GFC_INIT_LOGICAL_OFF;
gfc_option.flag_init_character = GFC_INIT_CHARACTER_OFF;
gfc_option.flag_init_character_value = (char)0;
+ gfc_option.flag_align_commons = 1;
+ gfc_option.flag_protect_parens = 1;
gfc_option.fpe = 0;
-
- /* Argument pointers cannot point to anything but their argument. */
- flag_argument_noalias = 3;
+ gfc_option.rtcheck = 0;
+ gfc_option.coarray = GFC_FCOARRAY_NONE;
flag_errno_math = 0;
set_default_std_flags ();
/* -fshort-enums can be default on some targets. */
- gfc_option.fshort_enums = targetm.default_short_enums ();
+ flag_short_enums = targetm.default_short_enums ();
/* Initialize cpp-related options. */
gfc_cpp_init_options(argc, argv);
char *source_path;
int i;
- /* Issue an error if -fwhole-program was used. */
+ /* Excess precision other than "fast" requires front-end
+ support. */
+ if (flag_excess_precision_cmdline == EXCESS_PRECISION_STANDARD
+ && TARGET_FLT_EVAL_METHOD_NON_DEFAULT)
+ sorry ("-fexcess-precision=standard for Fortran");
+ flag_excess_precision_cmdline = EXCESS_PRECISION_FAST;
+
+ /* Whole program needs whole file mode. */
if (flag_whole_program)
- gfc_fatal_error ("Option -fwhole-program is not supported for Fortran");
+ gfc_option.flag_whole_file = 1;
+
+ /* Enable whole-file mode if LTO is in effect. */
+ if (flag_lto || flag_whopr)
+ gfc_option.flag_whole_file = 1;
+
+ /* -fbounds-check is equivalent to -fcheck=bounds */
+ if (flag_bounds_check)
+ gfc_option.rtcheck |= GFC_RTCHECK_BOUNDS;
+
+ if (flag_compare_debug)
+ gfc_option.dump_parse_tree = 0;
/* Verify the input file name. */
if (!filename || strcmp (filename, "-") == 0)
source_path = (char *) alloca (i + 1);
memcpy (source_path, canon_source_file, i);
source_path[i] = 0;
- gfc_add_include_path (source_path, true);
+ gfc_add_include_path (source_path, true, true);
}
else
- gfc_add_include_path (".", true);
+ gfc_add_include_path (".", true, true);
if (canon_source_file != gfc_source_file)
gfc_free (CONST_CAST (char *, canon_source_file));
"implied by -fopenmp",
gfc_option.flag_max_stack_var_size);
- /* Implied -frecursive; implemented as -fmax-stack-var-size=-1. */
- if (gfc_option.flag_max_stack_var_size == -2 && gfc_option.flag_openmp)
+ /* Implement -frecursive as -fmax-stack-var-size=-1. */
+ if (gfc_option.flag_recursive)
gfc_option.flag_max_stack_var_size = -1;
+ /* Implied -frecursive; implemented as -fmax-stack-var-size=-1. */
+ if (gfc_option.flag_max_stack_var_size == -2 && gfc_option.flag_openmp
+ && gfc_option.flag_automatic)
+ {
+ gfc_option.flag_recursive = 1;
+ gfc_option.flag_max_stack_var_size = -1;
+ }
+
/* Set default. */
if (gfc_option.flag_max_stack_var_size == -2)
gfc_option.flag_max_stack_var_size = 32768;
- /* Implement -frecursive as -fmax-stack-var-size=-1. */
- if (gfc_option.flag_recursive)
- gfc_option.flag_max_stack_var_size = -1;
-
/* Implement -fno-automatic as -fmax-stack-var-size=0. */
if (!gfc_option.flag_automatic)
gfc_option.flag_max_stack_var_size = 0;
gfc_option.warn_tabs = 0;
}
+ if (pedantic && gfc_option.flag_whole_file)
+ gfc_option.flag_whole_file = 2;
+
gfc_cpp_post_options ();
/* FIXME: return gfc_cpp_preprocess_only ();
warn_unused = setting;
warn_return_type = setting;
warn_switch = setting;
-
- /* We save the value of warn_uninitialized, since if they put
- -Wuninitialized on the command line, we need to generate a
- warning about not using it without also specifying -O. */
- if (setting == 0)
- warn_uninitialized = 0;
- else if (warn_uninitialized != 1)
- warn_uninitialized = 2;
+ warn_uninitialized = setting;
}
strcpy (gfc_option.module_dir, arg);
strcat (gfc_option.module_dir, "/");
- gfc_add_include_path (gfc_option.module_dir, true);
+ gfc_add_include_path (gfc_option.module_dir, true, false);
}
}
+static void
+gfc_handle_coarray_option (const char *arg)
+{
+ if (strcmp (arg, "none") == 0)
+ gfc_option.coarray = GFC_FCOARRAY_NONE;
+ else if (strcmp (arg, "single") == 0)
+ gfc_option.coarray = GFC_FCOARRAY_SINGLE;
+ else
+ gfc_fatal_error ("Argument to -fcoarray is not valid: %s", arg);
+}
+
+
+static void
+gfc_handle_runtime_check_option (const char *arg)
+{
+ int result, pos = 0, n;
+ static const char * const optname[] = { "all", "bounds", "array-temps",
+ "recursion", "do", "pointer",
+ "mem", NULL };
+ static const int optmask[] = { GFC_RTCHECK_ALL, GFC_RTCHECK_BOUNDS,
+ GFC_RTCHECK_ARRAY_TEMPS,
+ GFC_RTCHECK_RECURSION, GFC_RTCHECK_DO,
+ GFC_RTCHECK_POINTER, GFC_RTCHECK_MEM,
+ 0 };
+
+ while (*arg)
+ {
+ while (*arg == ',')
+ arg++;
+
+ while (arg[pos] && arg[pos] != ',')
+ pos++;
+
+ result = 0;
+ for (n = 0; optname[n] != NULL; n++)
+ {
+ if (optname[n] && strncmp (optname[n], arg, pos) == 0)
+ {
+ gfc_option.rtcheck |= optmask[n];
+ arg += pos;
+ pos = 0;
+ result = 1;
+ break;
+ }
+ }
+ if (!result)
+ gfc_fatal_error ("Argument to -fcheck is not valid: %s", arg);
+ }
+}
+
+
/* Handle command-line options. Returns 0 if unrecognized, 1 if
recognized and handled. */
int
-gfc_handle_option (size_t scode, const char *arg, int value)
+gfc_handle_option (size_t scode, const char *arg, int value,
+ int kind ATTRIBUTE_UNUSED)
{
int result = 1;
enum opt_code code = (enum opt_code) scode;
gfc_option.warn_implicit_interface = value;
break;
+ case OPT_Wimplicit_procedure:
+ gfc_option.warn_implicit_procedure = value;
+ break;
+
case OPT_Wline_truncation:
gfc_option.warn_line_truncation = value;
break;
gfc_option.warn_intrinsic_shadow = value;
break;
+ case OPT_Walign_commons:
+ gfc_option.warn_align_commons = value;
+ break;
+
case OPT_fall_intrinsics:
gfc_option.flag_all_intrinsics = 1;
break;
break;
case OPT_fcheck_array_temporaries:
- gfc_option.flag_check_array_temporaries = value;
+ gfc_option.rtcheck |= GFC_RTCHECK_ARRAY_TEMPS;
break;
case OPT_fdump_core:
gfc_option.flag_underscoring = value;
break;
+ case OPT_fwhole_file:
+ gfc_option.flag_whole_file = 1;
+ break;
+
case OPT_fsecond_underscore:
gfc_option.flag_second_underscore = value;
break;
break;
case OPT_fintrinsic_modules_path:
- gfc_add_include_path (arg, false);
+ gfc_add_include_path (arg, false, false);
gfc_add_intrinsic_modules_path (arg);
break;
+ case OPT_fmax_array_constructor_:
+ gfc_option.flag_max_array_constructor = value > 65535 ? value : 65535;
+ break;
+
case OPT_fmax_errors_:
gfc_option.max_errors = value;
break;
gfc_option.flag_init_real = GFC_INIT_REAL_ZERO;
else if (!strcasecmp (arg, "nan"))
gfc_option.flag_init_real = GFC_INIT_REAL_NAN;
+ else if (!strcasecmp (arg, "snan"))
+ gfc_option.flag_init_real = GFC_INIT_REAL_SNAN;
else if (!strcasecmp (arg, "inf"))
gfc_option.flag_init_real = GFC_INIT_REAL_INF;
else if (!strcasecmp (arg, "-inf"))
break;
case OPT_I:
- gfc_add_include_path (arg, true);
+ gfc_add_include_path (arg, true, false);
break;
case OPT_J:
break;
case OPT_fshort_enums:
- gfc_option.fshort_enums = 1;
+ flag_short_enums = 1;
break;
case OPT_fconvert_little_endian:
case OPT_frecursive:
gfc_option.flag_recursive = 1;
break;
+
+ case OPT_falign_commons:
+ gfc_option.flag_align_commons = value;
+ break;
+
+ case OPT_fprotect_parens:
+ gfc_option.flag_protect_parens = value;
+ break;
+
+ case OPT_fcheck_:
+ gfc_handle_runtime_check_option (arg);
+ break;
+
+ case OPT_fcoarray_:
+ gfc_handle_coarray_option (arg);
+ break;
}
return result;