[PATCH] testsuite/102690 - XFAIL g++.dg/warn/Warray-bounds-16.C

Martin Sebor msebor@gmail.com
Wed Nov 10 22:07:47 GMT 2021


On 11/10/21 3:09 AM, Richard Biener via Gcc-patches wrote:
> This XFAILs the bogus diagnostic test and rectifies the expectation
> on the optimization.
> 
> Tested on x86_64-unknown-linux-gnu, pushed.
> 
> 2021-11-10  Richard Biener  <rguenther@suse.de>
> 
> 	PR testsuite/102690
> 	* g++.dg/warn/Warray-bounds-16.C: XFAIL diagnostic part
> 	and optimization.
> ---
>   gcc/testsuite/g++.dg/warn/Warray-bounds-16.C | 6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/gcc/testsuite/g++.dg/warn/Warray-bounds-16.C b/gcc/testsuite/g++.dg/warn/Warray-bounds-16.C
> index 17b4d0d194e..89cbadb91c7 100644
> --- a/gcc/testsuite/g++.dg/warn/Warray-bounds-16.C
> +++ b/gcc/testsuite/g++.dg/warn/Warray-bounds-16.C
> @@ -19,11 +19,11 @@ struct S
>       p = (int*) new unsigned char [sizeof (int) * m];
>   
>       for (int i = 0; i < m; i++)
> -      new (p + i) int ();
> +      new (p + i) int (); /* { dg-bogus "bounds" "pr102690" { xfail *-*-* } } */
>     }
>   };
>   
>   S a (0);
>   
> -/* Verify the loop has been eliminated.
> -   { dg-final { scan-tree-dump-not "goto" "optimized" } } */
> +/* The loop cannot be eliminated since the global 'new' can change 'm'.  */

I don't understand this comment.  Can you please explain how
the global operator new (i.e., the one outside the loop below)
can change the member of the class whose ctor calls the new?

The member, or more precisely the enclosing object, doesn't
yet exist at the time the global new is called because its
ctor hasn't finished, so nothing outside the ctor can access
it.  A pointer to the S under construction can be used (and
could be accessed by a replacement new) but it cannot be
dereferenced to access its members because the object it
points to doesn't exist until after the ctor completes.

I copy the test below:

inline void* operator new (__SIZE_TYPE__, void * v)
{
   return v;
}

struct S
{
   int* p;
   int m;

   S (int i)
   {
     m = i;
     p = (int*) new unsigned char [sizeof (int) * m];

     for (int i = 0; i < m; i++)
       new (p + i) int (); /* { dg-bogus "bounds" "pr102690" { xfail 
*-*-* } } */
   }
};

S a (0);

Thanks
Martin


More information about the Gcc-patches mailing list