diff mbox

RFA (libstdc++): PATCH to implement C++17 over-aligned new

Message ID CADzB+2kL784gwW5XLimkSEdMF_r1grFGnVacBESrtpDULXWzMw@mail.gmail.com
State New
Headers show

Commit Message

Jason Merrill Sept. 14, 2016, 4:18 p.m. UTC
On Wed, Sep 14, 2016 at 12:08 PM, Christophe Lyon
<christophe.lyon@linaro.org> wrote:
> On 14 September 2016 at 14:11, Andreas Schwab <schwab@linux-m68k.org> wrote:
>> On Sep 13 2016, Jason Merrill <jason@redhat.com> wrote:
>>
>>> On Tue, Sep 13, 2016 at 9:03 AM, Andreas Schwab <schwab@linux-m68k.org> wrote:
>>>> On Sep 13 2016, Jason Merrill <jason@redhat.com> wrote:
>>>>
>>>>> Does this help?
>>>>
>>>> Unfortunatly no.
>>>
>>> It occurs to me that this function doesn't need to restrict types at
>>> all.  I'm checking this in; hopefully it will do the trick.
>>
>> That didn't change anything either.
>>
>
> I confirm no change on arm* either.
> On aarch64, gen-attrs-[25]1.C, and devirt-33 now work.
> name-clash11.C still fails on both targets

Ah, I needed to remove the limit on field alignment as well.  This
seems to fix things.
commit 367afdb008cfb122e9bb2c73ba0a8d8b29a738c0
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Sep 14 11:12:09 2016 -0400

            * c-common.c (check_cxx_fundamental_alignment_constraints): Don't
            limit FIELD_DECL, either.

Comments

Rainer Orth Sept. 15, 2016, 9:26 a.m. UTC | #1
Hi Jason,

>> I confirm no change on arm* either.
>> On aarch64, gen-attrs-[25]1.C, and devirt-33 now work.
>> name-clash11.C still fails on both targets
>
> Ah, I needed to remove the limit on field alignment as well.  This
> seems to fix things.

The failures are gone on Solaris/SPARC (sparc-sun-solaris2.12) now, with
one exception (when run as C test):

32-bit:

FAIL: c-c++-common/pr52181.c  -Wc++-compat   (test for bogus messages, line 11)
FAIL: c-c++-common/pr52181.c  -Wc++-compat  (test for excess errors)

This is new with you last patch.

Excess errors:
/vol/gcc/src/hg/trunk/local/gcc/testsuite/c-c++-common/pr52181.c:6:1: warning: requested alignment 16 is larger than 8 [-Wattributes]
/vol/gcc/src/hg/trunk/local/gcc/testsuite/c-c++-common/pr52181.c:8:1: warning: requested alignment 16 is larger than 8 [-Wattributes]

	Rainer
Christophe Lyon Sept. 15, 2016, 12:12 p.m. UTC | #2
On 15 September 2016 at 11:26, Rainer Orth <ro@cebitec.uni-bielefeld.de> wrote:
> Hi Jason,
>
>>> I confirm no change on arm* either.
>>> On aarch64, gen-attrs-[25]1.C, and devirt-33 now work.
>>> name-clash11.C still fails on both targets
>>
>> Ah, I needed to remove the limit on field alignment as well.  This
>> seems to fix things.
>
> The failures are gone on Solaris/SPARC (sparc-sun-solaris2.12) now, with
> one exception (when run as C test):
>
> 32-bit:
>
> FAIL: c-c++-common/pr52181.c  -Wc++-compat   (test for bogus messages, line 11)
> FAIL: c-c++-common/pr52181.c  -Wc++-compat  (test for excess errors)
>

Hi Jason,

Same on arm* if that's easier for you.

Christophe


> This is new with you last patch.
>
> Excess errors:
> /vol/gcc/src/hg/trunk/local/gcc/testsuite/c-c++-common/pr52181.c:6:1: warning: requested alignment 16 is larger than 8 [-Wattributes]
> /vol/gcc/src/hg/trunk/local/gcc/testsuite/c-c++-common/pr52181.c:8:1: warning: requested alignment 16 is larger than 8 [-Wattributes]
>
>         Rainer
>
> --
> -----------------------------------------------------------------------------
> Rainer Orth, Center for Biotechnology, Bielefeld University
diff mbox

Patch

diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index b561f9f..57b6671 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -7868,43 +7868,21 @@  check_cxx_fundamental_alignment_constraints (tree node,
   if (cxx_fundamental_alignment_p (requested_alignment))
     return true;
 
-  if (DECL_P (node))
+  if (VAR_P (node))
     {
       if (TREE_STATIC (node))
-	{
-	  /* For file scope variables and static members, the target
-	     supports alignments that are at most
-	     MAX_OFILE_ALIGNMENT.  */
-	  if (requested_alignment > (max_align = MAX_OFILE_ALIGNMENT))
-	    alignment_too_large_p = true;
-	}
+	/* For file scope variables and static members, the target supports
+	   alignments that are at most MAX_OFILE_ALIGNMENT.  */
+	max_align = MAX_OFILE_ALIGNMENT;
       else
-	{
-#ifdef BIGGEST_FIELD_ALIGNMENT
-#define MAX_TARGET_FIELD_ALIGNMENT BIGGEST_FIELD_ALIGNMENT
-#else
-#define MAX_TARGET_FIELD_ALIGNMENT BIGGEST_ALIGNMENT
-#endif
-	  /* For non-static members, the target supports either
-	     alignments that at most either BIGGEST_FIELD_ALIGNMENT
-	     if it is defined or BIGGEST_ALIGNMENT.  */
-	  max_align = MAX_TARGET_FIELD_ALIGNMENT;
-	  if (TREE_CODE (node) == FIELD_DECL
-	      && requested_alignment > (max_align = MAX_TARGET_FIELD_ALIGNMENT))
-	    alignment_too_large_p = true;
-#undef MAX_TARGET_FIELD_ALIGNMENT
-	  /* For stack variables, the target supports at most
-	     MAX_STACK_ALIGNMENT.  */
-	  else if (decl_function_context (node) != NULL
-		   && requested_alignment > (max_align = MAX_STACK_ALIGNMENT))
-	    alignment_too_large_p = true;
-	}
-    }
-  else if (TYPE_P (node))
-    {
-      /* Let's be liberal for types; don't limit their alignment any more than
-	 check_user_alignment already did.  */
+	/* For stack variables, the target supports at most
+	   MAX_STACK_ALIGNMENT.  */
+	max_align = MAX_STACK_ALIGNMENT;
+      if (requested_alignment > max_align)
+	alignment_too_large_p = true;
     }
+  /* Let's be liberal for types and fields; don't limit their alignment any
+     more than check_user_alignment already did.  */
 
   if (alignment_too_large_p)
     pedwarn (input_location, OPT_Wattributes,
diff --git a/gcc/testsuite/g++.dg/cpp0x/gen-attrs-52.C b/gcc/testsuite/g++.dg/cpp0x/gen-attrs-52.C
index 0f87fd4..ad7cffc 100644
--- a/gcc/testsuite/g++.dg/cpp0x/gen-attrs-52.C
+++ b/gcc/testsuite/g++.dg/cpp0x/gen-attrs-52.C
@@ -3,19 +3,22 @@ 
 struct A {int i;}  a [[gnu::aligned(16)]];
 struct B {int i;} __attribute__((aligned(16))) b;
 
+constexpr unsigned si = sizeof(int);
+constexpr unsigned ai = alignof(int);
+
 int
 main ()
 {
  A aa;
  B bb;
 
- static_assert (sizeof (a) == 4, "sizeof (a) should be 4");
+ static_assert (sizeof (a) == si, "sizeof (a) should be 4");
  static_assert (sizeof (b) == 16, "sizeof (b) should be 16");
- static_assert (sizeof (aa) == 4, "sizeof (aa) should be 4");
+ static_assert (sizeof (aa) == si, "sizeof (aa) should be 4");
  static_assert (sizeof (bb) == 16, "sizeof (bb) should be 16");
 
  static_assert (__alignof__  (a) == 16, "alignof (a) should be 16");
  static_assert (__alignof__  (b) == 16, "alignof (b) should be 16");
- static_assert (__alignof__  (aa) == 4, "alignof (aa) should be 4");
+ static_assert (__alignof__  (aa) == ai, "alignof (aa) should be 4");
  static_assert (__alignof__  (bb) == 16, "alignof (bb) should be 16");
 }