diff options
author | Harald Anlauf <anlauf@gmx.de> | 2024-05-23 21:13:00 +0200 |
---|---|---|
committer | Harald Anlauf <anlauf@gmx.de> | 2024-07-15 20:41:43 +0200 |
commit | 71ec9ed7a7353f66d55b034a45336bf43a026b1d (patch) | |
tree | c873ed7743418e5a4fa838bfaa0999bd3064854b /gcc/fortran | |
parent | 13bfc385b0baebd22aeabb0d90915f2e9b18febe (diff) | |
download | gcc-71ec9ed7a7353f66d55b034a45336bf43a026b1d.zip gcc-71ec9ed7a7353f66d55b034a45336bf43a026b1d.tar.gz gcc-71ec9ed7a7353f66d55b034a45336bf43a026b1d.tar.bz2 |
Fortran: improve attribute conflict checking [PR93635]
gcc/fortran/ChangeLog:
PR fortran/93635
* symbol.cc (conflict_std): Helper function for reporting attribute
conflicts depending on the Fortran standard version.
(conf_std): Helper macro for checking standard-dependent conflicts.
(gfc_check_conflict): Use it.
gcc/testsuite/ChangeLog:
PR fortran/93635
* gfortran.dg/c-interop/c1255-2.f90: Adjust pattern.
* gfortran.dg/pr87907.f90: Likewise.
* gfortran.dg/pr93635.f90: New test.
Co-authored-by: Steven G. Kargl <kargl@gcc.gnu.org>
(cherry picked from commit 9561cf550a66a89e7c8d31202a03c4fddf82a3f2)
Diffstat (limited to 'gcc/fortran')
-rw-r--r-- | gcc/fortran/symbol.cc | 63 |
1 files changed, 28 insertions, 35 deletions
diff --git a/gcc/fortran/symbol.cc b/gcc/fortran/symbol.cc index 0a1646d..5db3c88 100644 --- a/gcc/fortran/symbol.cc +++ b/gcc/fortran/symbol.cc @@ -407,18 +407,36 @@ gfc_check_function_type (gfc_namespace *ns) /******************** Symbol attribute stuff *********************/ +/* Older standards produced conflicts for some attributes that are allowed + in newer standards. Check for the conflict and issue an error depending + on the standard in play. */ + +static bool +conflict_std (int standard, const char *a1, const char *a2, const char *name, + locus *where) +{ + if (name == NULL) + { + return gfc_notify_std (standard, "%s attribute conflicts " + "with %s attribute at %L", a1, a2, + where); + } + else + { + return gfc_notify_std (standard, "%s attribute conflicts " + "with %s attribute in %qs at %L", + a1, a2, name, where); + } +} + /* This is a generic conflict-checker. We do this to avoid having a single conflict in two places. */ #define conf(a, b) if (attr->a && attr->b) { a1 = a; a2 = b; goto conflict; } #define conf2(a) if (attr->a) { a2 = a; goto conflict; } -#define conf_std(a, b, std) if (attr->a && attr->b)\ - {\ - a1 = a;\ - a2 = b;\ - standard = std;\ - goto conflict_std;\ - } +#define conf_std(a, b, std) if (attr->a && attr->b \ + && !conflict_std (std, a, b, name, where)) \ + return false; bool gfc_check_conflict (symbol_attribute *attr, const char *name, locus *where) @@ -451,7 +469,6 @@ gfc_check_conflict (symbol_attribute *attr, const char *name, locus *where) "OACC DECLARE DEVICE_RESIDENT"; const char *a1, *a2; - int standard; if (attr->artificial) return true; @@ -460,20 +477,10 @@ gfc_check_conflict (symbol_attribute *attr, const char *name, locus *where) where = &gfc_current_locus; if (attr->pointer && attr->intent != INTENT_UNKNOWN) - { - a1 = pointer; - a2 = intent; - standard = GFC_STD_F2003; - goto conflict_std; - } + conf_std (pointer, intent, GFC_STD_F2003); - if (attr->in_namelist && (attr->allocatable || attr->pointer)) - { - a1 = in_namelist; - a2 = attr->allocatable ? allocatable : pointer; - standard = GFC_STD_F2003; - goto conflict_std; - } + conf_std (in_namelist, allocatable, GFC_STD_F2003); + conf_std (in_namelist, pointer, GFC_STD_F2003); /* Check for attributes not allowed in a BLOCK DATA. */ if (gfc_current_state () == COMP_BLOCK_DATA) @@ -922,20 +929,6 @@ conflict: a1, a2, name, where); return false; - -conflict_std: - if (name == NULL) - { - return gfc_notify_std (standard, "%s attribute conflicts " - "with %s attribute at %L", a1, a2, - where); - } - else - { - return gfc_notify_std (standard, "%s attribute conflicts " - "with %s attribute in %qs at %L", - a1, a2, name, where); - } } #undef conf |