public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH][C++] Fix PR67333
@ 2015-08-27 18:35 Mikhail Maltsev
  2015-09-16  6:09 ` [PATCH][PING][C++] " Mikhail Maltsev
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Mikhail Maltsev @ 2015-08-27 18:35 UTC (permalink / raw)
  To: gcc-patches, Jason Merrill

[-- Attachment #1: Type: text/plain, Size: 703 bytes --]

Hi.
This patch fixes a rejects-valid bug related to volatile-qualified arguments of
constexpr functions. This is essentially a one-line change in constexpr.c.
Bootstrapped and regtested on x86_64-pc-linux-gnu. OK for trunk?

gcc/cp/ChangeLog:

2015-08-25  Mikhail Maltsev  <maltsevm@gmail.com>

        PR c++/67333
        * constexpr.c (potential_constant_expression_1): Do not reject
        volatile-qualified values, if there is no lvalue-to-rvalue conversion.

gcc/testsuite/ChangeLog:

2015-08-25  Mikhail Maltsev  <maltsevm@gmail.com>

        PR c++/67333
        * g++.dg/cpp0x/constexpr-67333.C: New test.
        * g++.dg/cpp1y/constexpr-67333.C: New test.

-- 
Regards,
    Mikhail Maltsev

[-- Attachment #2: pr67333.patch --]
[-- Type: text/x-patch, Size: 1991 bytes --]

diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index 1eacb8b..f4ee727 100644
--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -4006,7 +4006,7 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict,
     return false;
   if (t == NULL_TREE)
     return true;
-  if (TREE_THIS_VOLATILE (t))
+  if (TREE_THIS_VOLATILE (t) && (!DECL_P (t) || want_rval))
     {
       if (flags & tf_error)
         error ("expression %qE has side-effects", t);
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-67333.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-67333.C
new file mode 100644
index 0000000..885ece6
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-67333.C
@@ -0,0 +1,29 @@
+// PR c++/67333
+// { dg-do compile { target c++11 } }
+
+template <int N>
+struct integral_constant
+{
+  static constexpr int value = N;
+};
+
+template <typename T, int S>
+constexpr int lengthof (const volatile T (&)[S])
+{
+  return S;
+}
+
+template <typename T, int S>
+constexpr int valueof (const volatile T (&s)[S])  // { dg-error "has side-effects" }
+{
+  return s[0];
+}
+
+int main ()
+{
+  volatile int meow[4] {};
+  integral_constant<lengthof (meow)>::value;  // OK
+  integral_constant<valueof (meow)>::value;   // { dg-error "in a constant expression" }
+  return 0;
+}
+
diff --git a/gcc/testsuite/g++.dg/cpp1y/constexpr-67333.C b/gcc/testsuite/g++.dg/cpp1y/constexpr-67333.C
new file mode 100644
index 0000000..7e3ef21
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/constexpr-67333.C
@@ -0,0 +1,26 @@
+// PR c++/67333
+// { dg-do compile { target c++14 } }
+
+template <int N>
+struct integral_constant
+{
+  static constexpr int value = N;
+};
+
+constexpr int decl (int x)
+{
+  volatile int v = x;
+  return x;
+}
+
+constexpr int use (int x)
+{
+  volatile int v = x;
+  return v;
+} // { dg-error "has side-effects" }
+
+int main()
+{
+  integral_constant<decl (2)>::value; // OK
+  integral_constant<use (2)>::value;  // { dg-error "in a constant expression" }
+}

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH][PING][C++] Fix PR67333
  2015-08-27 18:35 [PATCH][C++] Fix PR67333 Mikhail Maltsev
@ 2015-09-16  6:09 ` Mikhail Maltsev
  2015-10-05 23:47 ` [PATCH][PING^2][C++] " Mikhail Maltsev
  2015-10-06 13:47 ` [PATCH][C++] " Jason Merrill
  2 siblings, 0 replies; 6+ messages in thread
From: Mikhail Maltsev @ 2015-09-16  6:09 UTC (permalink / raw)
  To: gcc-patches, Jason Merrill

Ping.

On 08/27/2015 09:27 PM, Mikhail Maltsev wrote:
> Hi.
> This patch fixes a rejects-valid bug related to volatile-qualified arguments of
> constexpr functions. This is essentially a one-line change in constexpr.c.
> Bootstrapped and regtested on x86_64-pc-linux-gnu. OK for trunk?
> 
> gcc/cp/ChangeLog:
> 
> 2015-08-25  Mikhail Maltsev  <maltsevm@gmail.com>
> 
>         PR c++/67333
>         * constexpr.c (potential_constant_expression_1): Do not reject
>         volatile-qualified values, if there is no lvalue-to-rvalue conversion.
> 
> gcc/testsuite/ChangeLog:
> 
> 2015-08-25  Mikhail Maltsev  <maltsevm@gmail.com>
> 
>         PR c++/67333
>         * g++.dg/cpp0x/constexpr-67333.C: New test.
>         * g++.dg/cpp1y/constexpr-67333.C: New test.
> 

-- 
Regards,
    Mikhail Maltsev

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH][PING^2][C++] Fix PR67333
  2015-08-27 18:35 [PATCH][C++] Fix PR67333 Mikhail Maltsev
  2015-09-16  6:09 ` [PATCH][PING][C++] " Mikhail Maltsev
@ 2015-10-05 23:47 ` Mikhail Maltsev
  2015-10-06 13:47 ` [PATCH][C++] " Jason Merrill
  2 siblings, 0 replies; 6+ messages in thread
From: Mikhail Maltsev @ 2015-10-05 23:47 UTC (permalink / raw)
  To: gcc-patches, Jason Merrill

PING.

On 08/27/2015 09:27 PM, Mikhail Maltsev wrote:
> Hi.
> This patch fixes a rejects-valid bug related to volatile-qualified arguments of
> constexpr functions. This is essentially a one-line change in constexpr.c.
> Bootstrapped and regtested on x86_64-pc-linux-gnu. OK for trunk?
> 
> gcc/cp/ChangeLog:
> 
> 2015-08-25  Mikhail Maltsev  <maltsevm@gmail.com>
> 
>         PR c++/67333
>         * constexpr.c (potential_constant_expression_1): Do not reject
>         volatile-qualified values, if there is no lvalue-to-rvalue conversion.
> 
> gcc/testsuite/ChangeLog:
> 
> 2015-08-25  Mikhail Maltsev  <maltsevm@gmail.com>
> 
>         PR c++/67333
>         * g++.dg/cpp0x/constexpr-67333.C: New test.
>         * g++.dg/cpp1y/constexpr-67333.C: New test.
> 

-- 
Regards,
    Mikhail Maltsev

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH][C++] Fix PR67333
  2015-08-27 18:35 [PATCH][C++] Fix PR67333 Mikhail Maltsev
  2015-09-16  6:09 ` [PATCH][PING][C++] " Mikhail Maltsev
  2015-10-05 23:47 ` [PATCH][PING^2][C++] " Mikhail Maltsev
@ 2015-10-06 13:47 ` Jason Merrill
  2015-10-17 19:49   ` Mikhail Maltsev
  2 siblings, 1 reply; 6+ messages in thread
From: Jason Merrill @ 2015-10-06 13:47 UTC (permalink / raw)
  To: Mikhail Maltsev, gcc-patches

Hi, sorry for the slow response.  Please feel free to ping once a week.

On 08/27/2015 02:27 PM, Mikhail Maltsev wrote:
> +  if (TREE_THIS_VOLATILE (t) && (!DECL_P (t) || want_rval))

Why the !DECL_P check?  Pulling the value out of a volatile INDIRECT_REF 
is just as problematic as from a variable.

Jason

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH][C++] Fix PR67333
  2015-10-06 13:47 ` [PATCH][C++] " Jason Merrill
@ 2015-10-17 19:49   ` Mikhail Maltsev
  2015-10-18  9:31     ` Jason Merrill
  0 siblings, 1 reply; 6+ messages in thread
From: Mikhail Maltsev @ 2015-10-17 19:49 UTC (permalink / raw)
  To: Jason Merrill, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 878 bytes --]

On 10/06/2015 04:46 PM, Jason Merrill wrote:
> Hi, sorry for the slow response.  Please feel free to ping once a week.
> 
> On 08/27/2015 02:27 PM, Mikhail Maltsev wrote:
>> +  if (TREE_THIS_VOLATILE (t) && (!DECL_P (t) || want_rval))
> 
> Why the !DECL_P check?  Pulling the value out of a volatile INDIRECT_REF is just
> as problematic as from a variable.
Hmm... my intent was to check that we are not dealing with an expression, i.e.
that should have been 'EXPR_P' rather than '!DECL_P'.

I changed the condition to 'TREE_THIS_VOLATILE (t) && (EXPR_P (t) || want_rval)'
and also added one more test (the one with 'test_ref' function). The updated
patch passes bootstrap & regtest on x86_64-pc-linux-gnu.

But now I wonder, if the combination 'TREE_THIS_VOLATILE (t) && EXPR_P (t) &&
!want_rval' is possible at all and should it be rejected?

-- 
Regards,
    Mikhail Maltsev

[-- Attachment #2: pr67333-2.patch --]
[-- Type: text/x-patch, Size: 2211 bytes --]

diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index ec9710c..b23d52a 100644
--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -4006,7 +4006,7 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict,
     return false;
   if (t == NULL_TREE)
     return true;
-  if (TREE_THIS_VOLATILE (t))
+  if (TREE_THIS_VOLATILE (t) && (EXPR_P (t) || want_rval))
     {
       if (flags & tf_error)
         error ("expression %qE has side-effects", t);
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-67333.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-67333.C
new file mode 100644
index 0000000..885ece6
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-67333.C
@@ -0,0 +1,29 @@
+// PR c++/67333
+// { dg-do compile { target c++11 } }
+
+template <int N>
+struct integral_constant
+{
+  static constexpr int value = N;
+};
+
+template <typename T, int S>
+constexpr int lengthof (const volatile T (&)[S])
+{
+  return S;
+}
+
+template <typename T, int S>
+constexpr int valueof (const volatile T (&s)[S])  // { dg-error "has side-effects" }
+{
+  return s[0];
+}
+
+int main ()
+{
+  volatile int meow[4] {};
+  integral_constant<lengthof (meow)>::value;  // OK
+  integral_constant<valueof (meow)>::value;   // { dg-error "in a constant expression" }
+  return 0;
+}
+
diff --git a/gcc/testsuite/g++.dg/cpp1y/constexpr-67333.C b/gcc/testsuite/g++.dg/cpp1y/constexpr-67333.C
new file mode 100644
index 0000000..333047a
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/constexpr-67333.C
@@ -0,0 +1,36 @@
+// PR c++/67333
+// { dg-do compile { target c++14 } }
+
+template <int N>
+struct integral_constant
+{
+  static constexpr int value = N;
+};
+
+constexpr int decl (int x)
+{
+  volatile int v = x;
+  return x;
+}
+
+constexpr int use (int x)
+{
+  volatile int v = x;
+  return v;
+} // { dg-error "has side-effects" }
+
+constexpr int test_ref (volatile int &x)
+{
+  volatile int &vol_ref = x;
+  volatile int *vol_ptr = &x;
+  volatile int &vol_deref = *vol_ptr;
+  return 0;
+}
+
+int main()
+{
+  volatile int x = 0;
+  constexpr int t = test_ref (x);
+  integral_constant<decl (2)>::value; // OK
+  integral_constant<use (2)>::value;  // { dg-error "in a constant expression" }
+}

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH][C++] Fix PR67333
  2015-10-17 19:49   ` Mikhail Maltsev
@ 2015-10-18  9:31     ` Jason Merrill
  0 siblings, 0 replies; 6+ messages in thread
From: Jason Merrill @ 2015-10-18  9:31 UTC (permalink / raw)
  To: Mikhail Maltsev, gcc-patches

On 10/17/2015 08:57 AM, Mikhail Maltsev wrote:
> On 10/06/2015 04:46 PM, Jason Merrill wrote:
>> Hi, sorry for the slow response.  Please feel free to ping once a week.
>>
>> On 08/27/2015 02:27 PM, Mikhail Maltsev wrote:
>>> +  if (TREE_THIS_VOLATILE (t) && (!DECL_P (t) || want_rval))
>>
>> Why the !DECL_P check?  Pulling the value out of a volatile INDIRECT_REF is just
>> as problematic as from a variable.

> Hmm... my intent was to check that we are not dealing with an expression, i.e.
> that should have been 'EXPR_P' rather than '!DECL_P'.

But why do you want to check that?  My point is that the same issue can 
occur with an expression.  Can't you just check want_rval?

> But now I wonder, if the combination 'TREE_THIS_VOLATILE (t) && EXPR_P (t) &&
> !want_rval' is possible at all and should it be rejected?

It is possible for a volatile *_REF.

Jason

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-10-18  8:25 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-27 18:35 [PATCH][C++] Fix PR67333 Mikhail Maltsev
2015-09-16  6:09 ` [PATCH][PING][C++] " Mikhail Maltsev
2015-10-05 23:47 ` [PATCH][PING^2][C++] " Mikhail Maltsev
2015-10-06 13:47 ` [PATCH][C++] " Jason Merrill
2015-10-17 19:49   ` Mikhail Maltsev
2015-10-18  9:31     ` 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).