diff mbox series

[fortan] PR87103 - [OOP] ICE in gfc_new_symbol() due to overlong symbol name

Message ID 5056833.bhCz5HFUgy@andrew-precision-3520
State New
Headers show
Series [fortan] PR87103 - [OOP] ICE in gfc_new_symbol() due to overlong symbol name | expand

Commit Message

Andrew Benson Sept. 4, 2018, 4:43 p.m. UTC
As suggested by Janus, PR87103 is easily fixed by the attached patch which 
increases GFC_MAX_SYMBOL_LEN to 76 (sufficient to hold the maximum allowed F08 
symbol length of 63, plus a null terminator, plus the "__tmp_class_" prefix).

Bootstraps and regtests successfully.

OK for trunk?

-Andrew

On Saturday, August 25, 2018 1:50:57 PM PDT Andrew Benson wrote:
> I just opened PR for this: 87103
> 
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87103
> 
> The following code causes an ICE with gfortan 9.0.0 (r263855):
> 
> module a
>   type :: nameThatIsVeryLongButNotTooLongThatItShouldBeInvalid
>   end type nameThatIsVeryLongButNotTooLongThatItShouldBeInvalid
> contains
>   subroutine b(self)
>     class(nameThatIsVeryLongButNotTooLongThatItShouldBeInvalid), intent(in)
> :: self
>     select type (self)
>     class is (nameThatIsVeryLongButNotTooLongThatItShouldBeInvalid)
>     end select
>   end subroutine b
> end module a
> 
> $ gfortran -v
> Using built-in specs.
> COLLECT_GCC=gfortran
> COLLECT_LTO_WRAPPER=/home/abenson/Galacticus/Tools/libexec/gcc/x86_64-pc-
> linux-gnu/9.0.0/lto-wrapper
> Target: x86_64-pc-linux-gnu
> Configured with: ../gcc-trunk/configure
> --prefix=/home/abenson/Galacticus/Tools --enable-languages=c,c++,fortran
> --disable-multilib : (reconfigured) ../gcc- trunk/configure
> --prefix=/home/abenson/Galacticus/Tools --enable-languages=c,c+ +,fortran
> --disable-multilib : (reconfigured) ../gcc-trunk/configure --prefix=/
> home/abenson/Galacticus/Tools --disable-multilib --enable-languages=c,c+
> +,fortran,lto --no-create --no-recursion : (reconfigured)
> ../gcc-trunk/configure --prefix=/home/abenson/Galacticus/Tools
> --disable-multilib --enable- languages=c,c++,fortran,lto --no-create
> --no-recursion : (reconfigured) ../gcc- trunk/configure
> --prefix=/home/abenson/Galacticus/Tools --disable-multilib --
> enable-languages=c,c++,fortran,lto --no-create --no-recursion
> Thread model: posix
> gcc version 9.0.0 20180825 (experimental) (GCC)
> 
> 
> $ gfortran -c tmp1.F90 -o tmp1.o
> f951: internal compiler error: new_symbol(): Symbol name too long
> 0x7b9711 gfc_internal_error(char const*, ...)
>         ../../gcc-trunk/gcc/fortran/error.c:1362
> 0x84a838 gfc_new_symbol(char const*, gfc_namespace*)
>         ../../gcc-trunk/gcc/fortran/symbol.c:3132
> 0x84ab97 gfc_get_sym_tree(char const*, gfc_namespace*, gfc_symtree**, bool)
>         ../../gcc-trunk/gcc/fortran/symbol.c:3373
> 0x7e565d select_type_set_tmp
>         ../../gcc-trunk/gcc/fortran/match.c:6114
> 0x7ee260 gfc_match_class_is()
>         ../../gcc-trunk/gcc/fortran/match.c:6470
> 0x808c79 match_word
>         ../../gcc-trunk/gcc/fortran/parse.c:65
> 0x80a4f1 decode_statement
>         ../../gcc-trunk/gcc/fortran/parse.c:462
> 0x80d04c next_free
>         ../../gcc-trunk/gcc/fortran/parse.c:1234
> 0x80d04c next_statement
>         ../../gcc-trunk/gcc/fortran/parse.c:1466
> 0x810861 parse_select_type_block
>         ../../gcc-trunk/gcc/fortran/parse.c:4236
> 0x810861 parse_executable
>         ../../gcc-trunk/gcc/fortran/parse.c:5330
> 0x8118e6 parse_progunit
>         ../../gcc-trunk/gcc/fortran/parse.c:5697
> 0x811bfc parse_contained
>         ../../gcc-trunk/gcc/fortran/parse.c:5574
> 0x812a4c parse_module
>         ../../gcc-trunk/gcc/fortran/parse.c:5944
> 0x812f75 gfc_parse_file()
>         ../../gcc-trunk/gcc/fortran/parse.c:6247
> 0x859d3f gfc_be_parse_file
>         ../../gcc-trunk/gcc/fortran/f95-lang.c:204
> Please submit a full bug report,
> with preprocessed source if appropriate.
> Please include the complete backtrace with any bug report.
> See <https://gcc.gnu.org/bugs/> for instructions.
> 
> 
> The problem seems to be that gfc_new_symbol() is passed a name
> '__tmp_class_namethatisverylongbutnottoolongthatitshouldbeinvalid' in this
> case which exceeds GFC_MAX_SYMBOL_LEN=64. My understanding is that the code
> is valid since the symbol name itself,
> 'namethatisverylongbutnottoolongthatitshouldbeinvalid', is less than 64
> characters.
> 
> I'm not sure what the correct fix for this is - should the name length limit
> in gfc_new_symbol() just be increased by enough to allow the '__tmp_class_'
> prefix?
> 
> This appears to be a regression as the same code (with the same long-but-
> legal) symbol names compiled under earlier versions of gfortran. I'll
> attempt to rollback to previous versions and see if I can identify where
> the change occurred.
> 
> -Andrew

Comments

Bernhard Reutner-Fischer Sept. 4, 2018, 5:43 p.m. UTC | #1
On Tue, 4 Sep 2018 at 18:43, Andrew Benson <abenson@carnegiescience.edu> wrote:
>
> As suggested by Janus, PR87103 is easily fixed by the attached patch which
> increases GFC_MAX_SYMBOL_LEN to 76 (sufficient to hold the maximum allowed F08
> symbol length of 63, plus a null terminator, plus the "__tmp_class_" prefix).

This is so much wrong.
Note that this will be fixed properly by the changes contained in the
https://gcc.gnu.org/git/?p=gcc.git;a=shortlog;h=refs/heads/aldot/fortran-fe-stringpool
branch.
There we keep the GFC_MAX_SYMBOL_LEN at 63 proper but use an internal
buffer double that size which in turn is sufficient to hold all
compiler-generated identifiers.
See gfc_get_string() even in current TOT.

Maybe we should bite the bullet and start to merge the stringpool
changes now instead of this hack?

thanks and cheers,
Bernhard Reutner-Fischer Sept. 5, 2018, 10:35 a.m. UTC | #2
On Wed, 5 Sep 2018 at 03:30, Jerry DeLisle <jvdelisle@charter.net> wrote:
>
> On 09/04/2018 10:43 AM, Bernhard Reutner-Fischer wrote:
> > On Tue, 4 Sep 2018 at 18:43, Andrew Benson <abenson@carnegiescience.edu> wrote:
> >>
> >> As suggested by Janus, PR87103 is easily fixed by the attached patch which
> >> increases GFC_MAX_SYMBOL_LEN to 76 (sufficient to hold the maximum allowed F08
> >> symbol length of 63, plus a null terminator, plus the "__tmp_class_" prefix).
> >
> > This is so much wrong.
> > Note that this will be fixed properly by the changes contained in the
> > https://gcc.gnu.org/git/?p=gcc.git;a=shortlog;h=refs/heads/aldot/fortran-fe-stringpool
> > branch.
> > There we keep the GFC_MAX_SYMBOL_LEN at 63 proper but use an internal
> > buffer double that size which in turn is sufficient to hold all
> > compiler-generated identifiers.
> > See gfc_get_string() even in current TOT.
> >
> > Maybe we should bite the bullet and start to merge the stringpool
> > changes now instead of this hack?
>
> It all makes sense to me, please proceed. (my 2 cents worth)

Ok so i will reread the fortran-fe-stringpool series and submit it
here for review.

Let's return to the issue at hand for a moment, though.
I tested the attached alternate fix on top of the
fortran-fe-stringpool branch where it fixes PR87103.
Maybe somebody has spare cycles to test it on top of current trunk?

thanks,

[PATCH,FORTRAN] PR87103: Remove max symbol length check from gfc_new_symbol

gfc_match_name does check for too long names already. Since
gfc_new_symbol is also called for symbols with internal names containing
compiler-generated prefixes, these internal names can easily exceed the
max_identifier_length mandated by the standard.

gcc/fortran/ChangeLog

2018-09-04  Bernhard Reutner-Fischer  <aldot@gcc.gnu.org>

PR fortran/87103
* expr.c (gfc_check_conformance): Check vsnprintf for truncation.
* iresolve.c (gfc_get_string): Likewise.
* symbol.c (gfc_new_symbol): Remove check for maximum symbol
name length.  Remove redundant 0 setting of new calloc()ed
gfc_symbol.
Remove max symbol length check from gfc_new_symbol

gfc_match_name does check for too long names already. Since
gfc_new_symbol is also called for symbols with internal names containing
compiler-generated prefixes, these internal names can easily exceed the
max_identifier_length mandated by the standard.

gcc/fortran/ChangeLog

2018-09-04  Bernhard Reutner-Fischer  <aldot@gcc.gnu.org>

	PR fortran/87103
	* expr.c (gfc_check_conformance): Check vsnprintf for truncation.
	* iresolve.c (gfc_get_string): Likewise.
	* symbol.c (gfc_new_symbol): Remove check for maximum symbol
	name length.  Remove redundant 0 setting of new calloc()ed
	gfc_symbol.

diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c
index c5bf822cd24..6b5671390ec 100644
--- a/gcc/fortran/expr.c
+++ b/gcc/fortran/expr.c
@@ -3225,8 +3225,10 @@ gfc_check_conformance (gfc_expr *op1, gfc_expr *op2, const char *optype_msgid, .
     return true;
 
   va_start (argp, optype_msgid);
-  vsnprintf (buffer, 240, optype_msgid, argp);
+  d = vsnprintf (buffer, sizeof (buffer), optype_msgid, argp);
   va_end (argp);
+  if (d < 1 || d >= (int) sizeof (buffer)) /* Reject truncation.  */
+    gfc_internal_error ("optype_msgid overflow: %d", d);
 
   if (op1->rank != op2->rank)
     {
diff --git a/gcc/fortran/iresolve.c b/gcc/fortran/iresolve.c
index 61663fec7e5..d7bd0545173 100644
--- a/gcc/fortran/iresolve.c
+++ b/gcc/fortran/iresolve.c
@@ -60,9 +60,12 @@ gfc_get_string (const char *format, ...)
     }
   else
     {
+      int ret;
       va_start (ap, format);
-      vsnprintf (temp_name, sizeof (temp_name), format, ap);
+      ret = vsnprintf (temp_name, sizeof (temp_name), format, ap);
       va_end (ap);
+      if (ret < 1 || ret >= (int) sizeof (temp_name)) /* Reject truncation.  */
+	gfc_internal_error ("identifier overflow: %d", ret);
       temp_name[sizeof (temp_name) - 1] = 0;
       str = temp_name;
     }
diff --git a/gcc/fortran/symbol.c b/gcc/fortran/symbol.c
index cde34c67482..fc3354f0457 100644
--- a/gcc/fortran/symbol.c
+++ b/gcc/fortran/symbol.c
@@ -3142,25 +3142,9 @@ gfc_new_symbol (const char *name, gfc_namespace *ns)
   gfc_clear_ts (&p->ts);
   gfc_clear_attr (&p->attr);
   p->ns = ns;
-
   p->declared_at = gfc_current_locus;
-
-  if (strlen (name) > GFC_MAX_SYMBOL_LEN)
-    gfc_internal_error ("new_symbol(): Symbol name too long");
-
   p->name = gfc_get_string ("%s", name);
 
-  /* Make sure flags for symbol being C bound are clear initially.  */
-  p->attr.is_bind_c = 0;
-  p->attr.is_iso_c = 0;
-
-  /* Clear the ptrs we may need.  */
-  p->common_block = NULL;
-  p->f2k_derived = NULL;
-  p->assoc = NULL;
-  p->dt_next = NULL;
-  p->fn_result_spec = 0;
-
   return p;
 }
Andrew Benson Sept. 5, 2018, 2:24 p.m. UTC | #3
On Wednesday, September 5, 2018 12:35:04 PM PDT Bernhard Reutner-Fischer 
wrote:
> On Wed, 5 Sep 2018 at 03:30, Jerry DeLisle <jvdelisle@charter.net> wrote:
> > On 09/04/2018 10:43 AM, Bernhard Reutner-Fischer wrote:
> > > On Tue, 4 Sep 2018 at 18:43, Andrew Benson <abenson@carnegiescience.edu> 
wrote:
> > >> As suggested by Janus, PR87103 is easily fixed by the attached patch
> > >> which
> > >> increases GFC_MAX_SYMBOL_LEN to 76 (sufficient to hold the maximum
> > >> allowed F08 symbol length of 63, plus a null terminator, plus the
> > >> "__tmp_class_" prefix).> > 
> > > This is so much wrong.
> > > Note that this will be fixed properly by the changes contained in the
> > > https://gcc.gnu.org/git/?p=gcc.git;a=shortlog;h=refs/heads/aldot/fortran
> > > -fe-stringpool branch.
> > > There we keep the GFC_MAX_SYMBOL_LEN at 63 proper but use an internal
> > > buffer double that size which in turn is sufficient to hold all
> > > compiler-generated identifiers.
> > > See gfc_get_string() even in current TOT.
> > > 
> > > Maybe we should bite the bullet and start to merge the stringpool
> > > changes now instead of this hack?
> > 
> > It all makes sense to me, please proceed. (my 2 cents worth)
> 
> Ok so i will reread the fortran-fe-stringpool series and submit it
> here for review.
> 
> Let's return to the issue at hand for a moment, though.
> I tested the attached alternate fix on top of the
> fortran-fe-stringpool branch where it fixes PR87103.
> Maybe somebody has spare cycles to test it on top of current trunk?
> 
> thanks,
> 
> [PATCH,FORTRAN] PR87103: Remove max symbol length check from gfc_new_symbol
> 
> gfc_match_name does check for too long names already. Since
> gfc_new_symbol is also called for symbols with internal names containing
> compiler-generated prefixes, these internal names can easily exceed the
> max_identifier_length mandated by the standard.
> 
> gcc/fortran/ChangeLog
> 
> 2018-09-04  Bernhard Reutner-Fischer  <aldot@gcc.gnu.org>
> 
> PR fortran/87103
> * expr.c (gfc_check_conformance): Check vsnprintf for truncation.
> * iresolve.c (gfc_get_string): Likewise.
> * symbol.c (gfc_new_symbol): Remove check for maximum symbol
> name length.  Remove redundant 0 setting of new calloc()ed
> gfc_symbol.

This patch tests successfully on the current trunk for me.
Andrew Benson Aug. 24, 2019, 12:17 a.m. UTC | #4
This PR is still open - I re-tested the patch on the current trunk. The patch 
still applies with some line offsets (I've attached the updated patch) and 
regtests cleanly. It would be very helpful to me to get this patch committed 
if possible.

Thanks,
Andrew

On Wednesday, September 5, 2018 12:35:04 PM PDT Bernhard Reutner-Fischer 
wrote:
> On Wed, 5 Sep 2018 at 03:30, Jerry DeLisle <jvdelisle@charter.net> wrote:
> > On 09/04/2018 10:43 AM, Bernhard Reutner-Fischer wrote:
> > > On Tue, 4 Sep 2018 at 18:43, Andrew Benson <abenson@carnegiescience.edu> 
wrote:
> > >> As suggested by Janus, PR87103 is easily fixed by the attached patch
> > >> which
> > >> increases GFC_MAX_SYMBOL_LEN to 76 (sufficient to hold the maximum
> > >> allowed F08 symbol length of 63, plus a null terminator, plus the
> > >> "__tmp_class_" prefix).> > 
> > > This is so much wrong.
> > > Note that this will be fixed properly by the changes contained in the
> > > https://gcc.gnu.org/git/?p=gcc.git;a=shortlog;h=refs/heads/aldot/fortran
> > > -fe-stringpool branch.
> > > There we keep the GFC_MAX_SYMBOL_LEN at 63 proper but use an internal
> > > buffer double that size which in turn is sufficient to hold all
> > > compiler-generated identifiers.
> > > See gfc_get_string() even in current TOT.
> > > 
> > > Maybe we should bite the bullet and start to merge the stringpool
> > > changes now instead of this hack?
> > 
> > It all makes sense to me, please proceed. (my 2 cents worth)
> 
> Ok so i will reread the fortran-fe-stringpool series and submit it
> here for review.
> 
> Let's return to the issue at hand for a moment, though.
> I tested the attached alternate fix on top of the
> fortran-fe-stringpool branch where it fixes PR87103.
> Maybe somebody has spare cycles to test it on top of current trunk?
> 
> thanks,
> 
> [PATCH,FORTRAN] PR87103: Remove max symbol length check from gfc_new_symbol
> 
> gfc_match_name does check for too long names already. Since
> gfc_new_symbol is also called for symbols with internal names containing
> compiler-generated prefixes, these internal names can easily exceed the
> max_identifier_length mandated by the standard.
> 
> gcc/fortran/ChangeLog
> 
> 2018-09-04  Bernhard Reutner-Fischer  <aldot@gcc.gnu.org>
> 
> PR fortran/87103
> * expr.c (gfc_check_conformance): Check vsnprintf for truncation.
> * iresolve.c (gfc_get_string): Likewise.
> * symbol.c (gfc_new_symbol): Remove check for maximum symbol
> name length.  Remove redundant 0 setting of new calloc()ed
> gfc_symbol.
Bernhard Reutner-Fischer Aug. 28, 2019, 7 p.m. UTC | #5
On Fri, 23 Aug 2019 17:17:37 -0700
Andrew Benson <abenson@carnegiescience.edu> wrote:

> This PR is still open - I re-tested the patch on the current trunk. The patch 
> still applies with some line offsets (I've attached the updated patch) and 
> regtests cleanly. It would be very helpful to me to get this patch committed 
> if possible.

I think Jerry ACKed the patch back then. I'll try to find the time to
commit it maybe during one of the coming weekends unless someone else
beats me to it..

Thanks for the reminder!
Bernhard
> 
> Thanks,
> Andrew
> 
> On Wednesday, September 5, 2018 12:35:04 PM PDT Bernhard Reutner-Fischer 
> wrote:
> > On Wed, 5 Sep 2018 at 03:30, Jerry DeLisle <jvdelisle@charter.net> wrote:  
> > > On 09/04/2018 10:43 AM, Bernhard Reutner-Fischer wrote:  
> > > > On Tue, 4 Sep 2018 at 18:43, Andrew Benson <abenson@carnegiescience.edu>   
> wrote:
> > > >> As suggested by Janus, PR87103 is easily fixed by the attached patch
> > > >> which
> > > >> increases GFC_MAX_SYMBOL_LEN to 76 (sufficient to hold the maximum
> > > >> allowed F08 symbol length of 63, plus a null terminator, plus the
> > > >> "__tmp_class_" prefix).> >   
> > > > This is so much wrong.
> > > > Note that this will be fixed properly by the changes contained in the
> > > > https://gcc.gnu.org/git/?p=gcc.git;a=shortlog;h=refs/heads/aldot/fortran
> > > > -fe-stringpool branch.
> > > > There we keep the GFC_MAX_SYMBOL_LEN at 63 proper but use an internal
> > > > buffer double that size which in turn is sufficient to hold all
> > > > compiler-generated identifiers.
> > > > See gfc_get_string() even in current TOT.
> > > > 
> > > > Maybe we should bite the bullet and start to merge the stringpool
> > > > changes now instead of this hack?  
> > > 
> > > It all makes sense to me, please proceed. (my 2 cents worth)  
> > 
> > Ok so i will reread the fortran-fe-stringpool series and submit it
> > here for review.
> > 
> > Let's return to the issue at hand for a moment, though.
> > I tested the attached alternate fix on top of the
> > fortran-fe-stringpool branch where it fixes PR87103.
> > Maybe somebody has spare cycles to test it on top of current trunk?
> > 
> > thanks,
> > 
> > [PATCH,FORTRAN] PR87103: Remove max symbol length check from gfc_new_symbol
> > 
> > gfc_match_name does check for too long names already. Since
> > gfc_new_symbol is also called for symbols with internal names containing
> > compiler-generated prefixes, these internal names can easily exceed the
> > max_identifier_length mandated by the standard.
> > 
> > gcc/fortran/ChangeLog
> > 
> > 2018-09-04  Bernhard Reutner-Fischer  <aldot@gcc.gnu.org>
> > 
> > PR fortran/87103
> > * expr.c (gfc_check_conformance): Check vsnprintf for truncation.
> > * iresolve.c (gfc_get_string): Likewise.
> > * symbol.c (gfc_new_symbol): Remove check for maximum symbol
> > name length.  Remove redundant 0 setting of new calloc()ed
> > gfc_symbol.  
> 
>
Andrew Benson Aug. 28, 2019, 7:02 p.m. UTC | #6
Thanks Bernhard.

On Wednesday, August 28, 2019 9:00:36 PM PDT Bernhard Reutner-Fischer wrote:
> On Fri, 23 Aug 2019 17:17:37 -0700
> 
> Andrew Benson <abenson@carnegiescience.edu> wrote:
> > This PR is still open - I re-tested the patch on the current trunk. The
> > patch still applies with some line offsets (I've attached the updated
> > patch) and regtests cleanly. It would be very helpful to me to get this
> > patch committed if possible.
> 
> I think Jerry ACKed the patch back then. I'll try to find the time to
> commit it maybe during one of the coming weekends unless someone else
> beats me to it..
> 
> Thanks for the reminder!
> Bernhard
> 
> > Thanks,
> > Andrew
> > 
> > On Wednesday, September 5, 2018 12:35:04 PM PDT Bernhard Reutner-Fischer
> > 
> > wrote:
> > > On Wed, 5 Sep 2018 at 03:30, Jerry DeLisle <jvdelisle@charter.net> 
wrote:
> > > > On 09/04/2018 10:43 AM, Bernhard Reutner-Fischer wrote:
> > > > > On Tue, 4 Sep 2018 at 18:43, Andrew Benson
> > > > > <abenson@carnegiescience.edu>
> > 
> > wrote:
> > > > >> As suggested by Janus, PR87103 is easily fixed by the attached
> > > > >> patch
> > > > >> which
> > > > >> increases GFC_MAX_SYMBOL_LEN to 76 (sufficient to hold the maximum
> > > > >> allowed F08 symbol length of 63, plus a null terminator, plus the
> > > > >> "__tmp_class_" prefix).> >
> > > > > 
> > > > > This is so much wrong.
> > > > > Note that this will be fixed properly by the changes contained in
> > > > > the
> > > > > https://gcc.gnu.org/git/?p=gcc.git;a=shortlog;h=refs/heads/aldot/for
> > > > > tran
> > > > > -fe-stringpool branch.
> > > > > There we keep the GFC_MAX_SYMBOL_LEN at 63 proper but use an
> > > > > internal
> > > > > buffer double that size which in turn is sufficient to hold all
> > > > > compiler-generated identifiers.
> > > > > See gfc_get_string() even in current TOT.
> > > > > 
> > > > > Maybe we should bite the bullet and start to merge the stringpool
> > > > > changes now instead of this hack?
> > > > 
> > > > It all makes sense to me, please proceed. (my 2 cents worth)
> > > 
> > > Ok so i will reread the fortran-fe-stringpool series and submit it
> > > here for review.
> > > 
> > > Let's return to the issue at hand for a moment, though.
> > > I tested the attached alternate fix on top of the
> > > fortran-fe-stringpool branch where it fixes PR87103.
> > > Maybe somebody has spare cycles to test it on top of current trunk?
> > > 
> > > thanks,
> > > 
> > > [PATCH,FORTRAN] PR87103: Remove max symbol length check from
> > > gfc_new_symbol
> > > 
> > > gfc_match_name does check for too long names already. Since
> > > gfc_new_symbol is also called for symbols with internal names containing
> > > compiler-generated prefixes, these internal names can easily exceed the
> > > max_identifier_length mandated by the standard.
> > > 
> > > gcc/fortran/ChangeLog
> > > 
> > > 2018-09-04  Bernhard Reutner-Fischer  <aldot@gcc.gnu.org>
> > > 
> > > PR fortran/87103
> > > * expr.c (gfc_check_conformance): Check vsnprintf for truncation.
> > > * iresolve.c (gfc_get_string): Likewise.
> > > * symbol.c (gfc_new_symbol): Remove check for maximum symbol
> > > name length.  Remove redundant 0 setting of new calloc()ed
> > > gfc_symbol.
Andrew Benson Jan. 29, 2020, 8:19 p.m. UTC | #7
I think this patch is still waiting to be applied. I checked that it applies 
against trunk (with line offsets) and reg tests cleanly and posted an updated 
version (diff'd against current trunk) at:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87103#c7

I'm happy to go ahead and commit this if Bernhard is ok with me doing so.

-Andrew

On Wednesday, August 28, 2019 9:00:36 PM PST Bernhard Reutner-Fischer wrote:
> On Fri, 23 Aug 2019 17:17:37 -0700
> 
> Andrew Benson <abenson@carnegiescience.edu> wrote:
> > This PR is still open - I re-tested the patch on the current trunk. The
> > patch still applies with some line offsets (I've attached the updated
> > patch) and regtests cleanly. It would be very helpful to me to get this
> > patch committed if possible.
> 
> I think Jerry ACKed the patch back then. I'll try to find the time to
> commit it maybe during one of the coming weekends unless someone else
> beats me to it..
> 
> Thanks for the reminder!
> Bernhard
> 
> > Thanks,
> > Andrew
> > 
> > On Wednesday, September 5, 2018 12:35:04 PM PDT Bernhard Reutner-Fischer
> > 
> > wrote:
> > > On Wed, 5 Sep 2018 at 03:30, Jerry DeLisle <jvdelisle@charter.net> 
wrote:
> > > > On 09/04/2018 10:43 AM, Bernhard Reutner-Fischer wrote:
> > > > > On Tue, 4 Sep 2018 at 18:43, Andrew Benson
> > > > > <abenson@carnegiescience.edu>
> > 
> > wrote:
> > > > >> As suggested by Janus, PR87103 is easily fixed by the attached
> > > > >> patch
> > > > >> which
> > > > >> increases GFC_MAX_SYMBOL_LEN to 76 (sufficient to hold the maximum
> > > > >> allowed F08 symbol length of 63, plus a null terminator, plus the
> > > > >> "__tmp_class_" prefix).> >
> > > > > 
> > > > > This is so much wrong.
> > > > > Note that this will be fixed properly by the changes contained in
> > > > > the
> > > > > https://gcc.gnu.org/git/?p=gcc.git;a=shortlog;h=refs/heads/aldot/for
> > > > > tran
> > > > > -fe-stringpool branch.
> > > > > There we keep the GFC_MAX_SYMBOL_LEN at 63 proper but use an
> > > > > internal
> > > > > buffer double that size which in turn is sufficient to hold all
> > > > > compiler-generated identifiers.
> > > > > See gfc_get_string() even in current TOT.
> > > > > 
> > > > > Maybe we should bite the bullet and start to merge the stringpool
> > > > > changes now instead of this hack?
> > > > 
> > > > It all makes sense to me, please proceed. (my 2 cents worth)
> > > 
> > > Ok so i will reread the fortran-fe-stringpool series and submit it
> > > here for review.
> > > 
> > > Let's return to the issue at hand for a moment, though.
> > > I tested the attached alternate fix on top of the
> > > fortran-fe-stringpool branch where it fixes PR87103.
> > > Maybe somebody has spare cycles to test it on top of current trunk?
> > > 
> > > thanks,
> > > 
> > > [PATCH,FORTRAN] PR87103: Remove max symbol length check from
> > > gfc_new_symbol
> > > 
> > > gfc_match_name does check for too long names already. Since
> > > gfc_new_symbol is also called for symbols with internal names containing
> > > compiler-generated prefixes, these internal names can easily exceed the
> > > max_identifier_length mandated by the standard.
> > > 
> > > gcc/fortran/ChangeLog
> > > 
> > > 2018-09-04  Bernhard Reutner-Fischer  <aldot@gcc.gnu.org>
> > > 
> > > PR fortran/87103
> > > * expr.c (gfc_check_conformance): Check vsnprintf for truncation.
> > > * iresolve.c (gfc_get_string): Likewise.
> > > * symbol.c (gfc_new_symbol): Remove check for maximum symbol
> > > name length.  Remove redundant 0 setting of new calloc()ed
> > > gfc_symbol.
Bernhard Reutner-Fischer Jan. 30, 2020, 4:27 p.m. UTC | #8
On 29 January 2020 21:19:52 CET, Andrew Benson <abenson@carnegiescience.edu> wrote:
>I think this patch is still waiting to be applied. I checked that it
>applies 
>against trunk (with line offsets) and reg tests cleanly and posted an
>updated 
>version (diff'd against current trunk) at:
>
>https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87103#c7
>
>I'm happy to go ahead and commit this if Bernhard is ok with me doing
>so.

Please go ahead and push it.
Many thanks in advance and sorry for the delay!
thanks,
>
>-Andrew
>
>On Wednesday, August 28, 2019 9:00:36 PM PST Bernhard Reutner-Fischer
>wrote:
>> On Fri, 23 Aug 2019 17:17:37 -0700
>> 
>> Andrew Benson <abenson@carnegiescience.edu> wrote:
>> > This PR is still open - I re-tested the patch on the current trunk.
>The
>> > patch still applies with some line offsets (I've attached the
>updated
>> > patch) and regtests cleanly. It would be very helpful to me to get
>this
>> > patch committed if possible.
>> 
>> I think Jerry ACKed the patch back then. I'll try to find the time to
>> commit it maybe during one of the coming weekends unless someone else
>> beats me to it..
>> 
>> Thanks for the reminder!
>> Bernhard
>> 
>> > Thanks,
>> > Andrew
>> > 
>> > On Wednesday, September 5, 2018 12:35:04 PM PDT Bernhard
>Reutner-Fischer
>> > 
>> > wrote:
>> > > On Wed, 5 Sep 2018 at 03:30, Jerry DeLisle
><jvdelisle@charter.net> 
>wrote:
>> > > > On 09/04/2018 10:43 AM, Bernhard Reutner-Fischer wrote:
>> > > > > On Tue, 4 Sep 2018 at 18:43, Andrew Benson
>> > > > > <abenson@carnegiescience.edu>
>> > 
>> > wrote:
>> > > > >> As suggested by Janus, PR87103 is easily fixed by the
>attached
>> > > > >> patch
>> > > > >> which
>> > > > >> increases GFC_MAX_SYMBOL_LEN to 76 (sufficient to hold the
>maximum
>> > > > >> allowed F08 symbol length of 63, plus a null terminator,
>plus the
>> > > > >> "__tmp_class_" prefix).> >
>> > > > > 
>> > > > > This is so much wrong.
>> > > > > Note that this will be fixed properly by the changes
>contained in
>> > > > > the
>> > > > >
>https://gcc.gnu.org/git/?p=gcc.git;a=shortlog;h=refs/heads/aldot/for
>> > > > > tran
>> > > > > -fe-stringpool branch.
>> > > > > There we keep the GFC_MAX_SYMBOL_LEN at 63 proper but use an
>> > > > > internal
>> > > > > buffer double that size which in turn is sufficient to hold
>all
>> > > > > compiler-generated identifiers.
>> > > > > See gfc_get_string() even in current TOT.
>> > > > > 
>> > > > > Maybe we should bite the bullet and start to merge the
>stringpool
>> > > > > changes now instead of this hack?
>> > > > 
>> > > > It all makes sense to me, please proceed. (my 2 cents worth)
>> > > 
>> > > Ok so i will reread the fortran-fe-stringpool series and submit
>it
>> > > here for review.
>> > > 
>> > > Let's return to the issue at hand for a moment, though.
>> > > I tested the attached alternate fix on top of the
>> > > fortran-fe-stringpool branch where it fixes PR87103.
>> > > Maybe somebody has spare cycles to test it on top of current
>trunk?
>> > > 
>> > > thanks,
>> > > 
>> > > [PATCH,FORTRAN] PR87103: Remove max symbol length check from
>> > > gfc_new_symbol
>> > > 
>> > > gfc_match_name does check for too long names already. Since
>> > > gfc_new_symbol is also called for symbols with internal names
>containing
>> > > compiler-generated prefixes, these internal names can easily
>exceed the
>> > > max_identifier_length mandated by the standard.
>> > > 
>> > > gcc/fortran/ChangeLog
>> > > 
>> > > 2018-09-04  Bernhard Reutner-Fischer  <aldot@gcc.gnu.org>
>> > > 
>> > > PR fortran/87103
>> > > * expr.c (gfc_check_conformance): Check vsnprintf for truncation.
>> > > * iresolve.c (gfc_get_string): Likewise.
>> > > * symbol.c (gfc_new_symbol): Remove check for maximum symbol
>> > > name length.  Remove redundant 0 setting of new calloc()ed
>> > > gfc_symbol.
Andrew Benson Jan. 30, 2020, 5:49 p.m. UTC | #9
Thanks Bernhard - this is now committed:

https://gcc.gnu.org/g:004ac7b780308dc899e565b887c7def0a6e100f2

On Thursday, January 30, 2020 5:27:55 PM PST Bernhard Reutner-Fischer wrote:
> On 29 January 2020 21:19:52 CET, Andrew Benson <abenson@carnegiescience.edu> 
wrote:
> >I think this patch is still waiting to be applied. I checked that it
> >applies
> >against trunk (with line offsets) and reg tests cleanly and posted an
> >updated
> >version (diff'd against current trunk) at:
> >
> >https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87103#c7
> >
> >I'm happy to go ahead and commit this if Bernhard is ok with me doing
> >so.
> 
> Please go ahead and push it.
> Many thanks in advance and sorry for the delay!
> thanks,
> 
> >-Andrew
> >
> >On Wednesday, August 28, 2019 9:00:36 PM PST Bernhard Reutner-Fischer
> >
> >wrote:
> >> On Fri, 23 Aug 2019 17:17:37 -0700
> >> 
> >> Andrew Benson <abenson@carnegiescience.edu> wrote:
> >> > This PR is still open - I re-tested the patch on the current trunk.
> >
> >The
> >
> >> > patch still applies with some line offsets (I've attached the
> >
> >updated
> >
> >> > patch) and regtests cleanly. It would be very helpful to me to get
> >
> >this
> >
> >> > patch committed if possible.
> >> 
> >> I think Jerry ACKed the patch back then. I'll try to find the time to
> >> commit it maybe during one of the coming weekends unless someone else
> >> beats me to it..
> >> 
> >> Thanks for the reminder!
> >> Bernhard
> >> 
> >> > Thanks,
> >> > Andrew
> >> > 
> >> > On Wednesday, September 5, 2018 12:35:04 PM PDT Bernhard
> >
> >Reutner-Fischer
> >
> >> > wrote:
> >> > > On Wed, 5 Sep 2018 at 03:30, Jerry DeLisle
> >
> ><jvdelisle@charter.net>
> >
> >wrote:
> >> > > > On 09/04/2018 10:43 AM, Bernhard Reutner-Fischer wrote:
> >> > > > > On Tue, 4 Sep 2018 at 18:43, Andrew Benson
> >> > > > > <abenson@carnegiescience.edu>
> >> > 
> >> > wrote:
> >> > > > >> As suggested by Janus, PR87103 is easily fixed by the
> >
> >attached
> >
> >> > > > >> patch
> >> > > > >> which
> >> > > > >> increases GFC_MAX_SYMBOL_LEN to 76 (sufficient to hold the
> >
> >maximum
> >
> >> > > > >> allowed F08 symbol length of 63, plus a null terminator,
> >
> >plus the
> >
> >> > > > >> "__tmp_class_" prefix).> >
> >> > > > > 
> >> > > > > This is so much wrong.
> >> > > > > Note that this will be fixed properly by the changes
> >
> >contained in
> >
> >> > > > > the
> >
> >https://gcc.gnu.org/git/?p=gcc.git;a=shortlog;h=refs/heads/aldot/for
> >
> >> > > > > tran
> >> > > > > -fe-stringpool branch.
> >> > > > > There we keep the GFC_MAX_SYMBOL_LEN at 63 proper but use an
> >> > > > > internal
> >> > > > > buffer double that size which in turn is sufficient to hold
> >
> >all
> >
> >> > > > > compiler-generated identifiers.
> >> > > > > See gfc_get_string() even in current TOT.
> >> > > > > 
> >> > > > > Maybe we should bite the bullet and start to merge the
> >
> >stringpool
> >
> >> > > > > changes now instead of this hack?
> >> > > > 
> >> > > > It all makes sense to me, please proceed. (my 2 cents worth)
> >> > > 
> >> > > Ok so i will reread the fortran-fe-stringpool series and submit
> >
> >it
> >
> >> > > here for review.
> >> > > 
> >> > > Let's return to the issue at hand for a moment, though.
> >> > > I tested the attached alternate fix on top of the
> >> > > fortran-fe-stringpool branch where it fixes PR87103.
> >> > > Maybe somebody has spare cycles to test it on top of current
> >
> >trunk?
> >
> >> > > thanks,
> >> > > 
> >> > > [PATCH,FORTRAN] PR87103: Remove max symbol length check from
> >> > > gfc_new_symbol
> >> > > 
> >> > > gfc_match_name does check for too long names already. Since
> >> > > gfc_new_symbol is also called for symbols with internal names
> >
> >containing
> >
> >> > > compiler-generated prefixes, these internal names can easily
> >
> >exceed the
> >
> >> > > max_identifier_length mandated by the standard.
> >> > > 
> >> > > gcc/fortran/ChangeLog
> >> > > 
> >> > > 2018-09-04  Bernhard Reutner-Fischer  <aldot@gcc.gnu.org>
> >> > > 
> >> > > PR fortran/87103
> >> > > * expr.c (gfc_check_conformance): Check vsnprintf for truncation.
> >> > > * iresolve.c (gfc_get_string): Likewise.
> >> > > * symbol.c (gfc_new_symbol): Remove check for maximum symbol
> >> > > name length.  Remove redundant 0 setting of new calloc()ed
> >> > > gfc_symbol.
diff mbox series

Patch

Index: gcc/fortran/gfortran.h
===================================================================
--- gcc/fortran/gfortran.h	(revision 264085)
+++ gcc/fortran/gfortran.h	(working copy)
@@ -54,7 +54,9 @@  not after.
 
 /* Major control parameters.  */
 
-#define GFC_MAX_SYMBOL_LEN 63   /* Must be at least 63 for F2003.  */
+/* Must be at least 63 for F2003, +1 for null terminator,
+ +12 for prefix "__tmp_class_".  */
+#define GFC_MAX_SYMBOL_LEN 76
 #define GFC_LETTERS 26		/* Number of letters in the alphabet.  */
 
 #define MAX_SUBRECORD_LENGTH 2147483639   /* 2**31-9 */