From: Jason Merrill <jason@redhat.com>
To: Jakub Jelinek <jakub@redhat.com>
Cc: gcc-patches List <gcc-patches@gcc.gnu.org>,
David Malcolm <dmalcolm@redhat.com>
Subject: Re: C++ PATCH for c++/79228, complex literal suffixes
Date: Tue, 05 Dec 2017 14:24:00 -0000 [thread overview]
Message-ID: <CADzB+2k5WyQ39shDeOCQysU8_Cggu_tx=FLt5GaaqAJQ53hGLg@mail.gmail.com> (raw)
In-Reply-To: <20171205123318.GT2353@tucnak>
OK, thanks.
On Tue, Dec 5, 2017 at 7:33 AM, Jakub Jelinek <jakub@redhat.com> wrote:
> On Fri, Dec 01, 2017 at 03:16:23PM -0500, Jason Merrill wrote:
>> commit e39b7d506d236ce7ef9f64d1bcf0b384bb2d8038
>> Author: Jason Merrill <jason@redhat.com>
>> Date: Fri Dec 1 07:45:03 2017 -0500
>>
>> PR c++/79228 - extensions hide C++14 complex literal operators
>>
>> libcpp/
>> * expr.c (interpret_float_suffix): Ignore 'i' in C++14 and up.
>> (interpret_int_suffix): Likewise.
>> gcc/cp/
>> * parser.c (cp_parser_userdef_numeric_literal): Be helpful about
>> 'i' in C++14 and up.
>>
>> + /* In C++14 and up these suffixes are in the standard library, so treat
>> + them as user-defined literals. */
>> + if (CPP_OPTION (pfile, cplusplus)
>> + && CPP_OPTION (pfile, lang) > CLK_CXX11
>> + && (!memcmp (orig_s, "i", orig_len)
>> + || !memcmp (orig_s, "if", orig_len)
>> + || !memcmp (orig_s, "il", orig_len)))
>
> This doesn't seem right, it will invoke UB if orig_len > 2 by potentially
> accessing bytes beyond 'i' and '\0' in "i" (and for orig_len > 3 also after
> "if" or "il").
> If you only want to return 0 if orig_len bytes starting at orig_s are 'i'
> or 'i' 'f' or 'i' 'l', then I'd write instead as in the patch below.
> Or if memcmp is more readable, at least check orig_len first.
>
>> + /* In C++14 and up these suffixes are in the standard library, so treat
>> + them as user-defined literals. */
>> + if (CPP_OPTION (pfile, cplusplus)
>> + && CPP_OPTION (pfile, lang) > CLK_CXX11
>> + && (!memcmp (s, "i", orig_len)
>> + || !memcmp (s, "if", orig_len)
>> + || !memcmp (s, "il", orig_len)))
>
> Similarly. Additionally, "if" can't happen here, because we don't allow 'f'
> among suffixes.
>
> So, ok for trunk if it passes testing, or some other form thereof?
>
> 2017-12-05 Jakub Jelinek <jakub@redhat.com>
>
> PR c++/79228
> * expr.c (interpret_float_suffix): Avoid memcmp.
> (interpret_int_suffix): Likewise. Don't check for if.
>
> --- libcpp/expr.c.jj 2017-12-01 22:13:24.000000000 +0100
> +++ libcpp/expr.c 2017-12-05 13:26:57.019683785 +0100
> @@ -280,9 +280,10 @@ interpret_float_suffix (cpp_reader *pfil
> them as user-defined literals. */
> if (CPP_OPTION (pfile, cplusplus)
> && CPP_OPTION (pfile, lang) > CLK_CXX11
> - && (!memcmp (orig_s, "i", orig_len)
> - || !memcmp (orig_s, "if", orig_len)
> - || !memcmp (orig_s, "il", orig_len)))
> + && orig_s[0] == 'i'
> + && (orig_len == 1
> + || (orig_len == 2
> + && (orig_s[1] == 'f' || orig_s[1] == 'l'))))
> return 0;
> }
>
> @@ -345,9 +346,8 @@ interpret_int_suffix (cpp_reader *pfile,
> them as user-defined literals. */
> if (CPP_OPTION (pfile, cplusplus)
> && CPP_OPTION (pfile, lang) > CLK_CXX11
> - && (!memcmp (s, "i", orig_len)
> - || !memcmp (s, "if", orig_len)
> - || !memcmp (s, "il", orig_len)))
> + && s[0] == 'i'
> + && (orig_len == 1 || (orig_len == 2 && s[1] == 'l')))
> return 0;
> }
>
>
>
> Jakub
prev parent reply other threads:[~2017-12-05 14:24 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-01 20:16 Jason Merrill
2017-12-05 12:33 ` Jakub Jelinek
2017-12-05 14:24 ` Jason Merrill [this message]
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='CADzB+2k5WyQ39shDeOCQysU8_Cggu_tx=FLt5GaaqAJQ53hGLg@mail.gmail.com' \
--to=jason@redhat.com \
--cc=dmalcolm@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jakub@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).