Committed: g++.dg/warn/Wplacement-new-size-1.C, -2, -6: Fix for default_packed targets

Message ID 20210223004857.1E34B203D3@pchp3.se.axis.com
State New
Headers show
Series
  • Committed: g++.dg/warn/Wplacement-new-size-1.C, -2, -6: Fix for default_packed targets
Related show

Commit Message

Ahamed Husni via Gcc-patches Feb. 23, 2021, 12:48 a.m.
Looking at commit de05c19d5fd6, that adjustment to these
tests apparently assumed that the testsuite is run (only) on
targets where structure memory layout has padding as per
"natural alignment".  For cris-elf, a target with no padding
in structure memory layout, these tests have been failing
since that commit.

Tested cris-elf and x86_64-linux, committed as obvious.

gcc/testsuite:
	* g++.dg/warn/Wplacement-new-size-1.C,
	g++.dg/warn/Wplacement-new-size-2.C,
	g++.dg/warn/Wplacement-new-size-6.C: Adjust for
	default_packed targets.
---
 gcc/testsuite/g++.dg/warn/Wplacement-new-size-1.C | 12 ++++++------
 gcc/testsuite/g++.dg/warn/Wplacement-new-size-2.C | 14 +++++++-------
 gcc/testsuite/g++.dg/warn/Wplacement-new-size-6.C | 22 +++++++++++-----------
 3 files changed, 24 insertions(+), 24 deletions(-)

-- 
2.11.0

Comments

Ahamed Husni via Gcc-patches Feb. 23, 2021, 1:07 a.m. | #1
On 2/22/21 5:48 PM, Hans-Peter Nilsson wrote:
> Looking at commit de05c19d5fd6, that adjustment to these

> tests apparently assumed that the testsuite is run (only) on

> targets where structure memory layout has padding as per

> "natural alignment".  For cris-elf, a target with no padding

> in structure memory layout, these tests have been failing

> since that commit.

> 

> Tested cris-elf and x86_64-linux, committed as obvious.


Thanks for the heads up.  Would declaring the structs with attribute
packed work?  If so, that would seem more robust to me since it would
exercise the behavior on all targets.

Martin

> 

> gcc/testsuite:

> 	* g++.dg/warn/Wplacement-new-size-1.C,

> 	g++.dg/warn/Wplacement-new-size-2.C,

> 	g++.dg/warn/Wplacement-new-size-6.C: Adjust for

> 	default_packed targets.

> ---

>   gcc/testsuite/g++.dg/warn/Wplacement-new-size-1.C | 12 ++++++------

>   gcc/testsuite/g++.dg/warn/Wplacement-new-size-2.C | 14 +++++++-------

>   gcc/testsuite/g++.dg/warn/Wplacement-new-size-6.C | 22 +++++++++++-----------

>   3 files changed, 24 insertions(+), 24 deletions(-)

> 

> diff --git a/gcc/testsuite/g++.dg/warn/Wplacement-new-size-1.C b/gcc/testsuite/g++.dg/warn/Wplacement-new-size-1.C

> index cec83163dbe7..1ad5c2da75af 100644

> --- a/gcc/testsuite/g++.dg/warn/Wplacement-new-size-1.C

> +++ b/gcc/testsuite/g++.dg/warn/Wplacement-new-size-1.C

> @@ -67,8 +67,8 @@ void fBx (BAx *pbx, BAx &rbx)

>   {

>     BAx bax;

>     // The uninitialized flexible array takes up the bytes of padding.

> -  new (bax.ax.a) char;

> -  new (bax.ax.a) Int16;

> +  new (bax.ax.a) char;     // { dg-warning "placement" "" { target default_packed } }

> +  new (bax.ax.a) Int16;    // { dg-warning "placement" "" { target default_packed } }

>     new (bax.ax.a) Int32;    // { dg-warning "placement" }

>   

>     new (pbx->ax.a) char;

> @@ -86,10 +86,10 @@ void fBx1 ()

>     static BAx bax1 = { 1, /* Ax = */ { 2, /* a[] = */ {} } };

>   

>     // The empty flexible array takes up the bytes of padding.

> -  new (bax1.ax.a) char;

> -  new (bax1.ax.a) char[2];

> -  new (bax1.ax.a) Int16;

> -  new (bax1.ax.a) char[3];

> +  new (bax1.ax.a) char;     // { dg-warning "placement" "" { target default_packed } }

> +  new (bax1.ax.a) char[2];  // { dg-warning "placement" "" { target default_packed } }

> +  new (bax1.ax.a) Int16;    // { dg-warning "placement" "" { target default_packed } }

> +  new (bax1.ax.a) char[3];  // { dg-warning "placement" "" { target default_packed } }

>     new (bax1.ax.a) char[4];  // { dg-warning "placement" }

>     new (bax1.ax.a) Int32;    // { dg-warning "placement" }

>   }

> diff --git a/gcc/testsuite/g++.dg/warn/Wplacement-new-size-2.C b/gcc/testsuite/g++.dg/warn/Wplacement-new-size-2.C

> index e5fdfe1f603e..a4de2b04629c 100644

> --- a/gcc/testsuite/g++.dg/warn/Wplacement-new-size-2.C

> +++ b/gcc/testsuite/g++.dg/warn/Wplacement-new-size-2.C

> @@ -125,9 +125,9 @@ void fBx (BAx *pbx, BAx &rbx)

>   {

>     BAx bax;

>     // The uninitialized flexible array takes up the bytes of padding.

> -  new (bax.ax.a) char;

> -  new (bax.ax.a) Int16;

> -  new (bax.ax.a) char[3];

> +  new (bax.ax.a) char;        // { dg-warning "placement" "" { target default_packed } }

> +  new (bax.ax.a) Int16;       // { dg-warning "placement" "" { target default_packed } }

> +  new (bax.ax.a) char[3];     // { dg-warning "placement" "" { target default_packed } }

>     new (bax.ax.a) Int32;       // { dg-warning "placement" }

>     new (bax.ax.a) char[4];     // { dg-warning "placement" }

>     new (bax.ax.a) char[5];     // { dg-warning "placement" }

> @@ -147,10 +147,10 @@ void fBx1 ()

>     static BAx bax1 = { 1, /* Ax = */ { 2, /* a[] = */ {} } };

>   

>     // The empty flexible array takes up the bytes of padding.

> -  new (bax1.ax.a) char;

> -  new (bax1.ax.a) char[2];

> -  new (bax1.ax.a) Int16;

> -  new (bax1.ax.a) char[3];

> +  new (bax1.ax.a) char;       // { dg-warning "placement" "" { target default_packed } }

> +  new (bax1.ax.a) char[2];    // { dg-warning "placement" "" { target default_packed } }

> +  new (bax1.ax.a) Int16;      // { dg-warning "placement" "" { target default_packed } }

> +  new (bax1.ax.a) char[3];    // { dg-warning "placement" "" { target default_packed } }

>     new (bax1.ax.a) Int32;      // { dg-warning "placement" }

>     new (bax1.ax.a) char[4];    // { dg-warning "placement" }

>     new (bax1.ax.a) char[5];    // { dg-warning "placement" }

> diff --git a/gcc/testsuite/g++.dg/warn/Wplacement-new-size-6.C b/gcc/testsuite/g++.dg/warn/Wplacement-new-size-6.C

> index 5eb63d23b477..86a18fa08e63 100644

> --- a/gcc/testsuite/g++.dg/warn/Wplacement-new-size-6.C

> +++ b/gcc/testsuite/g++.dg/warn/Wplacement-new-size-6.C

> @@ -18,9 +18,9 @@ void fBx1 ()

>     static BAx bax1 = { 1, /* Ax = */ { 2, /* a[] = */ { 3 } } }; // { dg-error "initialization of flexible array member in a nested context" }

>   

>     // The first three bytes of the flexible array member live in the padding.

> -  new (bax1.ax.a) char;

> -  new (bax1.ax.a) char[2];

> -  new (bax1.ax.a) Int16;

> +  new (bax1.ax.a) char;     // { dg-warning "placement" "" { target default_packed } }

> +  new (bax1.ax.a) char[2];  // { dg-warning "placement" "" { target default_packed } }

> +  new (bax1.ax.a) Int16;    // { dg-warning "placement" "" { target default_packed } }

>     new (bax1.ax.a) Int32;    // { dg-warning "placement" }

>   }

>   

> @@ -29,10 +29,10 @@ void fBx2 ()

>     static BAx bax2 = { 1, /* Ax = */ { 2, /* a[] = */ { 3, 4 } } }; // { dg-error "initialization of flexible array member in a nested context" }

>   

>     // The first three bytes of the flexible array member live in the padding.

> -  new (bax2.ax.a) char;

> -  new (bax2.ax.a) char[2];

> -  new (bax2.ax.a) char[3];

> -  new (bax2.ax.a) Int16;

> +  new (bax2.ax.a) char;       // { dg-warning "placement" "" { target default_packed } }

> +  new (bax2.ax.a) char[2];    // { dg-warning "placement" "" { target default_packed } }

> +  new (bax2.ax.a) char[3];    // { dg-warning "placement" "" { target default_packed } }

> +  new (bax2.ax.a) Int16;      // { dg-warning "placement" "" { target default_packed } }

>     new (bax2.ax.a) char[4];    // { dg-warning "placement" }

>     new (bax2.ax.a) Int32;      // { dg-warning "placement" }

>   }

> @@ -42,10 +42,10 @@ void fBx3 ()

>     static BAx bax2 = { 1, /* Ax = */ { 3, /* a[] = */ { 4, 5, 6 } } }; // { dg-error "initialization of flexible array member in a nested context" }

>   

>     // The first three bytes of the flexible array member live in the padding.

> -  new (bax2.ax.a) char;

> -  new (bax2.ax.a) char[2];

> -  new (bax2.ax.a) Int16;

> -  new (bax2.ax.a) char[3];

> +  new (bax2.ax.a) char;       // { dg-warning "placement" "" { target default_packed } }

> +  new (bax2.ax.a) char[2];    // { dg-warning "placement" "" { target default_packed } }

> +  new (bax2.ax.a) Int16;      // { dg-warning "placement" "" { target default_packed } }

> +  new (bax2.ax.a) char[3];    // { dg-warning "placement" "" { target default_packed } }

>     new (bax2.ax.a) char[4];    // { dg-warning "placement" }

>     new (bax2.ax.a) Int32;      // { dg-warning "placement" }

>   }

>
Ahamed Husni via Gcc-patches Feb. 23, 2021, 1:21 a.m. | #2
> From: Martin Sebor <msebor@gmail.com>

> Date: Tue, 23 Feb 2021 02:07:59 +0100


> On 2/22/21 5:48 PM, Hans-Peter Nilsson wrote:

> > Looking at commit de05c19d5fd6, that adjustment to these

> > tests apparently assumed that the testsuite is run (only) on

> > targets where structure memory layout has padding as per

> > "natural alignment".  For cris-elf, a target with no padding

> > in structure memory layout, these tests have been failing

> > since that commit.

> > 

> > Tested cris-elf and x86_64-linux, committed as obvious.

> 

> Thanks for the heads up.  Would declaring the structs with attribute

> packed work?


That seems likely, yes.

brgds, H-P

Patch

diff --git a/gcc/testsuite/g++.dg/warn/Wplacement-new-size-1.C b/gcc/testsuite/g++.dg/warn/Wplacement-new-size-1.C
index cec83163dbe7..1ad5c2da75af 100644
--- a/gcc/testsuite/g++.dg/warn/Wplacement-new-size-1.C
+++ b/gcc/testsuite/g++.dg/warn/Wplacement-new-size-1.C
@@ -67,8 +67,8 @@  void fBx (BAx *pbx, BAx &rbx)
 {
   BAx bax;
   // The uninitialized flexible array takes up the bytes of padding.
-  new (bax.ax.a) char;
-  new (bax.ax.a) Int16;
+  new (bax.ax.a) char;     // { dg-warning "placement" "" { target default_packed } }
+  new (bax.ax.a) Int16;    // { dg-warning "placement" "" { target default_packed } }
   new (bax.ax.a) Int32;    // { dg-warning "placement" }
 
   new (pbx->ax.a) char;
@@ -86,10 +86,10 @@  void fBx1 ()
   static BAx bax1 = { 1, /* Ax = */ { 2, /* a[] = */ {} } };
 
   // The empty flexible array takes up the bytes of padding.
-  new (bax1.ax.a) char;
-  new (bax1.ax.a) char[2];
-  new (bax1.ax.a) Int16;
-  new (bax1.ax.a) char[3];
+  new (bax1.ax.a) char;     // { dg-warning "placement" "" { target default_packed } }
+  new (bax1.ax.a) char[2];  // { dg-warning "placement" "" { target default_packed } }
+  new (bax1.ax.a) Int16;    // { dg-warning "placement" "" { target default_packed } }
+  new (bax1.ax.a) char[3];  // { dg-warning "placement" "" { target default_packed } }
   new (bax1.ax.a) char[4];  // { dg-warning "placement" }
   new (bax1.ax.a) Int32;    // { dg-warning "placement" }
 }
diff --git a/gcc/testsuite/g++.dg/warn/Wplacement-new-size-2.C b/gcc/testsuite/g++.dg/warn/Wplacement-new-size-2.C
index e5fdfe1f603e..a4de2b04629c 100644
--- a/gcc/testsuite/g++.dg/warn/Wplacement-new-size-2.C
+++ b/gcc/testsuite/g++.dg/warn/Wplacement-new-size-2.C
@@ -125,9 +125,9 @@  void fBx (BAx *pbx, BAx &rbx)
 {
   BAx bax;
   // The uninitialized flexible array takes up the bytes of padding.
-  new (bax.ax.a) char;
-  new (bax.ax.a) Int16;
-  new (bax.ax.a) char[3];
+  new (bax.ax.a) char;        // { dg-warning "placement" "" { target default_packed } }
+  new (bax.ax.a) Int16;       // { dg-warning "placement" "" { target default_packed } }
+  new (bax.ax.a) char[3];     // { dg-warning "placement" "" { target default_packed } }
   new (bax.ax.a) Int32;       // { dg-warning "placement" }
   new (bax.ax.a) char[4];     // { dg-warning "placement" }
   new (bax.ax.a) char[5];     // { dg-warning "placement" }
@@ -147,10 +147,10 @@  void fBx1 ()
   static BAx bax1 = { 1, /* Ax = */ { 2, /* a[] = */ {} } };
 
   // The empty flexible array takes up the bytes of padding.
-  new (bax1.ax.a) char;
-  new (bax1.ax.a) char[2];
-  new (bax1.ax.a) Int16;
-  new (bax1.ax.a) char[3];
+  new (bax1.ax.a) char;       // { dg-warning "placement" "" { target default_packed } }
+  new (bax1.ax.a) char[2];    // { dg-warning "placement" "" { target default_packed } }
+  new (bax1.ax.a) Int16;      // { dg-warning "placement" "" { target default_packed } }
+  new (bax1.ax.a) char[3];    // { dg-warning "placement" "" { target default_packed } }
   new (bax1.ax.a) Int32;      // { dg-warning "placement" }
   new (bax1.ax.a) char[4];    // { dg-warning "placement" }
   new (bax1.ax.a) char[5];    // { dg-warning "placement" }
diff --git a/gcc/testsuite/g++.dg/warn/Wplacement-new-size-6.C b/gcc/testsuite/g++.dg/warn/Wplacement-new-size-6.C
index 5eb63d23b477..86a18fa08e63 100644
--- a/gcc/testsuite/g++.dg/warn/Wplacement-new-size-6.C
+++ b/gcc/testsuite/g++.dg/warn/Wplacement-new-size-6.C
@@ -18,9 +18,9 @@  void fBx1 ()
   static BAx bax1 = { 1, /* Ax = */ { 2, /* a[] = */ { 3 } } }; // { dg-error "initialization of flexible array member in a nested context" }
 
   // The first three bytes of the flexible array member live in the padding.
-  new (bax1.ax.a) char;
-  new (bax1.ax.a) char[2];
-  new (bax1.ax.a) Int16;
+  new (bax1.ax.a) char;     // { dg-warning "placement" "" { target default_packed } }
+  new (bax1.ax.a) char[2];  // { dg-warning "placement" "" { target default_packed } }
+  new (bax1.ax.a) Int16;    // { dg-warning "placement" "" { target default_packed } }
   new (bax1.ax.a) Int32;    // { dg-warning "placement" }
 }
 
@@ -29,10 +29,10 @@  void fBx2 ()
   static BAx bax2 = { 1, /* Ax = */ { 2, /* a[] = */ { 3, 4 } } }; // { dg-error "initialization of flexible array member in a nested context" }
 
   // The first three bytes of the flexible array member live in the padding.
-  new (bax2.ax.a) char;
-  new (bax2.ax.a) char[2];
-  new (bax2.ax.a) char[3];
-  new (bax2.ax.a) Int16;
+  new (bax2.ax.a) char;       // { dg-warning "placement" "" { target default_packed } }
+  new (bax2.ax.a) char[2];    // { dg-warning "placement" "" { target default_packed } }
+  new (bax2.ax.a) char[3];    // { dg-warning "placement" "" { target default_packed } }
+  new (bax2.ax.a) Int16;      // { dg-warning "placement" "" { target default_packed } }
   new (bax2.ax.a) char[4];    // { dg-warning "placement" }
   new (bax2.ax.a) Int32;      // { dg-warning "placement" }
 }
@@ -42,10 +42,10 @@  void fBx3 ()
   static BAx bax2 = { 1, /* Ax = */ { 3, /* a[] = */ { 4, 5, 6 } } }; // { dg-error "initialization of flexible array member in a nested context" }
 
   // The first three bytes of the flexible array member live in the padding.
-  new (bax2.ax.a) char;
-  new (bax2.ax.a) char[2];
-  new (bax2.ax.a) Int16;
-  new (bax2.ax.a) char[3];
+  new (bax2.ax.a) char;       // { dg-warning "placement" "" { target default_packed } }
+  new (bax2.ax.a) char[2];    // { dg-warning "placement" "" { target default_packed } }
+  new (bax2.ax.a) Int16;      // { dg-warning "placement" "" { target default_packed } }
+  new (bax2.ax.a) char[3];    // { dg-warning "placement" "" { target default_packed } }
   new (bax2.ax.a) char[4];    // { dg-warning "placement" }
   new (bax2.ax.a) Int32;      // { dg-warning "placement" }
 }