public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Martin Sebor <msebor@gmail.com>
Cc: Gcc Patch List <gcc-patches@gcc.gnu.org>,
	Jason Merrill <jason@redhat.com>,
	       "Joseph S. Myers" <joseph@codesourcery.com>
Subject: Re: [PATCH] integer overflow checking builtins in constant expressions
Date: Wed, 01 Jun 2016 07:52:00 -0000	[thread overview]
Message-ID: <20160601075212.GL28550@tucnak.redhat.com> (raw)
In-Reply-To: <574E13DD.9040401@gmail.com>

On Tue, May 31, 2016 at 04:44:45PM -0600, Martin Sebor wrote:
> >I fail to understand this.  You set type to NULL_TREE, and then (not in any
> >kind of loop, nor any label you could goto to) do:
> >   type = type ? type : xxx;
> >That is necessarily equal to type = xxx;, isn't it?
> 
> Each label falls through to the next, so the test prevents
> the subsequent labels from overwriting the value assigned
> to type by the label that matched the switch expression.
> I'm not exactly enamored with these repetitive tests but
> the only alternative that occurred to me was to duplicate
> the whole switch statement, and this seemed like the lesser
> of the two evils.  If you have a suggestion for something
> better I'd be happy to change it.

Ugh, I've missed missing break; Anyway, IMHO we shouldn't change
the old style builtins and therefore you really don't need this.

> >>+  /* When the last argument is a NULL pointer and the first two arguments
> >>+     are constant, attempt to fold the built-in call into a constant
> >>+     expression indicating whether or not it detected an overflow but
> >>+     without storing the result.  */
> >>+  if ((!arg2 || zerop (arg2))
> >
> >As I said in another mail, IMNSHO you don't want to change the clang
> >compatibility builtins, therefore arg2 should never be NULL.
> 
> Allowing the last argument to be null is the subject of
> the enhancement request in c/68120 (one of the two PRs
> driving this enhancement).  The argument can only be null
> for these overloads and not the type-generic ones because
> the latter use the type to which the pointer points to
> determine the type in which to do the arithmetic.  Without
> this change, C or C++ 98 users wouldn't be able to use the
> built-ins in constant expressions (C++ 98 doesn't allow
> casting a null pointer in those contexts).

Sorry, I don't understand this argument.  What is wrong on using
const int x = __builtin_add_overflow (1234567, 123456, (int *) NULL);
?
I don't get any warning/error on
#include <stddef.h>
int *const p = (int *) NULL;
in C89 nor C++98 with -pedantic-errors, not to mention that the
builtins are extensions anyway, so what do you accept/reject in its
arguments doesn't need to honor any specific rules.  Even if (int *) NULL
is not allowed for whatever reason, is (int *) 0 disallowed too?  It is
just a matter of what we document.

The clang compatibility builtins are severely limited and too ugly to live
with, they don't allow different types of the arguments, have just a very
limited set of accepted types, don't allow different result
type, how do you even handle a type for which you don't know if it is
unsigned, unsigned long or unsigned long long?
  size_t a, b, c, d;
...
  if (sizeof (size_t) == sizeof (unsigned long long))
    a = __builtin_uaddll_overflow (b, c, &d);
  else if (sizeof (size_t) == sizeof (unsigned long))
    a = __builtin_uaddl_overflow (b, c, &d);
  else if (sizeof (size_t) == sizeof (unsigned int))
    a = __builtin_uadd_overflow (b, c, &d);
  else
    abort ();
?  We really shouldn't encourage these at all.

> I suspect I didn't use integer_zerop because the argument
> is a pointer and not integer, but I'll change it before
> I commit the patch.

Pointers are treated the same as integers, they are represented as
INTEGER_CSTs too.
> 
> >Regarding the varargs vs. named args only different diagnostics, if you
> >think it should change, then IMHO you should submit as independent patch
> >a change to the diagnostics wording, so that the wording is the same, rather
> >than changing functions from fixed arguments to varargs (/ typegeneric).
> 
> I'm not sure I know what part of the patch you're referring
> to.  Are you suggesting to submit a separate patch for the
> change from "not enough arguments" to "too few arguments"
> below?
> 
> -		"not enough arguments to function %qE", fndecl);
> +		"too few arguments to function %qE", fndecl);

Yeah.  IMO that is an independent change, you can/should add a testcase for
it, and it can go in before or after the patch.

	Jakub

  parent reply	other threads:[~2016-06-01  7:52 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 [this message]
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
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=20160601075212.GL28550@tucnak.redhat.com \
    --to=jakub@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jason@redhat.com \
    --cc=joseph@codesourcery.com \
    --cc=msebor@gmail.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).