* [C++ PATCH] Handle CASE_HIGH in constexpr evaluation (PR c++/72868)
@ 2016-08-11 14:55 Jakub Jelinek
2016-08-11 15:46 ` Jason Merrill
0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2016-08-11 14:55 UTC (permalink / raw)
To: Jason Merrill; +Cc: gcc-patches
Hi!
As mentioned in the PR, constexpr.c has been handling cases with ranges
just as the lowest value of the range.
Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
trunk? What about 6.2 (not a regression, but low risk fix for wrong-code)?
2016-08-11 Jakub Jelinek <jakub@redhat.com>
PR c++/72868
* constexpr.c (label_matches): Handle case range expressions.
* g++.dg/cpp1y/constexpr-switch4.C: New test.
--- gcc/cp/constexpr.c.jj 2016-08-10 00:21:07.000000000 +0200
+++ gcc/cp/constexpr.c 2016-08-10 22:17:16.577041975 +0200
@@ -3448,6 +3448,12 @@ label_matches (tree *jump_target, tree_s
{
if (!CASE_LOW (stmt))
default_label = i;
+ else if (CASE_HIGH (stmt))
+ {
+ if (tree_int_cst_le (CASE_LOW (stmt), *jump_target)
+ && tree_int_cst_le (*jump_target, CASE_HIGH (stmt)))
+ return true;
+ }
else if (tree_int_cst_equal (*jump_target, CASE_LOW (stmt)))
return true;
}
--- gcc/testsuite/g++.dg/cpp1y/constexpr-switch4.C.jj 2016-08-10 22:22:29.567129868 +0200
+++ gcc/testsuite/g++.dg/cpp1y/constexpr-switch4.C 2016-08-10 22:23:25.104435699 +0200
@@ -0,0 +1,27 @@
+// PR c++/72868
+// { dg-do compile }
+// { dg-options "-std=gnu++14" }
+
+constexpr int
+foo (int i)
+{
+ switch (i)
+ {
+ case 11 ... 12:
+ return 4;
+ case 0 ... 9:
+ return 3;
+ default:
+ return 7;
+ }
+}
+
+#define SA(X) static_assert((X),#X)
+SA (foo (-1) == 7);
+SA (foo (0) == 3);
+SA (foo (3) == 3);
+SA (foo (9) == 3);
+SA (foo (10) == 7);
+SA (foo (11) == 4);
+SA (foo (12) == 4);
+SA (foo (13) == 7);
Jakub
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [C++ PATCH] Handle CASE_HIGH in constexpr evaluation (PR c++/72868)
2016-08-11 14:55 [C++ PATCH] Handle CASE_HIGH in constexpr evaluation (PR c++/72868) Jakub Jelinek
@ 2016-08-11 15:46 ` Jason Merrill
0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2016-08-11 15:46 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: gcc-patches List
OK for trunk and 6.
On Thu, Aug 11, 2016 at 10:55 AM, Jakub Jelinek <jakub@redhat.com> wrote:
> Hi!
>
> As mentioned in the PR, constexpr.c has been handling cases with ranges
> just as the lowest value of the range.
>
> Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
> trunk? What about 6.2 (not a regression, but low risk fix for wrong-code)?
>
> 2016-08-11 Jakub Jelinek <jakub@redhat.com>
>
> PR c++/72868
> * constexpr.c (label_matches): Handle case range expressions.
>
> * g++.dg/cpp1y/constexpr-switch4.C: New test.
>
> --- gcc/cp/constexpr.c.jj 2016-08-10 00:21:07.000000000 +0200
> +++ gcc/cp/constexpr.c 2016-08-10 22:17:16.577041975 +0200
> @@ -3448,6 +3448,12 @@ label_matches (tree *jump_target, tree_s
> {
> if (!CASE_LOW (stmt))
> default_label = i;
> + else if (CASE_HIGH (stmt))
> + {
> + if (tree_int_cst_le (CASE_LOW (stmt), *jump_target)
> + && tree_int_cst_le (*jump_target, CASE_HIGH (stmt)))
> + return true;
> + }
> else if (tree_int_cst_equal (*jump_target, CASE_LOW (stmt)))
> return true;
> }
> --- gcc/testsuite/g++.dg/cpp1y/constexpr-switch4.C.jj 2016-08-10 22:22:29.567129868 +0200
> +++ gcc/testsuite/g++.dg/cpp1y/constexpr-switch4.C 2016-08-10 22:23:25.104435699 +0200
> @@ -0,0 +1,27 @@
> +// PR c++/72868
> +// { dg-do compile }
> +// { dg-options "-std=gnu++14" }
> +
> +constexpr int
> +foo (int i)
> +{
> + switch (i)
> + {
> + case 11 ... 12:
> + return 4;
> + case 0 ... 9:
> + return 3;
> + default:
> + return 7;
> + }
> +}
> +
> +#define SA(X) static_assert((X),#X)
> +SA (foo (-1) == 7);
> +SA (foo (0) == 3);
> +SA (foo (3) == 3);
> +SA (foo (9) == 3);
> +SA (foo (10) == 7);
> +SA (foo (11) == 4);
> +SA (foo (12) == 4);
> +SA (foo (13) == 7);
>
> Jakub
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-08-11 15:46 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-11 14:55 [C++ PATCH] Handle CASE_HIGH in constexpr evaluation (PR c++/72868) Jakub Jelinek
2016-08-11 15:46 ` Jason Merrill
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).