public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Bernd Edlinger <bernd.edlinger@hotmail.de>
To: Martin Sebor <msebor@gmail.com>, Joseph Myers <joseph@codesourcery.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>,
	Richard Biener <rguenther@suse.de>,
	Jakub Jelinek <jakub@redhat.com>, Jeff Law <law@redhat.com>
Subject: Re: [PATCH] Handle overlength strings in the C FE
Date: Wed, 01 Aug 2018 17:37:00 -0000	[thread overview]
Message-ID: <AM5PR0701MB26574D2ED02BF34F915F62ACE42D0@AM5PR0701MB2657.eurprd07.prod.outlook.com> (raw)
In-Reply-To: <49903afb-c647-5f15-f51b-80f132e18850@gmail.com>

On 08/01/18 19:07, Martin Sebor wrote:
> On 08/01/2018 05:20 AM, Bernd Edlinger wrote:
>> On 07/30/18 17:49, Joseph Myers wrote:
>>> On Mon, 30 Jul 2018, Bernd Edlinger wrote:
>>>
>>>> Hi,
>>>>
>>>> this is how I would like to handle the over length strings issue in the C FE.
>>>> If the string constant is exactly the right length and ends in one explicit
>>>> NUL character, shorten it by one character.
>>>
>>> I don't think shortening should be limited to that case.  I think the case
>>> where the constant is longer than that (and so gets an unconditional
>>> pedwarn) should also have it shortened - any constant that doesn't fit in
>>> the object being initialized should be shortened to fit, whether diagnosed
>>> or not, we should define GENERIC / GIMPLE to disallow too-large string
>>> constants in initializers, and should add an assertion somewhere in the
>>> middle-end that no too-large string constants reach it.
>>>
>>
>> Okay, there is an update following your suggestion.
>>
>> Bootstrapped and reg-tested on x86_64-pc-linux-gnu.
>> Is it OK for trunk?
> 
> The ChangeLog description says:
> 
>      * c-typeck.c (digest_init): Fix overlength strings.
> 
> suggesting there is a bug but there is no test case.  If there
> is a bug in there that can be triggered by C code (valid or
> otherwise), it would be good to have a test case and a bug
> in Bugzilla.  If there is no bug and this is just cleanup,
> I would suggest to adjust the description.
> 

Yes, thanks for looking at this.  This is an attempt to
reduce the number of different encodings for otherwise
identical strings in the middle-end.

I could say "Shorten overlength strings." is that better?
There are already numerous test cases with overlength strings.
I verified that, because I have tested this patch on top
of https://gcc.gnu.org/ml/gcc-patches/2018-08/msg00050.html

> Other than that, while making improvements here, I think it
> would be helpful to also add more detail to the text of
> the warning:
> 

Sure, but it is important to do only one thing at a time.
I see this as a preparation to fixing the remaining
string_constant folding issues which are potential wrong-code
issues.

> 1) mention the type of the array being initialized in case
> it's not obvious from the declaration (the array bound could
> be a symbol, not a literal, or the type could be a typedef)
> 
> 2) mention the number of elements in the initializer in case
> it's a macro (such as __FILE__) whose definition isn't visible
> in the diagnostic
> 
> 3) mention that the excess elements are ignored (since it's
> undefined in the standard, it will let users know what
> happens in GCC).
> 
> Here's a test case and a suggested warning:
> 
>    #define S __FILE__ "\000"
>    enum { N = sizeof __FILE__ };
>    const char a[N] = S;
> 
>    warning: discarding 1 excess element from initializer-string for 'char[4]' [-Wc++-compat]
>     #define S __FILE__ "\000"
>               ^~~~~~~~
>    note: in expansion of macro ‘S’
>     const char a[N] = S;
>                       ^
> (Similarly for more than 1 excess element.)
> 

Yes, definitely helpful, but not part of this patch.
Probably one of your next patches, I would assume.

Bernd.

  reply	other threads:[~2018-08-01 17:37 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-30 11:51 [PATCH] Fix the damage done by my other patch from yesterday to strlenopt-49.c Bernd Edlinger
2018-07-30 13:03 ` Richard Biener
2018-07-30 14:41   ` Bernd Edlinger
2018-07-30 15:52     ` Joseph Myers
2018-07-30 15:57       ` Jakub Jelinek
2018-07-30 16:01         ` Joseph Myers
2018-07-30 16:28           ` Bernd Edlinger
2018-07-30 16:30             ` Jakub Jelinek
2018-07-30 16:08         ` Bernd Edlinger
2018-07-30 17:33     ` Richard Biener
2018-07-31 12:23   ` Bernd Edlinger
2018-07-30 15:22 ` Martin Sebor
2018-07-30 15:49 ` Joseph Myers
2018-08-01 11:20   ` [PATCH] Handle overlength strings in the C FE Bernd Edlinger
2018-08-01 16:04     ` Joseph Myers
2018-08-01 20:06       ` Bernd Edlinger
2018-08-01 20:28         ` Marek Polacek
2018-08-01 20:43           ` Joseph Myers
2018-08-09 14:07             ` Bernd Edlinger
2018-08-09 22:08               ` Joseph Myers
2018-08-24 19:59               ` [PATCHv2] " Bernd Edlinger
2018-09-13 21:44                 ` Jeff Law
2018-08-01 17:07     ` [PATCH] " Martin Sebor
2018-08-01 17:37       ` Bernd Edlinger [this message]
2018-08-01 21:03       ` Eric Gallager
2018-08-01 22:09         ` Joseph Myers

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=AM5PR0701MB26574D2ED02BF34F915F62ACE42D0@AM5PR0701MB2657.eurprd07.prod.outlook.com \
    --to=bernd.edlinger@hotmail.de \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    --cc=joseph@codesourcery.com \
    --cc=law@redhat.com \
    --cc=msebor@gmail.com \
    --cc=rguenther@suse.de \
    /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).