* [Patch, fortran] PR89462 - [11/12/13/14 Regression] gfortran loops in code generation
@ 2024-04-23 15:25 Paul Richard Thomas
2024-04-24 6:05 ` Paul Richard Thomas
0 siblings, 1 reply; 3+ messages in thread
From: Paul Richard Thomas @ 2024-04-23 15:25 UTC (permalink / raw)
To: fortran, gcc-patches; +Cc: jakub, Harald Anlauf
[-- Attachment #1.1: Type: text/plain, Size: 787 bytes --]
Hi All,
Jakub pinpointed the source of this bug in comment 6 of the PR. The rest
was 'obvious' :-)
I plan to push the patch to mainline in the next 24 hours unless there are
opinions to the contrary. Backporting is proposed to occur a couple of
weeks later.
Best regards
Paul
Fortran: Generate new charlens for shared symbol typespecs [PR89462]
2024-04-23 Paul Thomas <pault@gcc.gnu.org>
Jakub Jelinek <jakub@gcc.gnu.org>
gcc/fortran
PR fortran/89462
* decl.cc (build_sym): Add an extra argument 'elem'. If 'elem'
is greater than 1, gfc_new_charlen is called to generate a new
charlen, registered in the symbol namespace.
(variable_decl, enumerator_decl): Set the new argument in the
calls to build_sym.
gcc/testsuite/
PR fortran/89462
* gfortran.dg/pr89462.f90: New test.
[-- Attachment #2: submit.diff --]
[-- Type: text/x-patch, Size: 2179 bytes --]
diff --git a/gcc/fortran/decl.cc b/gcc/fortran/decl.cc
index a7576f4bc40..b8308aeee55 100644
--- a/gcc/fortran/decl.cc
+++ b/gcc/fortran/decl.cc
@@ -1713,7 +1713,7 @@ gfc_verify_c_interop_param (gfc_symbol *sym)
/* Function called by variable_decl() that adds a name to the symbol table. */
static bool
-build_sym (const char *name, gfc_charlen *cl, bool cl_deferred,
+build_sym (const char *name, int elem, gfc_charlen *cl, bool cl_deferred,
gfc_array_spec **as, locus *var_locus)
{
symbol_attribute attr;
@@ -1778,7 +1778,10 @@ build_sym (const char *name, gfc_charlen *cl, bool cl_deferred,
if (sym->ts.type == BT_CHARACTER)
{
- sym->ts.u.cl = cl;
+ if (elem > 1)
+ sym->ts.u.cl = gfc_new_charlen (sym->ns, cl);
+ else
+ sym->ts.u.cl = cl;
sym->ts.deferred = cl_deferred;
}
@@ -2960,7 +2963,7 @@ variable_decl (int elem)
create a symbol for those yet. If we fail to create the symbol,
bail out. */
if (!gfc_comp_struct (gfc_current_state ())
- && !build_sym (name, cl, cl_deferred, &as, &var_locus))
+ && !build_sym (name, elem, cl, cl_deferred, &as, &var_locus))
{
m = MATCH_ERROR;
goto cleanup;
@@ -10938,7 +10941,7 @@ enumerator_decl (void)
/* OK, we've successfully matched the declaration. Now put the
symbol in the current namespace. If we fail to create the symbol,
bail out. */
- if (!build_sym (name, NULL, false, &as, &var_locus))
+ if (!build_sym (name, 1, NULL, false, &as, &var_locus))
{
m = MATCH_ERROR;
goto cleanup;
diff --git a/gcc/testsuite/gfortran.dg/pr89462.f90 b/gcc/testsuite/gfortran.dg/pr89462.f90
new file mode 100644
index 00000000000..9efdb1adbc7
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr89462.f90
@@ -0,0 +1,12 @@
+! { dg-do compile }
+! Test the fix for PR89462 in which the shared 'cl' field of the typespec
+! shared between 'test', 'TR' and 'aTP' caused the compiler to go into an
+! infinite loop.
+! Contributed by Sergei Trofimovich <slyich@gmail.com>
+ CHARACTER*1 FUNCTION test(H)
+ CHARACTER*1 test2,TR,aTP
+ ENTRY test2(L)
+ CALL ttest3(aTP)
+ test = TR
+ RETURN
+ END
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Patch, fortran] PR89462 - [11/12/13/14 Regression] gfortran loops in code generation
2024-04-23 15:25 [Patch, fortran] PR89462 - [11/12/13/14 Regression] gfortran loops in code generation Paul Richard Thomas
@ 2024-04-24 6:05 ` Paul Richard Thomas
2024-04-24 6:10 ` Paul Richard Thomas
0 siblings, 1 reply; 3+ messages in thread
From: Paul Richard Thomas @ 2024-04-24 6:05 UTC (permalink / raw)
To: fortran, gcc-patches; +Cc: Harald Anlauf
[-- Attachment #1.1: Type: text/plain, Size: 1543 bytes --]
Hi,
The linaro pre-commit error testing picked up errors for arm and aarch
since they set the option -pedantic-errors.
/home/tcwg-build/workspace/tcwg_gnu_4/abe/snapshots/gcc.git~master/gcc/testsuite/gfortran.dg/pr89462.f90:6:14:
Warning: Obsolescent feature: Old-style character length at (1)
/home/tcwg-build/workspace/tcwg_gnu_4/abe/snapshots/gcc.git~master/gcc/testsuite/gfortran.dg/pr89462.f90:7:17:
Warning: Obsolescent feature: Old-style character length at (1)
I have added the option to the testcase together with the corresponding
warnings as in the attached.
I will wait for 24 hours more.
Paul
On Tue, 23 Apr 2024 at 16:25, Paul Richard Thomas <
paul.richard.thomas@gmail.com> wrote:
> Hi All,
>
> Jakub pinpointed the source of this bug in comment 6 of the PR. The rest
> was 'obvious' :-)
>
> I plan to push the patch to mainline in the next 24 hours unless there are
> opinions to the contrary. Backporting is proposed to occur a couple of
> weeks later.
>
> Best regards
>
> Paul
>
> Fortran: Generate new charlens for shared symbol typespecs [PR89462]
>
> 2024-04-23 Paul Thomas <pault@gcc.gnu.org>
> Jakub Jelinek <jakub@gcc.gnu.org>
>
> gcc/fortran
> PR fortran/89462
> * decl.cc (build_sym): Add an extra argument 'elem'. If 'elem'
> is greater than 1, gfc_new_charlen is called to generate a new
> charlen, registered in the symbol namespace.
> (variable_decl, enumerator_decl): Set the new argument in the
> calls to build_sym.
>
> gcc/testsuite/
> PR fortran/89462
> * gfortran.dg/pr89462.f90: New test.
>
>
[-- Attachment #2: submit.diff --]
[-- Type: text/x-patch, Size: 2984 bytes --]
diff --git a/gcc/fortran/decl.cc b/gcc/fortran/decl.cc
index a7576f4bc40..b8308aeee55 100644
--- a/gcc/fortran/decl.cc
+++ b/gcc/fortran/decl.cc
@@ -1713,7 +1713,7 @@ gfc_verify_c_interop_param (gfc_symbol *sym)
/* Function called by variable_decl() that adds a name to the symbol table. */
static bool
-build_sym (const char *name, gfc_charlen *cl, bool cl_deferred,
+build_sym (const char *name, int elem, gfc_charlen *cl, bool cl_deferred,
gfc_array_spec **as, locus *var_locus)
{
symbol_attribute attr;
@@ -1778,7 +1778,10 @@ build_sym (const char *name, gfc_charlen *cl, bool cl_deferred,
if (sym->ts.type == BT_CHARACTER)
{
- sym->ts.u.cl = cl;
+ if (elem > 1)
+ sym->ts.u.cl = gfc_new_charlen (sym->ns, cl);
+ else
+ sym->ts.u.cl = cl;
sym->ts.deferred = cl_deferred;
}
@@ -2960,7 +2963,7 @@ variable_decl (int elem)
create a symbol for those yet. If we fail to create the symbol,
bail out. */
if (!gfc_comp_struct (gfc_current_state ())
- && !build_sym (name, cl, cl_deferred, &as, &var_locus))
+ && !build_sym (name, elem, cl, cl_deferred, &as, &var_locus))
{
m = MATCH_ERROR;
goto cleanup;
@@ -10938,7 +10941,7 @@ enumerator_decl (void)
/* OK, we've successfully matched the declaration. Now put the
symbol in the current namespace. If we fail to create the symbol,
bail out. */
- if (!build_sym (name, NULL, false, &as, &var_locus))
+ if (!build_sym (name, 1, NULL, false, &as, &var_locus))
{
m = MATCH_ERROR;
goto cleanup;
diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 30b84762346..322ff552813 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -11756,8 +11756,16 @@ gfc_walk_variable_expr (gfc_ss * ss, gfc_expr * expr)
gfc_fix_class_refs (expr);
for (ref = expr->ref; ref; ref = ref->next)
- if (ref->type == REF_ARRAY && ref->u.ar.type != AR_ELEMENT)
- break;
+ {
+ if (ref->type == REF_COMPONENT
+ && ref->u.c.component->attr.function)
+ {
+ ref = NULL;
+ break;
+ }
+ if (ref->type == REF_ARRAY && ref->u.ar.type != AR_ELEMENT)
+ break;
+ }
return gfc_walk_array_ref (ss, expr, ref);
}
diff --git a/gcc/testsuite/gfortran.dg/pr89462.f90 b/gcc/testsuite/gfortran.dg/pr89462.f90
new file mode 100644
index 00000000000..b2a4912fcc8
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr89462.f90
@@ -0,0 +1,13 @@
+! { dg-do compile }
+! { dg-options "-pedantic-errors" }
+! Test the fix for PR89462 in which the shared 'cl' field of the typespec
+! shared between 'test', 'TR' and 'aTP' caused the compiler to go into an
+! infinite loop.
+! Contributed by Sergei Trofimovich <slyich@gmail.com>
+ CHARACTER*1 FUNCTION test(H) ! { dg-warning "Old-style character length" }
+ CHARACTER*1 test2,TR,aTP ! { dg-warning "Old-style character length" }
+ ENTRY test2(L)
+ CALL ttest3(aTP)
+ test = TR
+ RETURN
+ END
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Patch, fortran] PR89462 - [11/12/13/14 Regression] gfortran loops in code generation
2024-04-24 6:05 ` Paul Richard Thomas
@ 2024-04-24 6:10 ` Paul Richard Thomas
0 siblings, 0 replies; 3+ messages in thread
From: Paul Richard Thomas @ 2024-04-24 6:10 UTC (permalink / raw)
To: fortran, gcc-patches; +Cc: Harald Anlauf
[-- Attachment #1: Type: text/plain, Size: 1803 bytes --]
PS ignore the chunk in trans-array.cc. It is an attempt to fix PR93678 that
literally did nothing.
Paul
On Wed, 24 Apr 2024 at 07:05, Paul Richard Thomas <
paul.richard.thomas@gmail.com> wrote:
> Hi,
>
> The linaro pre-commit error testing picked up errors for arm and aarch
> since they set the option -pedantic-errors.
> /home/tcwg-build/workspace/tcwg_gnu_4/abe/snapshots/gcc.git~master/gcc/testsuite/gfortran.dg/pr89462.f90:6:14:
> Warning: Obsolescent feature: Old-style character length at (1)
> /home/tcwg-build/workspace/tcwg_gnu_4/abe/snapshots/gcc.git~master/gcc/testsuite/gfortran.dg/pr89462.f90:7:17:
> Warning: Obsolescent feature: Old-style character length at (1)
>
> I have added the option to the testcase together with the corresponding
> warnings as in the attached.
>
> I will wait for 24 hours more.
>
> Paul
>
> On Tue, 23 Apr 2024 at 16:25, Paul Richard Thomas <
> paul.richard.thomas@gmail.com> wrote:
>
>> Hi All,
>>
>> Jakub pinpointed the source of this bug in comment 6 of the PR. The rest
>> was 'obvious' :-)
>>
>> I plan to push the patch to mainline in the next 24 hours unless there
>> are opinions to the contrary. Backporting is proposed to occur a couple of
>> weeks later.
>>
>> Best regards
>>
>> Paul
>>
>> Fortran: Generate new charlens for shared symbol typespecs [PR89462]
>>
>> 2024-04-23 Paul Thomas <pault@gcc.gnu.org>
>> Jakub Jelinek <jakub@gcc.gnu.org>
>>
>> gcc/fortran
>> PR fortran/89462
>> * decl.cc (build_sym): Add an extra argument 'elem'. If 'elem'
>> is greater than 1, gfc_new_charlen is called to generate a new
>> charlen, registered in the symbol namespace.
>> (variable_decl, enumerator_decl): Set the new argument in the
>> calls to build_sym.
>>
>> gcc/testsuite/
>> PR fortran/89462
>> * gfortran.dg/pr89462.f90: New test.
>>
>>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-04-24 6:10 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-23 15:25 [Patch, fortran] PR89462 - [11/12/13/14 Regression] gfortran loops in code generation Paul Richard Thomas
2024-04-24 6:05 ` Paul Richard Thomas
2024-04-24 6:10 ` Paul Richard Thomas
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).