From: Jakub Jelinek <jakub@redhat.com>
To: Jason Merrill <jason@redhat.com>, gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] c, c++, v2: Avoid incorrect shortening of divisions [PR108365]
Date: Fri, 13 Jan 2023 01:25:17 +0100 [thread overview]
Message-ID: <Y8Ck7ctsZ6M8fUD/@tucnak> (raw)
In-Reply-To: <Y8BuGyewY8o2YFkR@tucnak>
On Thu, Jan 12, 2023 at 09:31:23PM +0100, Jakub Jelinek via Gcc-patches wrote:
> On Thu, Jan 12, 2023 at 08:55:32PM +0100, Jakub Jelinek via Gcc-patches wrote:
> > > > So, the following patch for the NOP_EXPR cases checks just in case that
> > > > it is from integral type and more importantly checks it is a widening
> > > > conversion, and then next to it also allows op0 to be just unsigned,
> > > > promoted or not, as that is what the C FE will do for those cases too
> > > > and I believe it must work - either the division/modulo common type
> > > > will be that unsigned type, then we can shorten and don't need to worry
> > > > about UB, or it will be some wider signed type but then it can't be most
> > > > negative value of the wider type.
> > >
> > > Why not use the same condition in C and C++?
> >
> > I can test that. Do you mean change the C FE to match the patched C++
> > or change C++ FE to just test TYPE_UNSIGNED (orig_op0)?
> > I think both should work, though what I wrote perhaps can shorten in more
> > cases. Can try to construct testcases where it differs...
>
> E.g.
> int f1 (int x, int y) { return (unsigned) x / y; }
> unsigned short f2 (unsigned short x, unsigned short y) { return (unsigned) x / y; }
> unsigned int f3 (unsigned int x, unsigned int y) { return (long long) x / y; }
> C++ FE before and after the patch shortens the division in f2 and f3,
> C FE shortens only in f2. So using the C FE condition would be a regression
> for C++.
>
> Therefore I'm going to test following patch:
Bootstrapped/regtested successfully on x86_64-linux and i686-linux.
Jakub
next prev parent reply other threads:[~2023-01-13 0:25 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-11 17:58 [PATCH] c++: " Jakub Jelinek
2023-01-12 19:37 ` Jason Merrill
2023-01-12 19:55 ` Jakub Jelinek
2023-01-12 20:31 ` [PATCH] c, c++, v2: " Jakub Jelinek
2023-01-13 0:25 ` Jakub Jelinek [this message]
2023-01-13 16:58 ` Jason Merrill
2023-01-13 17:45 ` [PATCH] c, c++, v3: " Jakub Jelinek
2023-01-13 19:08 ` 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=Y8Ck7ctsZ6M8fUD/@tucnak \
--to=jakub@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jason@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).