public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-2348] GTY: Explicitly reject 'string_length' option for (fields in) global variables
@ 2023-07-06 10:03 Thomas Schwinge
  0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2023-07-06 10:03 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:ee8ed948c1f659d10f5c19e4d51bd8a79369762b

commit r14-2348-gee8ed948c1f659d10f5c19e4d51bd8a79369762b
Author: Thomas Schwinge <thomas@codesourcery.com>
Date:   Tue Jul 4 11:46:50 2023 +0200

    GTY: Explicitly reject 'string_length' option for (fields in) global variables
    
    This is preparational for another thing that I'm working on.  No change in
    behavior -- other than a more explicit error message.
    
    The 'string_length' option currently is not supported for (fields in) global
    variables.  For example, if we apply the following (made-up) changes:
    
        --- gcc/c-family/c-cppbuiltin.cc
        +++ gcc/c-family/c-cppbuiltin.cc
        @@ -1777 +1777 @@ struct GTY(()) lazy_hex_fp_value_struct
        -  const char *hex_str;
        +  const char * GTY((string_length("strlen(%h.hex_str) + 1"))) hex_str;
    
        --- gcc/varasm.cc
        +++ gcc/varasm.cc
        @@ -66 +66 @@ along with GCC; see the file COPYING3.  If not see
        -extern GTY(()) const char *first_global_object_name;
        +extern GTY((string_length("strlen(%h.first_global_object_name) + 1"))) const char *first_global_object_name;
    
    ..., we get:
    
        [...]
        build/gengtype  \
                            -S [...]/source-gcc/gcc -I gtyp-input.list -w tmp-gtype.state
        /bin/sh [...]/source-gcc/gcc/../move-if-change tmp-gtype.state gtype.state
        build/gengtype  \
                            -r gtype.state
        [...]/source-gcc/gcc/varasm.cc:66: global `first_global_object_name' has unknown option `string_length'
        [...]/source-gcc/gcc/c-family/c-cppbuiltin.cc:1789: field `hex_str' of global `lazy_hex_fp_values[0]' has unknown option `string_length'
        make[2]: *** [Makefile:2890: s-gtype] Error 1
        [...]
    
    These errors occur when writing "GC roots", where -- per my understanding --
    'string_length' isn't relevant for actual GC purposes.  However, like
    elsewhere, it is for PCH purposes, and simply accepting 'string_length' here
    isn't sufficient: we'll still get '(gt_pointer_walker) &gt_pch_n_S' used in the
    'struct ggc_root_tab' instances, and there's no easy way to change that to
    instead use 'gt_pch_n_S2' with explicit 'size_t string_len' argument.  (At
    least not sufficiently easy to justify spending any further time on, given that
    I don't have an actual use for that feature.)
    
    So, until an actual need arises, and/or to avoid the next person looking into
    this having to figure out the same thing again, let's just document this
    limitation:
    
        [...]/source-gcc/gcc/varasm.cc:66: option `string_length' not supported for global `first_global_object_name'
        [...]/source-gcc/gcc/c-family/c-cppbuiltin.cc:1789: option `string_length' not supported for field `hex_str' of global `lazy_hex_fp_values[0]'
    
    This amends commit f3b957ea8b9dadfb1ed30f24f463529684b7a36a
    "pch: Fix streaming of strings with embedded null bytes".
    
            gcc/
            * gengtype.cc (write_root, write_roots): Explicitly reject
            'string_length' option.
            * doc/gty.texi (GTY Options) <string_length>: Document.

Diff:
---
 gcc/doc/gty.texi |  4 ++++
 gcc/gengtype.cc  | 10 ++++++++++
 2 files changed, 14 insertions(+)

diff --git a/gcc/doc/gty.texi b/gcc/doc/gty.texi
index 9fc509128fe..7bd064b5781 100644
--- a/gcc/doc/gty.texi
+++ b/gcc/doc/gty.texi
@@ -217,6 +217,10 @@ struct GTY(()) non_terminated_string @{
 @};
 @end smallexample
 
+The @code{string_length} option currently is not supported for (fields
+in) global variables.
+@c <https://inbox.sourceware.org/87bkgqvlst.fsf@euler.schwinge.homeip.net>
+
 @findex skip
 @item skip
 
diff --git a/gcc/gengtype.cc b/gcc/gengtype.cc
index 7763f40e9ab..04dbb0de8bd 100644
--- a/gcc/gengtype.cc
+++ b/gcc/gengtype.cc
@@ -4337,6 +4337,11 @@ write_root (outf_p f, pair_p v, type_p type, const char *name, int has_length,
 	      else if (strcmp (o->name, "desc") == 0
 		       && o->kind == OPTION_STRING)
 		desc = o->info.string;
+	      else if (strcmp (o->name, "string_length") == 0)
+		/* See 'doc/gty.texi'.  */
+		error_at_line (line,
+			       "option `%s' not supported for field `%s' of global `%s'",
+			       o->name, fld->name, name);
 	      else
 		error_at_line (line,
 			       "field `%s' of global `%s' has unknown option `%s'",
@@ -4535,6 +4540,11 @@ write_roots (pair_p variables, bool emit_pch)
 	  deletable_p = 1;
 	else if (strcmp (o->name, "cache") == 0)
 	  ;
+	else if (strcmp (o->name, "string_length") == 0)
+	  /* See 'doc/gty.texi'.  */
+	  error_at_line (&v->line,
+			 "option `%s' not supported for global `%s'",
+			 o->name, v->name);
 	else
 	  error_at_line (&v->line,
 			 "global `%s' has unknown option `%s'",

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-07-06 10:03 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-06 10:03 [gcc r14-2348] GTY: Explicitly reject 'string_length' option for (fields in) global variables Thomas Schwinge

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).