c++: Drop alignas restriction for stack variables.
authorJason Merrill <jason@redhat.com>
Wed, 29 Jan 2020 22:16:12 +0000 (17:16 -0500)
committerJason Merrill <jason@redhat.com>
Thu, 30 Jan 2020 00:38:32 +0000 (19:38 -0500)
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.

gcc/c-family/ChangeLog
gcc/c-family/c-attribs.c
gcc/testsuite/g++.dg/cpp0x/alignas17.C [new file with mode: 0644]

index 023e49ae5086954805d54d4407e16487437bc71f..b15630df41bf567852209fec3d5ae72b95fd825b 100644 (file)
@@ -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.
index dc9579c5c606945e71090bae338b0d72039f8bad..7ec6fc848ac0ca31c11e0abb5bc025f9e7105bf9 100644 (file)
@@ -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;
diff --git a/gcc/testsuite/g++.dg/cpp0x/alignas17.C b/gcc/testsuite/g++.dg/cpp0x/alignas17.C
new file mode 100644 (file)
index 0000000..b736083
--- /dev/null
@@ -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);
+}