aboutsummaryrefslogtreecommitdiff
path: root/gcc/fortran/parse.cc
diff options
context:
space:
mode:
authorPaul Thomas <pault@gcc.gnu.org>2023-11-02 22:23:05 +0000
committerPaul Thomas <pault@gcc.gnu.org>2023-11-02 22:23:05 +0000
commit7c1d011bc1f8b26dba4ebcbd4a429628dfb2698d (patch)
tree764d27b796c77b94c7c9199e21997f12bc9988e8 /gcc/fortran/parse.cc
parent341c633bd8ce4e4a82038873606c6b32e94ae339 (diff)
downloadgcc-7c1d011bc1f8b26dba4ebcbd4a429628dfb2698d.zip
gcc-7c1d011bc1f8b26dba4ebcbd4a429628dfb2698d.tar.gz
gcc-7c1d011bc1f8b26dba4ebcbd4a429628dfb2698d.tar.bz2
Fortran: Fix for regression in ASSOCIATE [PR112316]
2023-11-02 Paul Thomas <pault@gcc.gnu.org> gcc/fortran PR fortran/112316 * parse.cc (parse_associate): Remove condition that caused this regression. gcc/testsuite/ PR fortran/112316 * gfortran.dg/pr112316.f90: New test.
Diffstat (limited to 'gcc/fortran/parse.cc')
-rw-r--r--gcc/fortran/parse.cc96
1 files changed, 46 insertions, 50 deletions
diff --git a/gcc/fortran/parse.cc b/gcc/fortran/parse.cc
index e103ebe..abd3a42 100644
--- a/gcc/fortran/parse.cc
+++ b/gcc/fortran/parse.cc
@@ -5133,6 +5133,7 @@ parse_associate (void)
{
gfc_symbol* sym;
gfc_expr *target;
+ int rank;
if (gfc_get_sym_tree (a->name, NULL, &a->st, false))
gcc_unreachable ();
@@ -5196,62 +5197,57 @@ parse_associate (void)
}
}
- if (target->rank)
+ rank = target->rank;
+ /* Fixup cases where the ranks are mismatched. */
+ if (sym->ts.type == BT_CLASS && CLASS_DATA (sym))
{
- int rank = 0;
- rank = target->rank;
- /* When the rank is greater than zero then sym will be an array. */
- if (sym->ts.type == BT_CLASS && CLASS_DATA (sym))
+ if ((!CLASS_DATA (sym)->as && rank != 0)
+ || (CLASS_DATA (sym)->as
+ && CLASS_DATA (sym)->as->rank != rank))
{
- if ((!CLASS_DATA (sym)->as && rank != 0)
- || (CLASS_DATA (sym)->as
- && CLASS_DATA (sym)->as->rank != rank))
+ /* Don't just (re-)set the attr and as in the sym.ts,
+ because this modifies the target's attr and as. Copy the
+ data and do a build_class_symbol. */
+ symbol_attribute attr = CLASS_DATA (target)->attr;
+ int corank = gfc_get_corank (target);
+ gfc_typespec type;
+
+ if (rank || corank)
{
- /* Don't just (re-)set the attr and as in the sym.ts,
- because this modifies the target's attr and as. Copy the
- data and do a build_class_symbol. */
- symbol_attribute attr = CLASS_DATA (target)->attr;
- int corank = gfc_get_corank (target);
- gfc_typespec type;
-
- if (rank || corank)
- {
- as = gfc_get_array_spec ();
- as->type = AS_DEFERRED;
- as->rank = rank;
- as->corank = corank;
- attr.dimension = rank ? 1 : 0;
- attr.codimension = corank ? 1 : 0;
- }
- else
- {
- as = NULL;
- attr.dimension = attr.codimension = 0;
- }
- attr.class_ok = 0;
- type = CLASS_DATA (sym)->ts;
- if (!gfc_build_class_symbol (&type,
- &attr, &as))
- gcc_unreachable ();
- sym->ts = type;
- sym->ts.type = BT_CLASS;
- sym->attr.class_ok = 1;
+ as = gfc_get_array_spec ();
+ as->type = AS_DEFERRED;
+ as->rank = rank;
+ as->corank = corank;
+ attr.dimension = rank ? 1 : 0;
+ attr.codimension = corank ? 1 : 0;
}
else
- sym->attr.class_ok = 1;
- }
- else if ((!sym->as && rank != 0)
- || (sym->as && sym->as->rank != rank))
- {
- as = gfc_get_array_spec ();
- as->type = AS_DEFERRED;
- as->rank = rank;
- as->corank = gfc_get_corank (target);
- sym->as = as;
- sym->attr.dimension = 1;
- if (as->corank)
- sym->attr.codimension = 1;
+ {
+ as = NULL;
+ attr.dimension = attr.codimension = 0;
+ }
+ attr.class_ok = 0;
+ type = CLASS_DATA (sym)->ts;
+ if (!gfc_build_class_symbol (&type, &attr, &as))
+ gcc_unreachable ();
+ sym->ts = type;
+ sym->ts.type = BT_CLASS;
+ sym->attr.class_ok = 1;
}
+ else
+ sym->attr.class_ok = 1;
+ }
+ else if ((!sym->as && rank != 0)
+ || (sym->as && sym->as->rank != rank))
+ {
+ as = gfc_get_array_spec ();
+ as->type = AS_DEFERRED;
+ as->rank = rank;
+ as->corank = gfc_get_corank (target);
+ sym->as = as;
+ sym->attr.dimension = 1;
+ if (as->corank)
+ sym->attr.codimension = 1;
}
}