public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Martin Sebor <msebor@gmail.com>
To: Jason Merrill <jason@redhat.com>
Cc: Gcc Patch List <gcc-patches@gcc.gnu.org>,
	Joseph Myers <joseph@codesourcery.com>
Subject: Re: [PATCH] convert braced initializers to strings (PR 71625)
Date: Tue, 31 Jul 2018 14:49:00 -0000	[thread overview]
Message-ID: <e2bb35fa-7469-df5d-c6e1-fdacbc637155@gmail.com> (raw)
In-Reply-To: <CADzB+2=2Kj=HRLXi1pLx3NGE5XCNRaKjKuG44WeXncCoqrLLdw@mail.gmail.com>

On 07/31/2018 07:38 AM, Jason Merrill wrote:
> On Tue, Jul 31, 2018 at 9:51 AM, Martin Sebor <msebor@gmail.com> wrote:
>> The middle-end contains code to determine the lengths of constant
>> character arrays initialized by string literals.  The code is used
>> in a number of optimizations and warnings.
>>
>> However, the code is unable to deal with constant arrays initialized
>> using the braced initializer syntax, as in
>>
>>   const char a[] = { '1', '2', '\0' };
>>
>> The attached patch extends the C and C++ front-ends to convert such
>> initializers into a STRING_CST form.
>>
>> The goal of this work is to both enable existing optimizations for
>> such arrays, and to help detect bugs due to using non-nul terminated
>> arrays where nul-terminated strings are expected.  The latter is
>> an extension of the GCC 8 _Wstringop-overflow and
>> -Wstringop-truncation warnings that help detect or prevent reading
>> past the end of dynamically created character arrays.  Future work
>> includes detecting potential past-the-end reads from uninitialized
>> local character arrays.
>
>>   && TYPE_MAIN_VARIANT (TREE_TYPE (valtype)) == char_type_node)
>
> Why? Don't we want this for other character types as well?

It suppresses narrowing warnings for things like

   signed char a[] = { 0xff };

(there are a couple of tests that exercise this).

At the same time, STRING_CST is supposed to be able to represent
strings of any integer type so there should be a way to make it
work.  On the flip side, recent discussions of changes in this
area suggest there may be bugs in the wide character handling of
STRING_CST so those would need to be fixed before relying on it
for robust support.

In any case, if you have a suggestion for how to make it work for
at least the narrow character types I'll adjust the patch.

Martin

  reply	other threads:[~2018-07-31 14:49 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-30 23:51 Martin Sebor
2018-07-31 13:39 ` Jason Merrill
2018-07-31 14:49   ` Martin Sebor [this message]
2018-08-07  8:58     ` Jason Merrill
2018-08-07 23:04       ` Martin Sebor
2018-08-08 11:09         ` Jason Merrill
2018-08-09  0:17           ` Martin Sebor
2018-08-09 22:07             ` Joseph Myers
2018-08-13 10:36             ` Jason Merrill
2018-08-14 13:27             ` James Greenhalgh
2018-08-14 15:08               ` Martin Sebor
2018-08-14 15:24                 ` Martin Sebor
2018-08-15  2:34                   ` Martin Sebor
2018-08-15 10:29                     ` James Greenhalgh
2018-08-15 15:04                       ` Richard Biener
2018-08-15 15:51                       ` Martin Sebor
2018-08-17 17:19                         ` [PATCH] Fix poly types after PR tree-optimization/71625 strlen optimization Szabolcs Nagy
2018-08-17 17:22                           ` Kyrill Tkachov
2018-08-14 21:14               ` [PATCH] convert braced initializers to strings (PR 71625) Joseph Myers
2018-08-14 22:18                 ` Martin Sebor
2018-08-15 12:07                   ` Joseph Myers
2018-08-15 21:02                     ` Martin Sebor
2018-08-15 21:14                       ` Jeff Law
2018-08-15 21:34                       ` Jeff Law
2018-08-16 15:23                         ` Martin Sebor
2018-08-16 15:32                           ` Jeff Law
2018-08-06 16:41 ` Martin Sebor
2018-08-06 17:04   ` Joseph Myers
2018-08-07  2:02     ` Martin Sebor
2018-08-07 11:31       ` Joseph Myers
2018-08-07 23:05         ` Martin Sebor
2018-08-08 17:33 Bernd Edlinger
2018-08-08 18:34 ` Bernd Edlinger
2018-08-08 19:50   ` Martin Sebor
2018-08-08 20:35     ` Bernd Edlinger
2018-08-08 20:48     ` Joseph Myers
2018-08-09  0:23       ` Martin Sebor
2018-08-09 10:47         ` Joseph Myers
2018-08-16  6:37 Bernd Edlinger
2018-08-17 22:26 ` Bernd Edlinger
2018-08-18  4:13   ` Jeff Law
2018-08-18 10:40   ` Richard Sandiford
2018-08-18 14:25     ` Bernd Edlinger
2018-08-18 16:46       ` Richard Sandiford
2018-08-18 17:09         ` Bernd Edlinger

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=e2bb35fa-7469-df5d-c6e1-fdacbc637155@gmail.com \
    --to=msebor@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jason@redhat.com \
    --cc=joseph@codesourcery.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).