diff options
author | domob <domob@138bc75d-0d04-0410-961f-82ee72b054a4> | 2008-07-24 18:52:51 +0000 |
---|---|---|
committer | domob <domob@138bc75d-0d04-0410-961f-82ee72b054a4> | 2008-07-24 18:52:51 +0000 |
commit | a34926badf40195e6424269a9b016530a3e79f7d (patch) | |
tree | 85be9ebc4a554eb2712749c7968b5f149a50d8eb /gcc/fortran/intrinsic.c | |
parent | 7f2ee37af89ab6cfa9ecff25ff8a7cefe8d08948 (diff) | |
download | gcc-a34926badf40195e6424269a9b016530a3e79f7d.tar.gz |
2008-07-24 Daniel Kraft <d@domob.eu>
PR fortran/33141
* lang.opt (Wnonstd-intrinsics): Removed option.
(Wintrinsics-std), (Wintrinsic-shadow): New options.
* invoke.texi (Option Summary): Removed -Wnonstd-intrinsics
from the list and added -Wintrinsics-std and -Wintrinsic-shadow.
(Error and Warning Options): Documented the new options and removed
the documentation for -Wnonstd-intrinsics.
* gfortran.h (gfc_option_t): New members warn_intrinsic_shadow and
warn_intrinsics_std, removed warn_nonstd_intrinsics.
(gfc_is_intrinsic): Renamed from gfc_intrinsic_name.
(gfc_warn_intrinsic_shadow), (gfc_check_intrinsic_standard): New.
* decl.c (match_procedure_decl): Replaced gfc_intrinsic_name by
the new name gfc_is_intrinsic.
(warn_intrinsic_shadow): New helper method.
(gfc_match_function_decl), (gfc_match_subroutine): Call the new method
warn_intrinsic_shadow to check the just-parsed procedure.
* expr.c (check_init_expr): Call new gfc_is_intrinsic to check whether
the function called is really an intrinsic in the selected standard.
* intrinsic.c (gfc_is_intrinsic): Renamed from gfc_intrinsic_name and
extended to take into account the selected standard settings when trying
to find out whether a symbol is an intrinsic or not.
(gfc_check_intrinsic_standard): Made public and extended.
(gfc_intrinsic_func_interface), (gfc_intrinsic_sub_interface): Removed
the calls to check_intrinsic_standard, this check now happens inside
gfc_is_intrinsic.
(gfc_warn_intrinsic_shadow): New method defined.
* options.c (gfc_init_options): Initialize new warning flags to false
and removed intialization of Wnonstd-intrinsics flag.
(gfc_post_options): Removed logic for Wnonstd-intrinsics flag.
(set_Wall): Set new warning flags and removed Wnonstd-intrinsics flag.
(gfc_handle_option): Handle the new flags and removed handling of the
old Wnonstd-intrinsics flag.
* primary.c (gfc_match_rvalue): Replaced call to gfc_intrinsic_name by
the new name gfc_is_intrinsic.
* resolve.c (resolve_actual_arglist): Ditto.
(resolve_generic_f), (resolve_unknown_f): Ditto.
(is_external_proc): Ditto.
(resolve_generic_s), (resolve_unknown_s): Ditto.
(resolve_symbol): Ditto and ensure for symbols declared INTRINSIC that
they are really available in the selected standard setting.
2008-07-24 Daniel Kraft <d@domob.eu>
PR fortran/33141
* gfortran.dg/intrinsic_shadow_1.f03: New test for -Wintrinsic-shadow.
* gfortran.dg/intrinsic_shadow_2.f03: Ditto.
* gfortran.dg/intrinsic_shadow_3.f03: Ditto.
* gfortran.dg/intrinsic_std_1.f90: New test for -Wintrinsics-std.
* gfortran.dg/intrinsic_std_2.f90: Ditto.
* gfortran.dg/intrinsic_std_3.f90: Ditto.
* gfortran.dg/intrinsic_std_4.f90: Ditto.
* gfortran.dg/warn_std_1.f90: Removed option -Wnonstd-intrinsics.
* gfortran.dg/warn_std_2.f90: Replaced -Wnonstd-intrinsics by
-Wintrinsics-std and adapted expected errors/warnings.
* gfortran.dg/warn_std_3.f90: Ditto.
* gfortran.dg/c_sizeof_2.f90: Adapted expected error/warning message.
* gfortran.dg/gamma_2.f90: Ditto.
* gfortran.dg/selected_char_kind_3.f90: Ditto.
* gfortran.dg/fmt_g0_2.f08: Call with -fall-intrinsics to allow abort.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@138122 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/fortran/intrinsic.c')
-rw-r--r-- | gcc/fortran/intrinsic.c | 172 |
1 files changed, 149 insertions, 23 deletions
diff --git a/gcc/fortran/intrinsic.c b/gcc/fortran/intrinsic.c index 4c55a2c99ba..e5eec7ef4aa 100644 --- a/gcc/fortran/intrinsic.c +++ b/gcc/fortran/intrinsic.c @@ -807,15 +807,47 @@ gfc_intrinsic_actual_ok (const char *name, const bool subroutine_flag) } -/* Given a string, figure out if it is the name of an intrinsic - subroutine or function. There are no generic intrinsic - subroutines, they are all specific. */ +/* Given a symbol, find out if it is (and is to be treated) an intrinsic. If + it's name refers to an intrinsic but this intrinsic is not included in the + selected standard, this returns FALSE and sets the symbol's external + attribute. */ -int -gfc_intrinsic_name (const char *name, int subroutine_flag) +bool +gfc_is_intrinsic (gfc_symbol* sym, int subroutine_flag, locus loc) { - return subroutine_flag ? gfc_find_subroutine (name) != NULL - : gfc_find_function (name) != NULL; + gfc_intrinsic_sym* isym; + const char* symstd; + + /* If INTRINSIC/EXTERNAL state is already known, return. */ + if (sym->attr.intrinsic) + return true; + if (sym->attr.external) + return false; + + if (subroutine_flag) + isym = gfc_find_subroutine (sym->name); + else + isym = gfc_find_function (sym->name); + + /* No such intrinsic available at all? */ + if (!isym) + return false; + + /* See if this intrinsic is allowed in the current standard. */ + if (gfc_check_intrinsic_standard (isym, &symstd, false, loc) == FAILURE) + { + if (gfc_option.warn_intrinsics_std) + gfc_warning_now ("The intrinsic '%s' at %L is not included in the" + " selected standard but %s and '%s' will be treated as" + " if declared EXTERNAL. Use an appropriate -std=*" + " option or define -fall-intrinsics to allow this" + " intrinsic.", sym->name, &loc, symstd, sym->name); + sym->attr.external = 1; + + return false; + } + + return true; } @@ -3448,21 +3480,82 @@ check_specific (gfc_intrinsic_sym *specific, gfc_expr *expr, int error_flag) /* Check whether an intrinsic belongs to whatever standard the user - has chosen. */ + has chosen, taking also into account -fall-intrinsics. Here, no + warning/error is emitted; but if symstd is not NULL, it is pointed to a + textual representation of the symbols standard status (like + "new in Fortran 2008", "a GNU extension" or "obsolescent in Fortran 95") that + can be used to construct a detailed warning/error message in case of + a FAILURE. */ -static try -check_intrinsic_standard (const char *name, int standard, locus *where) +try +gfc_check_intrinsic_standard (const gfc_intrinsic_sym* isym, + const char** symstd, bool silent, locus where) { - /* Do not warn about GNU-extensions if -std=gnu. */ - if (!gfc_option.warn_nonstd_intrinsics - || (standard == GFC_STD_GNU && gfc_option.warn_std & GFC_STD_GNU)) + const char* symstd_msg; + + /* For -fall-intrinsics, just succeed. */ + if (gfc_option.flag_all_intrinsics) return SUCCESS; - if (gfc_notify_std (standard, "Intrinsic '%s' at %L is not included " - "in the selected standard", name, where) == FAILURE) - return FAILURE; + /* Find the symbol's standard message for later usage. */ + switch (isym->standard) + { + case GFC_STD_F77: + symstd_msg = "available since Fortran 77"; + break; - return SUCCESS; + case GFC_STD_F95_OBS: + symstd_msg = "obsolescent in Fortran 95"; + break; + + case GFC_STD_F95_DEL: + symstd_msg = "deleted in Fortran 95"; + break; + + case GFC_STD_F95: + symstd_msg = "new in Fortran 95"; + break; + + case GFC_STD_F2003: + symstd_msg = "new in Fortran 2003"; + break; + + case GFC_STD_F2008: + symstd_msg = "new in Fortran 2008"; + break; + + case GFC_STD_GNU: + symstd_msg = "a GNU Fortran extension"; + break; + + case GFC_STD_LEGACY: + symstd_msg = "for backward compatibility"; + break; + + default: + gfc_internal_error ("Invalid standard code on intrinsic '%s' (%d)", + isym->name, isym->standard); + } + + /* If warning about the standard, warn and succeed. */ + if (gfc_option.warn_std & isym->standard) + { + /* Do only print a warning if not a GNU extension. */ + if (!silent && isym->standard != GFC_STD_GNU) + gfc_warning ("Intrinsic '%s' (is %s) is used at %L", + isym->name, _(symstd_msg), &where); + + return SUCCESS; + } + + /* If allowing the symbol's standard, succeed, too. */ + if (gfc_option.allow_std & isym->standard) + return SUCCESS; + + /* Otherwise, fail. */ + if (symstd) + *symstd = _(symstd_msg); + return FAILURE; } @@ -3508,9 +3601,6 @@ gfc_intrinsic_func_interface (gfc_expr *expr, int error_flag) return MATCH_NO; } - if (check_intrinsic_standard (name, isym->standard, &expr->where) == FAILURE) - return MATCH_ERROR; - if ((isym->id == GFC_ISYM_REAL || isym->id == GFC_ISYM_DBLE || isym->id == GFC_ISYM_CMPLX) && gfc_init_expr @@ -3605,9 +3695,6 @@ gfc_intrinsic_sub_interface (gfc_code *c, int error_flag) if (isym == NULL) return MATCH_NO; - if (check_intrinsic_standard (name, isym->standard, &c->loc) == FAILURE) - return MATCH_ERROR; - gfc_suppress_error = !error_flag; init_arglist (isym); @@ -3827,3 +3914,42 @@ gfc_convert_chartype (gfc_expr *expr, gfc_typespec *ts) return SUCCESS; } + + +/* Check if the passed name is name of an intrinsic (taking into account the + current -std=* and -fall-intrinsic settings). If it is, see if we should + warn about this as a user-procedure having the same name as an intrinsic + (-Wintrinsic-shadow enabled) and do so if we should. */ + +void +gfc_warn_intrinsic_shadow (const gfc_symbol* sym, bool in_module, bool func) +{ + gfc_intrinsic_sym* isym; + + /* If the warning is disabled, do nothing at all. */ + if (!gfc_option.warn_intrinsic_shadow) + return; + + /* Try to find an intrinsic of the same name. */ + if (func) + isym = gfc_find_function (sym->name); + else + isym = gfc_find_subroutine (sym->name); + + /* If no intrinsic was found with this name or it's not included in the + selected standard, everything's fine. */ + if (!isym || gfc_check_intrinsic_standard (isym, NULL, true, + sym->declared_at) == FAILURE) + return; + + /* Emit the warning. */ + if (in_module) + gfc_warning ("'%s' declared at %L may shadow the intrinsic of the same" + " name. In order to call the intrinsic, explicit INTRINSIC" + " declarations may be required.", + sym->name, &sym->declared_at); + else + gfc_warning ("'%s' declared at %L is also the name of an intrinsic. It can" + " only be called via an explicit interface or if declared" + " EXTERNAL.", sym->name, &sym->declared_at); +} |