This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Add ASSERT_RTX_PTR_EQ
- From: David Malcolm <dmalcolm at redhat dot com>
- To: Bernd Schmidt <bschmidt at redhat dot com>, gcc-patches at gcc dot gnu dot org
- Cc: David Malcolm <dmalcolm at redhat dot com>
- Date: Fri, 2 Dec 2016 15:24:04 -0500
- Subject: [PATCH] Add ASSERT_RTX_PTR_EQ
- Authentication-results: sourceware.org; auth=none
- References: <af4b8a60-a0d3-84ef-e301-411e4e8fc48e@redhat.com>
On Fri, 2016-12-02 at 16:28 +0100, Bernd Schmidt wrote:
> On 12/01/2016 10:43 PM, David Malcolm wrote:
> > > > + rtx_insn *jump_insn = get_insn_by_uid (1);
> > > > + ASSERT_EQ (JUMP_INSN, GET_CODE (jump_insn));
> > > > + ASSERT_EQ (ret_rtx, JUMP_LABEL (jump_insn));
> > > > + // FIXME: ^^^ use ASSERT_RTX_PTR_EQ here ^^^
> > >
> > > Why is this a fixme and not just done that way (several
> > > instances)?
> >
> > ASSERT_RTX_PTR_EQ doesn't exist yet; there was some discussion
> > about it
> > in earlier versions of the patch, but I haven't written it. It
> > would
> > be equivalent to ASSERT_EQ, checking pointer equality, but would
> > dump
> > the mismatching expected vs actual rtx on failure.
> >
> > Should I convert this to a TODO, or go ahead and implement
> > ASSERT_RTX_PTR_EQ?
>
> Missed this question. Just add ASSERT_RTX_PTR_EQ, that shouldn't be
> hard, should it?
>
>
> Bernd
This patch implements an ASSERT_RTX_PTR_EQ macro, like ASSERT_EQ,
but which dumps both rtx to stderr if the assertion fails.
gcc/ChangeLog:
* selftest-rtl.c (selftest::assert_rtx_ptr_eq_at): New function.
* selftest-rtl.h (ASSERT_RTX_PTR_EQ): New macro.
---
gcc/selftest-rtl.c | 23 +++++++++++++++++++++++
gcc/selftest-rtl.h | 18 ++++++++++++++++++
2 files changed, 41 insertions(+)
diff --git a/gcc/selftest-rtl.c b/gcc/selftest-rtl.c
index 20e6550..c14db43 100644
--- a/gcc/selftest-rtl.c
+++ b/gcc/selftest-rtl.c
@@ -36,6 +36,29 @@ along with GCC; see the file COPYING3. If not see
namespace selftest {
+/* Compare rtx EXPECTED and ACTUAL by pointer equality, calling
+ ::selftest::pass if they are equal, aborting if they are non-equal.
+ LOC is the effective location of the assertion, MSG describes it. */
+
+void
+assert_rtx_ptr_eq_at (const location &loc, const char *msg,
+ rtx expected, rtx actual)
+{
+ if (expected == actual)
+ ::selftest::pass (loc, msg);
+ else
+ {
+ fprintf (stderr, "%s:%i: %s: FAIL: %s\n", loc.m_file, loc.m_line,
+ loc.m_function, msg);
+ fprintf (stderr, " expected (at %p): ", (void *)expected);
+ print_rtl (stderr, expected);
+ fprintf (stderr, "\n actual (at %p): ", (void *)actual);
+ print_rtl (stderr, actual);
+ fprintf (stderr, "\n");
+ abort ();
+ }
+}
+
/* Constructor for selftest::rtl_dump_test.
Read a dumped RTL function from PATH.
Takes ownership of PATH, freeing in dtor.
diff --git a/gcc/selftest-rtl.h b/gcc/selftest-rtl.h
index 35d6437..cb2772d 100644
--- a/gcc/selftest-rtl.h
+++ b/gcc/selftest-rtl.h
@@ -47,6 +47,24 @@ assert_rtl_dump_eq (const location &loc, const char *expected_dump, rtx x,
assert_rtl_dump_eq (SELFTEST_LOCATION, (EXPECTED_DUMP), (RTX), \
(REUSE_MANAGER))
+/* Evaluate rtx EXPECTED and ACTUAL and compare them with ==
+ (i.e. pointer equality), calling ::selftest::pass if they are
+ equal, aborting if they are non-equal. */
+
+#define ASSERT_RTX_PTR_EQ(EXPECTED, ACTUAL) \
+ SELFTEST_BEGIN_STMT \
+ const char *desc = "ASSERT_RTX_PTR_EQ (" #EXPECTED ", " #ACTUAL ")"; \
+ ::selftest::assert_rtx_ptr_eq_at (SELFTEST_LOCATION, desc, (EXPECTED), \
+ (ACTUAL)); \
+ SELFTEST_END_STMT
+
+/* Compare rtx EXPECTED and ACTUAL by pointer equality, calling
+ ::selftest::pass if they are equal, aborting if they are non-equal.
+ LOC is the effective location of the assertion, MSG describes it. */
+
+extern void assert_rtx_ptr_eq_at (const location &loc, const char *msg,
+ rtx expected, rtx actual);
+
/* A class for testing RTL function dumps. */
class rtl_dump_test
--
1.8.5.3