From: Martin Sebor <msebor@gmail.com>
To: Jakub Jelinek <jakub@redhat.com>, Jason Merrill <jason@redhat.com>
Cc: Gcc Patch List <gcc-patches@gcc.gnu.org>,
"Joseph S. Myers" <joseph@codesourcery.com>
Subject: Re: [PATCH] integer overflow checking builtins in constant expressions
Date: Tue, 07 Jun 2016 20:30:00 -0000 [thread overview]
Message-ID: <57572ECE.9070505@gmail.com> (raw)
In-Reply-To: <20160607194217.GV7387@tucnak.redhat.com>
On 06/07/2016 01:42 PM, Jakub Jelinek wrote:
> On Tue, Jun 07, 2016 at 03:35:28PM -0400, Jason Merrill wrote:
>>> Indeed, confirming removal of the cp/tree.c hunk doesn't affect anything in
>>> the testsuite, nor e.g.
>>> enum A {
>>> B = 1,
>>> C = 2,
>>> D = __builtin_add_overflow_p (B, C, C)
>>> };
>>> int e[__builtin_add_overflow_p (B, C, C) + 1];
>>> template <int N> int foo (int);
>>> void
>>> bar ()
>>> {
>>> foo <__builtin_add_overflow_p (B, C, C) + 1> (0);
>>> }
>>> That said, builtin_valid_in_constant_expr_p is used in lots of spots, and in
>>> various of them I see that without the change it actually sets
>>> *non_integral_constant_expression_p = true;
>>> or something similar, but I have no idea why it still works despite of that.
>>
>> Ah, that's the C++98 constant expression handling, which is a lot more
>> restricted. C++11 and up don't care about that flag.
>
> Oops, actually, it seems even the cp/tree.c hunks are significant:
>
> I've only compiled the above testcase with the default -std=c++14, with
> -std=c++98 without the cp/tree.c bits I get:
>
> a.C:4:7: error: âbool __builtin_add_overflow_p(...)â cannot appear in a
> constant-expression
> D = __builtin_add_overflow_p (B, C, C)
> ^~~~~~~~~~~~~~~~~~~~~~~~
> a.C:4:40: error: a function call cannot appear in a constant-expression
> D = __builtin_add_overflow_p (B, C, C)
> ^
> a.C:6:45: error: array bound is not an integer constant before â]â token
> int e[__builtin_add_overflow_p (B, C, C) + 1];
> ^
> a.C: In function âvoid bar()â:
> a.C:11:8: error: âbool __builtin_add_overflow_p(...)â cannot appear in a
> constant-expression
> foo <__builtin_add_overflow_p (B, C, C) + 1> (0);
> ^~~~~~~~~~~~~~~~~~~~~~~~
> a.C:11:41: error: a function call cannot appear in a constant-expression
> foo <__builtin_add_overflow_p (B, C, C) + 1> (0);
> ^
> a.C:11:50: error: no matching function for call to âfoo(int)â
> foo <__builtin_add_overflow_p (B, C, C) + 1> (0);
> ^
> a.C:7:22: note: candidate: template<int N> int foo(int)
> template <int N> int foo (int);
> ^~~
> a.C:7:22: note: template argument deduction/substitution failed:
> a.C:11:50: error: template argument 1 is invalid
> foo <__builtin_add_overflow_p (B, C, C) + 1> (0);
> ^
>
> Though, maybe it is only worth supporting the __builtin_*_overflow_p
> builtins for C++98 integer constant expression contexts and
> thus only handle there the 3 builtins instead of all the others.
>
> I guess I should add this testcase to the testsuite then.
I've also since discovered that the handling of (at least)
BUILTIN_LINE is important in C++ 98 mode and if I had run
the c-c++-common tests instead of just the strict C++ subset
I would have seen the c-c++-common/builtin_location.c test
fail with the same error.
I suspect I added the other built-ins to the function to get
the Clang-compatibility typed built-ins to work in C++ 98
(with the default argument). When it was decided that
the Clang built-ins shouldn't change I removed the tests
but not this change.
Martin
next prev parent reply other threads:[~2016-06-07 20:30 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-01 16:40 Martin Sebor
2016-05-09 16:39 ` PING " Martin Sebor
2016-05-16 19:30 ` PING 2 " Martin Sebor
2016-05-17 18:54 ` Jason Merrill
2016-05-31 23:43 ` Martin Sebor
[not found] ` <20160531215025.GK28550@tucnak.redhat.com>
[not found] ` <574E13DD.9040401@gmail.com>
2016-06-01 7:52 ` Jakub Jelinek
2016-06-01 15:17 ` Martin Sebor
2016-06-01 15:45 ` Jakub Jelinek
2016-06-01 16:13 ` Martin Sebor
2016-06-02 3:11 ` Martin Sebor
2016-06-02 7:23 ` Jakub Jelinek
2016-06-02 7:34 ` Jakub Jelinek
2016-06-03 15:07 ` Martin Sebor
2016-06-03 15:23 ` Jakub Jelinek
2016-06-03 16:22 ` Martin Sebor
2016-06-02 23:21 ` Martin Sebor
2016-06-03 0:28 ` Martin Sebor
2016-06-03 7:06 ` Jakub Jelinek
2016-06-03 15:29 ` Martin Sebor
2016-06-03 15:32 ` Jakub Jelinek
2016-06-03 20:09 ` Martin Sebor
2016-06-06 12:36 ` Jakub Jelinek
2016-06-06 19:44 ` Jakub Jelinek
2016-06-07 9:12 ` Marek Polacek
2016-06-07 14:32 ` Jason Merrill
2016-06-07 15:51 ` Martin Sebor
2016-06-07 16:34 ` Jakub Jelinek
2016-06-07 19:35 ` Jason Merrill
2016-06-07 19:42 ` Jakub Jelinek
2016-06-07 20:30 ` Martin Sebor [this message]
2016-06-07 20:52 ` Jakub Jelinek
2016-06-07 21:56 ` Martin Sebor
2016-06-08 7:23 ` Jakub Jelinek
2016-06-08 18:38 ` Jason Merrill
2016-06-07 19:36 ` Jason Merrill
2016-06-01 18:46 ` Jason Merrill
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=57572ECE.9070505@gmail.com \
--to=msebor@gmail.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jakub@redhat.com \
--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).