This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] convert braced initializers to strings (PR 71625)
- From: Jason Merrill <jason at redhat dot com>
- To: Martin Sebor <msebor at gmail dot com>
- Cc: Gcc Patch List <gcc-patches at gcc dot gnu dot org>, Joseph Myers <joseph at codesourcery dot com>
- Date: Tue, 31 Jul 2018 23:38:46 +1000
- Subject: Re: [PATCH] convert braced initializers to strings (PR 71625)
- References: <c9067f6a-9e55-8483-4f4f-c162d4c7a170@gmail.com>
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?
Jason