public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Hans-Peter Nilsson <hp@axis.com>
To: <gcc-patches@gcc.gnu.org>
Cc: <jason@redhat.com>, <nathan@acm.org>
Subject: Ping*2 PATCH: testcase for "ICE for unknown parameter to constexpr'd switch-statement, PR113545"
Date: Wed, 7 Feb 2024 01:04:15 +0100	[thread overview]
Message-ID: <20240207000415.C74BF20424@pchp3.se.axis.com> (raw)
In-Reply-To: <20240130051845.3F52D20420@pchp3.se.axis.com> (message from Hans-Peter Nilsson on Tue, 30 Jan 2024 06:18:45 +0100)

> From: Hans-Peter Nilsson <hp@axis.com>
> Date: Tue, 30 Jan 2024 06:18:45 +0100

> Ping for the xfailed testsuite patch below the review
> (actual constexpr.cc patch to be handled separately):

Ping*2.  Again, this is for the xfailed test-case only.

> 
> > From: Hans-Peter Nilsson <hp@axis.com>
> > Date: Tue, 23 Jan 2024 05:55:00 +0100
> > 
> > > Date: Mon, 22 Jan 2024 14:33:59 -0500
> > > From: Marek Polacek <polacek@redhat.com>
> > 
> > > The problem seems to be more about conversion so g++.dg/conversion/reinterpret5.C
> > > or g++.dg/cpp0x/constexpr-reinterpret3.C seems more appropriate.
> > > 
> > > > @@ -0,0 +1,49 @@
> > > 
> > > Please add
> > > 
> > > PR c++/113545
> > 
> > > > +  unsigned const char c = swbar(reinterpret_cast<__UINTPTR_TYPE__>(&foo));
> > > > +  xyzzy(c);
> > > > +  unsigned const char d = ifbar(reinterpret_cast<__UINTPTR_TYPE__>(&foo));
> > > 
> > > I suppose we should also test a C-style cast (which leads to a reinterpret_cast
> > > in this case).
> > > 
> > > Maybe check we get an error when c/d are constexpr (that used to ICE).
> > 
> > Like this?  Not sure about the value of that variant, but here goes.
> > 
> > I checked that these behave as expected (xfail as ICE properly) without the
> > previosly posted patch to cp/constexpr.cc and XPASS with it applied.
> > 
> > Ok to commit?
> > 
> > -- >8 --
> > Subject: [PATCH] c++: testcases for PR113545 (constexpr with switch and
> >  passing non-constexpr parameter)
> > 
> > gcc/testsuite:
> > 	PR c++/113545
> > 	* g++.dg/cpp0x/constexpr-reinterpret3.C,
> > 	g++.dg/cpp0x/constexpr-reinterpret4.C: New tests.
> > ---
> >  .../g++.dg/cpp0x/constexpr-reinterpret3.C     | 55 +++++++++++++++++++
> >  .../g++.dg/cpp0x/constexpr-reinterpret4.C     | 54 ++++++++++++++++++
> >  2 files changed, 109 insertions(+)
> >  create mode 100644 gcc/testsuite/g++.dg/cpp0x/constexpr-reinterpret3.C
> >  create mode 100644 gcc/testsuite/g++.dg/cpp0x/constexpr-reinterpret4.C
> > 
> > diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-reinterpret3.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-reinterpret3.C
> > new file mode 100644
> > index 000000000000..319cc5e8bee9
> > --- /dev/null
> > +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-reinterpret3.C
> > @@ -0,0 +1,55 @@
> > +// PR c++/113545
> > +// { dg-do run { target c++11 } }
> > +// { dg-ice "PR112545 - constexpr function with switch called for reinterpret_cast" }
> > +
> > +char foo;
> > +
> > +// This one caught a call to gcc_unreachable in
> > +// cp/constexpr.cc:label_matches, when passed a convert_expr from the
> > +// cast in the call.
> > +constexpr unsigned char swbar(__UINTPTR_TYPE__ baz)
> > +{
> > +  switch (baz)
> > +    {
> > +    case 13:
> > +      return 11;
> > +    case 14:
> > +      return 78;
> > +    case 2048:
> > +      return 13;
> > +    default:
> > +      return 42;
> > +    }
> > +}
> > +
> > +// For reference, the equivalent* if-statements.
> > +constexpr unsigned char ifbar(__UINTPTR_TYPE__ baz)
> > +{
> > +  if (baz == 13)
> > +    return 11;
> > +  else if (baz == 14)
> > +    return 78;
> > +  else if (baz == 2048)
> > +    return 13;
> > +  else
> > +    return 42;
> > +}
> > +
> > +__attribute__ ((__noipa__))
> > +void xyzzy(int x)
> > +{
> > +  if (x != 42)
> > +    __builtin_abort ();
> > +}
> > +
> > +int main()
> > +{
> > +  unsigned const char c = swbar(reinterpret_cast<__UINTPTR_TYPE__>(&foo));
> > +  xyzzy(c);
> > +  unsigned const char d = ifbar(reinterpret_cast<__UINTPTR_TYPE__>(&foo));
> > +  xyzzy(d);
> > +  unsigned const char e = swbar((__UINTPTR_TYPE__) &foo);
> > +  xyzzy(e);
> > +  unsigned const char f = ifbar((__UINTPTR_TYPE__) &foo);
> > +  xyzzy(f);
> > +}
> > diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-reinterpret4.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-reinterpret4.C
> > new file mode 100644
> > index 000000000000..4d0fdf2c0a78
> > --- /dev/null
> > +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-reinterpret4.C
> > @@ -0,0 +1,54 @@
> > +// PR c++/113545
> > +// { dg-do compile { target c++11 } }
> > +
> > +char foo;
> > +
> > +// This one caught a call to gcc_unreachable in
> > +// cp/constexpr.cc:label_matches, when passed a convert_expr from the
> > +// cast in the call.
> > +constexpr unsigned char swbar(__UINTPTR_TYPE__ baz)
> > +{
> > +  switch (baz)
> > +    {
> > +    case 13:
> > +      return 11;
> > +    case 14:
> > +      return 78;
> > +    case 2048:
> > +      return 13;
> > +    default:
> > +      return 42;
> > +    }
> > +}
> > +
> > +// For reference, the equivalent* if-statements.
> > +constexpr unsigned char ifbar(__UINTPTR_TYPE__ baz)
> > +{
> > +  if (baz == 13)
> > +    return 11;
> > +  else if (baz == 14)
> > +    return 78;
> > +  else if (baz == 2048)
> > +    return 13;
> > +  else
> > +    return 42;
> > +}
> > +
> > +__attribute__ ((__noipa__))
> > +void xyzzy(int x)
> > +{
> > +  if (x != 42)
> > +    __builtin_abort ();
> > +}
> > +
> > +int main()
> > +{
> > +  unsigned constexpr char c = swbar(reinterpret_cast<__UINTPTR_TYPE__>(&foo)); // { dg-error "conversion from pointer type" }
> > +  xyzzy(c);
> > +  unsigned constexpr char d = ifbar(reinterpret_cast<__UINTPTR_TYPE__>(&foo)); // { dg-error "conversion from pointer type" }
> > +  xyzzy(d);
> > +  unsigned constexpr char e = swbar((__UINTPTR_TYPE__) &foo); // { dg-error "conversion from pointer type" }
> > +  xyzzy(e);
> > +  unsigned constexpr char f = ifbar((__UINTPTR_TYPE__) &foo); // { dg-error "conversion from pointer type" }
> > +  xyzzy(f);
> > +}
> > -- 
> > 2.30.2
> > 
> 

  reply	other threads:[~2024-02-07  0:04 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-22 17:02 [PATCH] c++: Don't ICE for unknown parameter to constexpr'd switch-statement, PR113545 Hans-Peter Nilsson
2024-01-22 19:33 ` Marek Polacek
2024-01-23  0:55   ` Hans-Peter Nilsson
2024-01-23  2:23   ` Hans-Peter Nilsson
2024-01-23  4:55   ` Hans-Peter Nilsson
2024-01-30  5:18     ` Ping PATCH: testcase for "ICE for unknown parameter to constexpr'd switch-statement, PR113545" Hans-Peter Nilsson
2024-02-07  0:04       ` Hans-Peter Nilsson [this message]
2024-02-07  0:23   ` [PATCH] c++: Don't ICE for unknown parameter to constexpr'd switch-statement, PR113545 Hans-Peter Nilsson
2024-02-07 21:32     ` Jason Merrill
2024-02-08  2:11       ` Marek Polacek
2024-02-08 15:40         ` Hans-Peter Nilsson
2024-02-08 15:44           ` Marek Polacek
2024-02-08 16:07             ` Hans-Peter Nilsson
2024-02-08 16:22               ` Marek Polacek
2024-02-08 16:42                 ` Hans-Peter Nilsson
2024-02-09  4:02       ` [PATCH v2]: testcases for "ICE for unknown parameter to constexpr'd switch-statement, PR113545" Hans-Peter Nilsson
2024-02-09 15:30       ` [PATCH v3]: " Hans-Peter Nilsson
2024-02-09 16:02         ` [PATCH v4]: " Hans-Peter Nilsson
2024-02-09 18:22           ` 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=20240207000415.C74BF20424@pchp3.se.axis.com \
    --to=hp@axis.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jason@redhat.com \
    --cc=nathan@acm.org \
    /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).