diff mbox series

Fix testsuite/g++.dg/cpp1y/constexpr-66093.C execution failure...

Message ID or8s9ph5xz.fsf@lxoliva.fsfla.org
State New
Headers show
Series Fix testsuite/g++.dg/cpp1y/constexpr-66093.C execution failure... | expand

Commit Message

Alexandre Oliva Dec. 22, 2020, 9:44 p.m. UTC
The constexpr iteration dereferenced an array element past the end of
the array.

Regstrapped on x86_64-linux-gnu, and tested with -x-arm-wrs-vxworks7r2.
Ok to install?


from Jerome Lambourg <lambourg@adacore.com>
for  gcc/testsuite/ChangeLog

        * g++.dg/cpp1y/constexpr-66093.C: Fix bounds issue.
---
 gcc/testsuite/g++.dg/cpp1y/constexpr-66093.C |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Mike Stump Dec. 29, 2020, 6:45 p.m. UTC | #1
On Dec 22, 2020, at 1:44 PM, Alexandre Oliva <oliva@adacore.com> wrote:
> 
> The constexpr iteration dereferenced an array element past the end of
> the array.
> 
> Regstrapped on x86_64-linux-gnu, and tested with -x-arm-wrs-vxworks7r2.
> Ok to install?

How about:

  a[i-1] = i;

instead?  This I think better matches the comment in the code, and preserves the expected output as well.

If you like that and that works, Ok for that version.

> from Jerome Lambourg <lambourg@adacore.com>
> for  gcc/testsuite/ChangeLog
> 
>        * g++.dg/cpp1y/constexpr-66093.C: Fix bounds issue.
> ---
> gcc/testsuite/g++.dg/cpp1y/constexpr-66093.C |    2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/gcc/testsuite/g++.dg/cpp1y/constexpr-66093.C b/gcc/testsuite/g++.dg/cpp1y/constexpr-66093.C
> index ad3169210d29a..3d742cfebd83d 100644
> --- a/gcc/testsuite/g++.dg/cpp1y/constexpr-66093.C
> +++ b/gcc/testsuite/g++.dg/cpp1y/constexpr-66093.C
> @@ -19,7 +19,7 @@ private:
> 
> constexpr A f() {
>     A a{};
> -    for (int i = 1; i <= n; i++) {
> +    for (int i = 0; i < n; i++) {
>         a[i] = i;
>     }
>     return a;
Alexandre Oliva Jan. 1, 2021, 11:37 p.m. UTC | #2
On Dec 29, 2020, Mike Stump <mikestump@comcast.net> wrote:

>   a[i-1] = i;

'fraid that won't pass:

    for (int i = 0; i < n; i++) {
        assert (a[i] == i);
    }


we could make it:

    a[i-1] = i-1;

but...  yuck.

IMHO it's a lot less surprising to have an init loop that matches the check.


>> +++ b/gcc/testsuite/g++.dg/cpp1y/constexpr-66093.C
>> @@ -19,7 +19,7 @@ private:
>> 
>> constexpr A f() {
>> A a{};
>> -    for (int i = 1; i <= n; i++) {
>> +    for (int i = 0; i < n; i++) {
>> a[i] = i;
>> }
>> return a;
Mike Stump Jan. 2, 2021, 12:28 a.m. UTC | #3
On Jan 1, 2021, at 3:37 PM, Alexandre Oliva <oliva@adacore.com> wrote:
> 
> On Dec 29, 2020, Mike Stump <mikestump@comcast.net> wrote:
> 
>>  a[i-1] = i;
> 
> 'fraid that won't pass:
> 
>    for (int i = 0; i < n; i++) {
>        assert (a[i] == i);
>    }

Ok, how about your version with the comment updated?
Alexandre Oliva Jan. 2, 2021, 2:41 a.m. UTC | #4
On Jan  1, 2021, Mike Stump <mikestump@comcast.net> wrote:

> On Jan 1, 2021, at 3:37 PM, Alexandre Oliva <oliva@adacore.com> wrote:
>> 
>> On Dec 29, 2020, Mike Stump <mikestump@comcast.net> wrote:
>> 
>>> a[i-1] = i;
>> 
>> 'fraid that won't pass:
>> 
>> for (int i = 0; i < n; i++) {
>> assert (a[i] == i);
>> }

> Ok, how about your version with the comment updated?

Err, are we talking about the same testcase?
There aren't any comments in this one.
Mike Stump Jan. 4, 2021, 8 p.m. UTC | #5
On Jan 1, 2021, at 6:41 PM, Alexandre Oliva <oliva@adacore.com> wrote:
> 
> On Jan  1, 2021, Mike Stump <mikestump@comcast.net> wrote:
> 
>> On Jan 1, 2021, at 3:37 PM, Alexandre Oliva <oliva@adacore.com> wrote:
>>> 
>>> On Dec 29, 2020, Mike Stump <mikestump@comcast.net> wrote:
>>> 
>>>> a[i-1] = i;
>>> 
>>> 'fraid that won't pass:
>>> 
>>> for (int i = 0; i < n; i++) {
>>> assert (a[i] == i);
>>> }
> 
>> Ok, how about your version with the comment updated?
> 
> Err, are we talking about the same testcase?
> There aren't any comments in this one.

Oh, It's possible the comments were stripped from the bug report or initial email.  Never mind then about the comment part.
Alexandre Oliva Jan. 5, 2021, 7:56 a.m. UTC | #6
On Jan  4, 2021, Mike Stump <mikestump@comcast.net> wrote:

> Oh, It's possible the comments were stripped from the bug report or
> initial email.  Never mind then about the comment part.

Thanks, I'm installing the initial patch.  Please let me know in case I
mistook the above as approval thereof.
diff mbox series

Patch

diff --git a/gcc/testsuite/g++.dg/cpp1y/constexpr-66093.C b/gcc/testsuite/g++.dg/cpp1y/constexpr-66093.C
index ad3169210d29a..3d742cfebd83d 100644
--- a/gcc/testsuite/g++.dg/cpp1y/constexpr-66093.C
+++ b/gcc/testsuite/g++.dg/cpp1y/constexpr-66093.C
@@ -19,7 +19,7 @@  private:
 
 constexpr A f() {
     A a{};
-    for (int i = 1; i <= n; i++) {
+    for (int i = 0; i < n; i++) {
         a[i] = i;
     }
     return a;