From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1431) id 0E9D9384640E; Thu, 25 Apr 2024 05:52:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0E9D9384640E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1714024379; bh=fdtfvapctsMGyyAFXkRbbzue1JoIvc+M7Kx2KOaYCU4=; h=From:To:Subject:Date:From; b=NvN8dMgr9T/PaG0TlE7hQvfravREaq7f2IZgLzUWwumtefNsFPSLBlivRdD8zVvXl MVZSW0yh9AD7QNvTeDzRZfzUiIEz40SUCBfwnbdwaF7K+SkcXGHVTZxmkXEjSQ/yNa Y/SSdcnN2IRDTIVyqGaSNP441VLBcWqXczG7SyRc= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Paul Thomas To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-10115] Fortran: Generate new charlens for shared symbol typespecs [PR89462] X-Act-Checkin: gcc X-Git-Author: Paul Thomas X-Git-Refname: refs/heads/master X-Git-Oldrev: 09680e3ee7d72978b493dd4127ce2e769f96a45e X-Git-Newrev: 1fd5a07444776d76cdd6a2eee7df0478201197a5 Message-Id: <20240425055259.0E9D9384640E@sourceware.org> Date: Thu, 25 Apr 2024 05:52:58 +0000 (GMT) List-Id: https://gcc.gnu.org/g:1fd5a07444776d76cdd6a2eee7df0478201197a5 commit r14-10115-g1fd5a07444776d76cdd6a2eee7df0478201197a5 Author: Paul Thomas Date: Thu Apr 25 06:52:31 2024 +0100 Fortran: Generate new charlens for shared symbol typespecs [PR89462] 2024-04-25 Paul Thomas Jakub Jelinek 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. Diff: --- gcc/fortran/decl.cc | 11 +++++++---- gcc/testsuite/gfortran.dg/pr89462.f90 | 13 +++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) 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..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 + 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