From: Simon Marchi <simon.marchi@ericsson.com>
To: Sergio Durigan Junior <sergiodj@redhat.com>,
GDB Patches <gdb-patches@sourceware.org>,
Pedro Alves <palves@redhat.com>
Subject: Re: [PATCH] Fix thinko on common/offset-type.h (compare 'lhs' against 'rhs')
Date: Fri, 26 Oct 2018 16:08:00 -0000 [thread overview]
Message-ID: <c00a342b-1805-153a-37f2-900e5d79ce77@ericsson.com> (raw)
In-Reply-To: <20181025211008.12164-1-sergiodj@redhat.com>
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="utf-8", Size: 3648 bytes --]
On 2018-10-25 5:10 p.m., Sergio Durigan Junior wrote:
> While doing something else, I noticed that the OFFSET_TYPE's
> "DEFINE_OFFSET_REL_OP" has a thinko: it is comparing 'lhs' against
> itself, instead of against 'rhs'. This patch fixes it.
>
> I also found an interesting thing. We have an unittest for
> offset-type, and in theory it should have caught this problem, because
> it has tests for relational operators. However, the tests
> successfully pass, and after some investigation I'm almost sure this
> is because these operators are not being properly overloaded. I tried
> a few things to make them be used, without success. If someone wants
> to give this a try, I'd appreciate.
>
> No regressions introduced.
>
> gdb/ChangeLog:
> 2018-10-25 Sergio Durigan Junior <sergiodj@redhat.com>
>
> * common/offset-type.h (DEFINE_OFFSET_REL_OP): Compare 'lhs'
> against 'rhs', instead of with 'lhs' again.
> ---
> gdb/ChangeLog | 5 +++++
> gdb/common/offset-type.h | 2 +-
> 2 files changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/gdb/ChangeLog b/gdb/ChangeLog
> index 61dc039d4f..d16c81b3a7 100644
> --- a/gdb/ChangeLog
> +++ b/gdb/ChangeLog
> @@ -1,3 +1,8 @@
> +2018-10-25 Sergio Durigan Junior <sergiodj@redhat.com>
> +
> + * common/offset-type.h (DEFINE_OFFSET_REL_OP): Compare 'lhs'
> + against 'rhs', instead of with 'lhs' again.
> +
> 2018-10-25 Andrew Burgess <andrew.burgess@embecosm.com>
>
> * python/py-function.c (convert_values_to_python): Return
> diff --git a/gdb/common/offset-type.h b/gdb/common/offset-type.h
> index b480b14406..ed59227aa5 100644
> --- a/gdb/common/offset-type.h
> +++ b/gdb/common/offset-type.h
> @@ -81,7 +81,7 @@
> { \
> using underlying = typename std::underlying_type<E>::type; \
> return (static_cast<underlying> (lhs) \
> - OP static_cast<underlying> (lhs)); \
> + OP static_cast<underlying> (rhs)); \
> }
>
> DEFINE_OFFSET_REL_OP(>)
>
Woops. I couldn't believe this had not caused any visible bugs, given that
the two offset types defined currently (cu_offset and sect_offset) are used
quite a lot. I was also surprised that the unit tests in
unittests/offset-type-selftests.c passed, since we have checks for these:
/* Test <, <=, >, >=. */
{
constexpr off_A o1 = (off_A) 10;
constexpr off_A o2 = (off_A) 20;
static_assert (o1 < o2, "");
static_assert (!(o2 < o1), "");
static_assert (o2 > o1, "");
static_assert (!(o1 > o2), "");
static_assert (o1 <= o2, "");
static_assert (!(o2 <= o1), "");
static_assert (o2 >= o1, "");
static_assert (!(o1 >= o2), "");
static_assert (o1 <= o1, "");
static_assert (o1 >= o1, "");
}
I changed these to SELF_CHECK, stuck a gdb_assert(false) in the operator
definition (in the DEFINE_OFFSET_REL_OP macro), and the selftest still runs
without any error.
And if you just remove them (the DEFINE_OFFSET_REL_OP macro and its usages),
the compiler is perfectly happy. So I'm starting to think this operator
definition is not used nor needed. The important thing is that the compiler
rejects comparisons between different offset types, such as what is tested here:
CHECK_VALID (false, void, off_A {} < off_B {});
but if the compiler is able to generate a default comparison operator between
two operands of the same offset type, then I don't think we need to provide
one explicitly.
Therefore, I think we could just remove the relational operator definitions
entirely.
Simon
\x16º&Öéj×!zÊÞ¶êç×}Ó©b²Ö«r\x18\x1dnr\x17¬
next prev parent reply other threads:[~2018-10-26 16:08 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-25 21:10 Sergio Durigan Junior
2018-10-26 4:03 ` Kevin Buettner
2018-10-26 16:30 ` Sergio Durigan Junior
2018-10-26 16:08 ` Simon Marchi [this message]
2018-10-26 16:29 ` Sergio Durigan Junior
2018-10-26 18:23 ` Simon Marchi
2018-10-29 20:11 ` Pedro Alves
2018-10-29 20:14 ` Pedro Alves
2018-10-29 21:14 ` [PATCH] Remove relational operators from common/offset-type.h Sergio Durigan Junior
[not found] ` <692dbc7e4c7e6f1f6ceccf9fb5711880@polymtl.ca>
2018-10-30 3:49 ` Sergio Durigan Junior
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=c00a342b-1805-153a-37f2-900e5d79ce77@ericsson.com \
--to=simon.marchi@ericsson.com \
--cc=gdb-patches@sourceware.org \
--cc=palves@redhat.com \
--cc=sergiodj@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