c++: Drop alignas restriction for stack variables.
Since expand_stack_vars and such know how to deal with variables aligned beyond MAX_SUPPORTED_STACK_ALIGNMENT, we shouldn't reject alignas of large alignments. And if we don't do that, there's no point in having check_cxx_fundamental_alignment_constraints at all, since check_user_alignment already enforces MAX_OFILE_ALIGNMENT. PR c++/89357 * c-attribs.c (check_cxx_fundamental_alignment_constraints): Remove.
This commit is contained in:
parent
8be8e32faf
commit
e3b6c052b6
|
@ -1,3 +1,8 @@
|
|||
2020-01-29 Jason Merrill <jason@redhat.com>
|
||||
|
||||
PR c++/89357
|
||||
* c-attribs.c (check_cxx_fundamental_alignment_constraints): Remove.
|
||||
|
||||
2020-01-23 Jason Merrill <jason@redhat.com>
|
||||
|
||||
* c-warn.c (conversion_warning): Change -Wsign-conversion handling.
|
||||
|
|
|
@ -1957,65 +1957,6 @@ fail:
|
|||
return res;
|
||||
}
|
||||
|
||||
/* If in c++-11, check if the c++-11 alignment constraint with respect
|
||||
to fundamental alignment (in [dcl.align]) are satisfied. If not in
|
||||
c++-11 mode, does nothing.
|
||||
|
||||
[dcl.align]2/ says:
|
||||
|
||||
[* if the constant expression evaluates to a fundamental alignment,
|
||||
the alignment requirement of the declared entity shall be the
|
||||
specified fundamental alignment.
|
||||
|
||||
* if the constant expression evaluates to an extended alignment
|
||||
and the implementation supports that alignment in the context
|
||||
of the declaration, the alignment of the declared entity shall
|
||||
be that alignment
|
||||
|
||||
* if the constant expression evaluates to an extended alignment
|
||||
and the implementation does not support that alignment in the
|
||||
context of the declaration, the program is ill-formed]. */
|
||||
|
||||
static bool
|
||||
check_cxx_fundamental_alignment_constraints (tree node,
|
||||
unsigned align_log,
|
||||
int flags)
|
||||
{
|
||||
bool alignment_too_large_p = false;
|
||||
unsigned requested_alignment = (1U << align_log) * BITS_PER_UNIT;
|
||||
unsigned max_align = 0;
|
||||
|
||||
if ((!(flags & ATTR_FLAG_CXX11) && !warn_cxx_compat)
|
||||
|| (node == NULL_TREE || node == error_mark_node))
|
||||
return true;
|
||||
|
||||
if (cxx_fundamental_alignment_p (requested_alignment))
|
||||
return true;
|
||||
|
||||
if (VAR_P (node))
|
||||
{
|
||||
if (TREE_STATIC (node) || DECL_EXTERNAL (node))
|
||||
/* For file scope variables and static members, the target supports
|
||||
alignments that are at most MAX_OFILE_ALIGNMENT. */
|
||||
max_align = MAX_OFILE_ALIGNMENT;
|
||||
else
|
||||
/* 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,
|
||||
"requested alignment %d is larger than %d",
|
||||
requested_alignment / BITS_PER_UNIT, max_align / BITS_PER_UNIT);
|
||||
|
||||
return !alignment_too_large_p;
|
||||
}
|
||||
|
||||
/* Common codes shared by handle_warn_if_not_aligned_attribute and
|
||||
handle_aligned_attribute. */
|
||||
|
||||
|
@ -2059,8 +2000,7 @@ common_handle_aligned_attribute (tree *node, tree name, tree args, int flags,
|
|||
/* Log2 of specified alignment. */
|
||||
int pow2align = check_user_alignment (align_expr, objfile,
|
||||
/* warn_zero = */ true);
|
||||
if (pow2align == -1
|
||||
|| !check_cxx_fundamental_alignment_constraints (*node, pow2align, flags))
|
||||
if (pow2align == -1)
|
||||
{
|
||||
*no_add_attrs = true;
|
||||
return NULL_TREE;
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
// PR c++/89357
|
||||
// { dg-do compile { target c++11 } }
|
||||
|
||||
void g(int &);
|
||||
|
||||
void f0() {
|
||||
__attribute__((aligned(128))) static int x;
|
||||
g(x);
|
||||
}
|
||||
|
||||
void f1() {
|
||||
alignas(128) int x;
|
||||
g(x);
|
||||
}
|
Loading…
Reference in New Issue