public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-1444] c-family: Copy DECL_USER_ALIGN even if DECL_ALIGN is similar.
@ 2021-06-15  8:03 Robin Dapp
  0 siblings, 0 replies; only message in thread
From: Robin Dapp @ 2021-06-15  8:03 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:ba2eef033e59d80fde35d0cc3acf4d82f7706e60

commit r12-1444-gba2eef033e59d80fde35d0cc3acf4d82f7706e60
Author: Robin Dapp <rdapp@linux.ibm.com>
Date:   Tue Jun 15 09:06:02 2021 +0200

    c-family: Copy DECL_USER_ALIGN even if DECL_ALIGN is similar.
    
    When re-declaring a function with differing attributes DECL_USER_ALIGN
    is usually not merged/copied when DECL_ALIGN is similar.  On s390 this
    will cause a warning message not to be shown.  Similarly, we warned
    about the wrong alignment when short-circuiting an alignment initialization in
    common_handle_aligned_attribute ().
    
    Fix this by copying DECL_USER_ALIGN even if DECL_ALIGN is similar as
    well as getting rid of the short-circuited initialization.
    
    gcc/c-family/ChangeLog:
    
            * c-attribs.c (common_handle_aligned_attribute): Remove short
            circuit and dead code.
    
    gcc/c/ChangeLog:
    
            * c-decl.c (merge_decls): Copy DECL_USER_ALIGN if DECL_ALIGN is
            similar.
    
    gcc/cp/ChangeLog:
    
            * decl.c (duplicate_decls): Likewise.

Diff:
---
 gcc/c-family/c-attribs.c | 30 +++++++-----------------------
 gcc/c/c-decl.c           |  3 +++
 gcc/cp/decl.c            |  4 ++++
 3 files changed, 14 insertions(+), 23 deletions(-)

diff --git a/gcc/c-family/c-attribs.c b/gcc/c-family/c-attribs.c
index 6bf492afcc0..e60fb31d8c8 100644
--- a/gcc/c-family/c-attribs.c
+++ b/gcc/c-family/c-attribs.c
@@ -2338,14 +2338,17 @@ common_handle_aligned_attribute (tree *node, tree name, tree args, int flags,
       *no_add_attrs = true;
     }
   else if (TREE_CODE (decl) == FUNCTION_DECL
-	   && ((curalign = DECL_ALIGN (decl)) > bitalign
-	       || ((lastalign = DECL_ALIGN (last_decl)) > bitalign)))
+	   && (((curalign = DECL_ALIGN (decl)) > bitalign)
+	       | ((lastalign = DECL_ALIGN (last_decl)) > bitalign)))
     {
       /* Either a prior attribute on the same declaration or one
 	 on a prior declaration of the same function specifies
 	 stricter alignment than this attribute.  */
-      bool note = lastalign != 0;
-      if (lastalign)
+      bool note = (lastalign > curalign
+		   || (lastalign == curalign
+		       && (DECL_USER_ALIGN (last_decl)
+			   > DECL_USER_ALIGN (decl))));
+      if (note)
 	curalign = lastalign;
 
       curalign /= BITS_PER_UNIT;
@@ -2390,25 +2393,6 @@ common_handle_aligned_attribute (tree *node, tree name, tree args, int flags,
       This formally comes from the c++11 specification but we are
       doing it for the GNU attribute syntax as well.  */
     *no_add_attrs = true;
-  else if (!warn_if_not_aligned_p
-	   && TREE_CODE (decl) == FUNCTION_DECL
-	   && DECL_ALIGN (decl) > bitalign)
-    {
-      /* Don't warn for function alignment here if warn_if_not_aligned_p
-	 is true.  It will be warned about later.  */
-      if (DECL_USER_ALIGN (decl))
-	{
-	  /* Only reject attempts to relax/override an alignment
-	     explicitly specified previously and accept declarations
-	     that appear to relax the implicit function alignment for
-	     the target.  Both increasing and increasing the alignment
-	     set by -falign-functions setting is permitted.  */
-	  error ("alignment for %q+D was previously specified as %d "
-		 "and may not be decreased", decl,
-		 DECL_ALIGN (decl) / BITS_PER_UNIT);
-	  *no_add_attrs = true;
-	}
-    }
   else if (warn_if_not_aligned_p
 	   && TREE_CODE (decl) == FIELD_DECL
 	   && !DECL_C_BIT_FIELD (decl))
diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c
index a86792bbe06..7cd13a593eb 100644
--- a/gcc/c/c-decl.c
+++ b/gcc/c/c-decl.c
@@ -2620,6 +2620,9 @@ merge_decls (tree newdecl, tree olddecl, tree newtype, tree oldtype)
 	  SET_DECL_ALIGN (newdecl, DECL_ALIGN (olddecl));
 	  DECL_USER_ALIGN (newdecl) |= DECL_USER_ALIGN (olddecl);
 	}
+      else if (DECL_ALIGN (olddecl) == DECL_ALIGN (newdecl)
+	       && DECL_USER_ALIGN (olddecl) != DECL_USER_ALIGN (newdecl))
+	DECL_USER_ALIGN (newdecl) = 1;
       if (DECL_WARN_IF_NOT_ALIGN (olddecl)
 	  > DECL_WARN_IF_NOT_ALIGN (newdecl))
 	SET_DECL_WARN_IF_NOT_ALIGN (newdecl,
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index f5596b689a2..02772e94763 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -2805,6 +2805,10 @@ duplicate_decls (tree newdecl, tree olddecl, bool hiding, bool was_hidden)
       SET_DECL_ALIGN (newdecl, DECL_ALIGN (olddecl));
       DECL_USER_ALIGN (newdecl) |= DECL_USER_ALIGN (olddecl);
     }
+  else if (DECL_ALIGN (olddecl) == DECL_ALIGN (newdecl)
+      && DECL_USER_ALIGN (olddecl) != DECL_USER_ALIGN (newdecl))
+    DECL_USER_ALIGN (newdecl) = 1;
+
   DECL_USER_ALIGN (olddecl) = DECL_USER_ALIGN (newdecl);
   if (DECL_WARN_IF_NOT_ALIGN (olddecl)
       > DECL_WARN_IF_NOT_ALIGN (newdecl))


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-06-15  8:03 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-15  8:03 [gcc r12-1444] c-family: Copy DECL_USER_ALIGN even if DECL_ALIGN is similar Robin Dapp

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).