public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <rguenther@suse.de>
To: Bernd Edlinger <bernd.edlinger@hotmail.de>
Cc: Jeff Law <law@redhat.com>,
	    "gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] Check the STRING_CSTs in varasm.c
Date: Fri, 17 Aug 2018 13:38:00 -0000	[thread overview]
Message-ID: <alpine.LSU.2.20.1808171529380.16707@zhemvz.fhfr.qr> (raw)
In-Reply-To: <AM5PR0701MB2657134391AA894E44F8C9A2E43D0@AM5PR0701MB2657.eurprd07.prod.outlook.com>

On Fri, 17 Aug 2018, Bernd Edlinger wrote:

> On 08/17/18 14:19, Richard Biener wrote:
> > On Fri, 17 Aug 2018, Bernd Edlinger wrote:
> > 
> >> Richard Biener wrote:
> >>> +embedded @code{NUL} characters.  However, the
> >>> +@code{TREE_STRING_LENGTH} always includes a trailing @code{NUL} that
> >>> +is not part of the language string literal but appended by the front end.
> >>> +If the string shall not be @code{NUL}-terminated the @code{TREE_TYPE}
> >>> +is one character shorter than @code{TREE_STRING_LENGTH}.
> >>> +Excess caracters other than one trailing @code{NUL} character are not
> > 
> > characters btw.
> > 
> 
> thanks, updated.
> 
> > I read the above that the string literal for
> > 
> > char x[2] = "1";
> > 
> > is actually "1\0\0" - there's one NUL that is not part of the language
> > string literal.  The second sentence then suggests that both \0
> > are removed because 2 is less than 3?
> > 
> 
> maybe 2 is a bad example, lets consider:
> char x[2000000000] = "1";
> 
> That is a string_cst with STRING_LENGTH = 2, content = "2\0\0"
> the array_type is used on both x, and the string_cst,
> I was assuming that both tree objects refer to the same type object.
> which is char[0..2000000000-1]

Oh, didn't realize we use char[200000000] for the STRING_CST.  Makes
my suggestion to use char[] instead not (very) much worse than the
existing practice then.

> varasm assembles the bytes that are given by STRING_LENGTH
> and appends zeros as appropriate.
> 
> > As said, having this extra semantics of a STRING_CST tied to
> > another tree node (its TREE_TYPE) looks ugly.
> > 
> >>> +permitted.
> >>>
> >>> I find this very confusing and oppose to that change.  Can we get
> >>> back to the drawing board please?  If we want an easy way to
> >>> see whether a string is "properly" terminated then maybe we can
> >>> simply use a flag that gets set by build_string?
> >>>
> >>
> >> What I mean with that is the case like
> >> char x[2] = "123456";
> >>
> >> which is build_string(7, "123456"), but with a type char[2],
> >> so varasm throws away "3456\0".
> > 
> > I think varasm throws away chars not because of the type of
> > the STRING_CST but because of the available storage in x.
> > 
> 
> But at other places we look at the type of the string_cst, don't we?
> Shouldn't those be the same?

I think most (all?) places look at TREE_TYPE (TREE_TYPE (string))
only.  I'm not aware of users of the array domain of the array type
of a string - but I'm far from knowing GCC inside-out ;)

> >> I want to say that this is not okay, the excess precision
> >> should only be used to strip the nul termination, in cases
> >> where it is intended to be a assembled as a not zero terminated
> >> string.  But maybe the wording could be improved?
> > 
> > ISTR we always assemble a NUL in .strings to get string merging
> > working.
> > 
> 
> String merging is not working when the string is not explicitly
> NUL terminated, my followup patch here tries to fix that:
> 
> [PATCH] Handle not explicitly zero terminated strings in merge sections
> https://gcc.gnu.org/ml/gcc-patches/2018-08/msg00481.html

I'd have expected sth as simple as

  if (merge_strings && str[thissize - 1] != '\0')
    thissize++;

being appended in output_constant.

Richard.

  reply	other threads:[~2018-08-17 13:38 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-01 11:35 Bernd Edlinger
2018-08-03 21:36 ` Jeff Law
2018-08-03 21:42   ` Bernd Edlinger
2018-08-04  5:55   ` Bernd Edlinger
2018-08-05 10:28     ` Bernd Edlinger
2018-08-17  4:46       ` Jeff Law
2018-08-17 12:13         ` Bernd Edlinger
2018-08-18  3:43           ` Jeff Law
2018-08-17  9:38     ` Richard Biener
2018-08-17 10:38       ` Bernd Edlinger
2018-08-17 12:19         ` Richard Biener
2018-08-17 12:36           ` Bernd Edlinger
2018-08-17 13:38             ` Richard Biener [this message]
2018-08-17 13:53               ` Bernd Edlinger
2018-08-18  3:47                 ` Jeff Law
2018-08-22 14:27                 ` Bernd Edlinger
2018-08-22 20:54                   ` Martin Sebor
2018-08-22 22:52                     ` Bernd Edlinger
2018-08-24 20:18                     ` Bernd Edlinger
2018-09-13 18:44                       ` Jeff Law
2018-09-13 19:08                         ` Bernd Edlinger
2018-09-13 18:59                       ` Jeff Law
2018-09-13 19:51                         ` Bernd Edlinger
2018-09-13 21:32                           ` Jeff Law
2018-09-13 22:02                       ` Jeff Law
2018-08-17  9:33   ` Richard Biener
2018-08-17 10:22     ` Bernd Edlinger
2018-08-17 12:14       ` Richard Biener

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.LSU.2.20.1808171529380.16707@zhemvz.fhfr.qr \
    --to=rguenther@suse.de \
    --cc=bernd.edlinger@hotmail.de \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=law@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).