public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: "Kewen.Lin" <linkw@linux.ibm.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>,
	Bill Schmidt <wschmidt@linux.ibm.com>,
	Segher Boessenkool <segher@kernel.crashing.org>
Subject: Re: [PATCH] Fix PR94401 by considering reverse overrun
Date: Thu, 2 Apr 2020 12:39:38 +0200	[thread overview]
Message-ID: <20200402103938.GR2212@tucnak> (raw)
In-Reply-To: <5e92fc81-bd24-d866-26ee-48a251e69b82@linux.ibm.com>

On Thu, Apr 02, 2020 at 06:07:55PM +0800, Kewen.Lin wrote:
> > The above is misformatted.  The ? and : shouldn't be indented further than
> > the dataref_offset, but usually e.g. for the sake of emacs we add ()s around
> > the expression in this case.  So:
> > 			tree offset = (dataref_offset
> > 				       ? dataref_offset
> > 				       : build_int_cst (ref_type, 0));
> > or
> > 			tree offset
> > 			  = (dataref_offset
> > 			     ? dataref_offset : build_int_cst (ref_type, 0));
> > 
> 
> Thanks Jakub!  I'll follow this by add () for ternary expression.
> With manual added "()", clang-format can get below:

Note, the () isn't about ternary expressions, if everything fits on one
line, there is no reason to add ()s, so
  tree offset = dataref_offset ? dataref_offset : build_int_cst (ref_type, 0);
is just fine that way, on the other side
					int whatever = HOST_WIDE_INT_1U
						       + foobarbaz (qux);
should have them too, like:
					int whatever = (HOST_WIDE_INT_1U
							+ foobarbaz (qux));
or
					int whatever
					  = HOST_WIDE_INT_1U + foobarbaz (qux);
I don't use emacs, but was told that emacs without the ()s would misindent
it like (I think):
					int whatever = HOST_WIDE_INT_1U
					  + foobarbaz (qux);
which is what we do not want.

> 
> 			tree offset
> 			  = (dataref_offset ? dataref_offset
> 					    : build_int_cst (ref_type, 0));
> 
> contrib/check_GNU_style.sh didn't complain this, I'm not sure whether
> it's possible to add this kind of convention into contrib/clang-format.

clang-format is not our official indentation style; I have no problem with
the above formatting from readability POV, though unsure what emacs will do
with that (but if it moves that : right below the first dataref_offset,
no big deal, that is also fine and probably more appropriate if the
build_int_cst... is long and would need more wrapping).

	Jakub


  reply	other threads:[~2020-04-02 10:39 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-02  7:15 Kewen.Lin
2020-04-02  8:28 ` Jakub Jelinek
2020-04-02 10:07   ` Kewen.Lin
2020-04-02 10:39     ` Jakub Jelinek [this message]
2020-04-02 12:05   ` Segher Boessenkool
2020-04-02  9:21 ` Richard Biener
2020-04-02 10:33   ` Kewen.Lin

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=20200402103938.GR2212@tucnak \
    --to=jakub@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=linkw@linux.ibm.com \
    --cc=segher@kernel.crashing.org \
    --cc=wschmidt@linux.ibm.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).