diff --git a/gcc/fortran/invoke.texi b/gcc/fortran/invoke.texi index 8bdc8a6b038..58e4e50b315 100644 --- a/gcc/fortran/invoke.texi +++ b/gcc/fortran/invoke.texi @@ -1227,6 +1227,17 @@ compiler itself. The output generated by this option might change between releases. This option may also generate internal compiler errors for features which have only recently been added. +@item -fdebug-aux-vars +@opindex @code{debug-aux-vars} +Make internal variables generated by the gfortran front end visible to a +debugger. This option also renames these internal variables shown by +@code{-fdump-tree-original} to a form @code{string:number} and enables +compiler warnings on them. + +This option is only really useful when debugging the gfortran compiler +itself together with @code{-g} or @code{-ggdb3} and +@code{-fdump-tree-original}. + @item -ffpe-trap=@var{list} @opindex @code{ffpe-trap=}@var{list} Specify a list of floating point exception traps to enable. On most diff --git a/gcc/fortran/lang.opt b/gcc/fortran/lang.opt index 96ed208cb85..57b0264458e 100644 --- a/gcc/fortran/lang.opt +++ b/gcc/fortran/lang.opt @@ -452,6 +452,10 @@ fd-lines-as-comments Fortran RejectNegative Treat lines with 'D' in column one as comments. +fdebug-aux-vars +Fortran Var(flag_debug_aux_vars) +Issue debug information for compiler-generated auxiliary variables. + fdec Fortran Var(flag_dec) Enable all DEC language extensions. diff --git a/gcc/fortran/trans.c b/gcc/fortran/trans.c index 025abe38985..1d5f6c28c7a 100644 --- a/gcc/fortran/trans.c +++ b/gcc/fortran/trans.c @@ -73,6 +73,40 @@ gfc_advance_chain (tree t, int n) return t; } +static int num_var; + +#define MAX_PREFIX_LEN 20 + +static tree +create_var_debug_raw (tree type, const char *prefix) +{ + /* Space for prefix + @ + 9-digit-number + \0. */ + char name_buf[MAX_PREFIX_LEN + 1 + 9 + 1]; + tree t; + + if (prefix == NULL) + prefix = "gfc"; + else + gcc_assert (strlen(prefix) <= MAX_PREFIX_LEN); + + snprintf (name_buf, sizeof(name_buf), "%s:%d", prefix, num_var++); + t = build_decl (input_location, VAR_DECL, get_identifier (name_buf), type); + + /* We want debug info for it. */ + DECL_IGNORED_P (t) = 0; + /* It should not be nameless. */ + DECL_NAMELESS (t) = 0; + + /* Make the variable writable. */ + TREE_READONLY (t) = 0; + + DECL_EXTERNAL (t) = 0; + TREE_STATIC (t) = 0; + TREE_USED (t) = 1; + + return t; +} + /* Creates a variable declaration with a given TYPE. */ tree @@ -80,6 +114,9 @@ gfc_create_var_np (tree type, const char *prefix) { tree t; + if (flag_debug_aux_vars) + return create_var_debug_raw (type, prefix); + t = create_tmp_var_raw (type, prefix); /* No warnings for anonymous variables. */