Commit 38711381 by Jason Merrill Committed by Jason Merrill

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

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

From-SVN: r240139
parent 0761f6bf
2016-09-14 Jason Merrill <jason@redhat.com>
* c-common.c (check_cxx_fundamental_alignment_constraints): Don't
limit FIELD_DECL, either.
2016-09-14 Marek Polacek <polacek@redhat.com> 2016-09-14 Marek Polacek <polacek@redhat.com>
* c-common.c (c_common_truthvalue_conversion): Use false instead of 0. * c-common.c (c_common_truthvalue_conversion): Use false instead of 0.
......
...@@ -7868,43 +7868,21 @@ check_cxx_fundamental_alignment_constraints (tree node, ...@@ -7868,43 +7868,21 @@ check_cxx_fundamental_alignment_constraints (tree node,
if (cxx_fundamental_alignment_p (requested_alignment)) if (cxx_fundamental_alignment_p (requested_alignment))
return true; return true;
if (DECL_P (node)) if (VAR_P (node))
{ {
if (TREE_STATIC (node)) if (TREE_STATIC (node))
{ /* For file scope variables and static members, the target supports
/* For file scope variables and static members, the target alignments that are at most MAX_OFILE_ALIGNMENT. */
supports alignments that are at most max_align = MAX_OFILE_ALIGNMENT;
MAX_OFILE_ALIGNMENT. */
if (requested_alignment > (max_align = MAX_OFILE_ALIGNMENT))
alignment_too_large_p = true;
}
else 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 /* For stack variables, the target supports at most
MAX_STACK_ALIGNMENT. */ MAX_STACK_ALIGNMENT. */
else if (decl_function_context (node) != NULL max_align = MAX_STACK_ALIGNMENT;
&& requested_alignment > (max_align = MAX_STACK_ALIGNMENT)) if (requested_alignment > max_align)
alignment_too_large_p = true; alignment_too_large_p = true;
} }
} /* Let's be liberal for types and fields; don't limit their alignment any
else if (TYPE_P (node)) more than check_user_alignment already did. */
{
/* Let's be liberal for types; don't limit their alignment any more than
check_user_alignment already did. */
}
if (alignment_too_large_p) if (alignment_too_large_p)
pedwarn (input_location, OPT_Wattributes, pedwarn (input_location, OPT_Wattributes,
......
...@@ -3,19 +3,22 @@ ...@@ -3,19 +3,22 @@
struct A {int i;} a [[gnu::aligned(16)]]; struct A {int i;} a [[gnu::aligned(16)]];
struct B {int i;} __attribute__((aligned(16))) b; struct B {int i;} __attribute__((aligned(16))) b;
constexpr unsigned si = sizeof(int);
constexpr unsigned ai = alignof(int);
int int
main () main ()
{ {
A aa; A aa;
B bb; 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 (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 (sizeof (bb) == 16, "sizeof (bb) should be 16");
static_assert (__alignof__ (a) == 16, "alignof (a) 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__ (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"); static_assert (__alignof__ (bb) == 16, "alignof (bb) should be 16");
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment