public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Richard Biener <rguenth@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r10-9553] c-family: ICE with assume_aligned attribute [PR99062]
Date: Mon, 29 Mar 2021 12:38:22 +0000 (GMT)	[thread overview]
Message-ID: <20210329123822.9EA983858002@sourceware.org> (raw)

https://gcc.gnu.org/g:9d020d111fbeae228b20d75a8c832b214e561ab3

commit r10-9553-g9d020d111fbeae228b20d75a8c832b214e561ab3
Author: Marek Polacek <polacek@redhat.com>
Date:   Wed Feb 10 15:24:25 2021 -0500

    c-family: ICE with assume_aligned attribute [PR99062]
    
    We ICE in handle_assume_aligned_attribute since r271338 which added
    
    @@ -2935,8 +2936,8 @@ handle_assume_aligned_attribute (tree *node, tree name, tree args, int,
              /* The misalignment specified by the second argument
                 must be non-negative and less than the alignment.  */
              warning (OPT_Wattributes,
    -                  "%qE attribute argument %E is not in the range [0, %E)",
    -                  name, val, align);
    +                  "%qE attribute argument %E is not in the range [0, %wu]",
    +                  name, val, tree_to_uhwi (align) - 1);
              *no_add_attrs = true;
              return NULL_TREE;
            }
    because align is INT_MIN and tree_to_uhwi asserts tree_fits_uhwi_p -- which
    ALIGN does not and the prior tree_fits_shwi_p check is fine with it, as
    well as the integer_pow2p check.
    
    Since neither of the arguments to assume_aligned can be negative, I've
    hoisted the tree_int_cst_sgn check.  And add the missing "argument"
    word to an existing warning.
    
    gcc/c-family/ChangeLog:
    
            PR c++/99062
            * c-attribs.c (handle_assume_aligned_attribute): Check that the
            alignment argument is non-negative.  Tweak a warning message.
    
    gcc/testsuite/ChangeLog:
    
            PR c++/99062
            * gcc.dg/attr-assume_aligned-4.c: Adjust dg-warning.
            * g++.dg/ext/attr-assume-aligned.C: New test.
    
    (cherry picked from commit 30a4d95bf76b0a0fdb66ac0211589a4434c83af3)

Diff:
---
 gcc/c-family/c-attribs.c                       | 11 +++++++++--
 gcc/testsuite/g++.dg/ext/attr-assume-aligned.C |  5 +++++
 gcc/testsuite/gcc.dg/attr-assume_aligned-4.c   |  4 ++--
 3 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/gcc/c-family/c-attribs.c b/gcc/c-family/c-attribs.c
index ac936d5bbbb..e67c71a50e7 100644
--- a/gcc/c-family/c-attribs.c
+++ b/gcc/c-family/c-attribs.c
@@ -3001,11 +3001,18 @@ handle_assume_aligned_attribute (tree *node, tree name, tree args, int,
       if (!tree_fits_shwi_p (val))
 	{
 	  warning (OPT_Wattributes,
-		   "%qE attribute %E is not an integer constant",
+		   "%qE attribute argument %E is not an integer constant",
 		   name, val);
 	  *no_add_attrs = true;
 	  return NULL_TREE;
 	}
+      else if (tree_int_cst_sgn (val) < 0)
+	{
+	  warning (OPT_Wattributes,
+		   "%qE attribute argument %E is not positive", name, val);
+	  *no_add_attrs = true;
+	  return NULL_TREE;
+	}
 
       if (!align)
 	{
@@ -3021,7 +3028,7 @@ handle_assume_aligned_attribute (tree *node, tree name, tree args, int,
 
 	  align = val;
 	}
-      else if (tree_int_cst_sgn (val) < 0 || tree_int_cst_le (align, val))
+      else if (tree_int_cst_le (align, val))
 	{
 	  /* The misalignment specified by the second argument
 	     must be non-negative and less than the alignment.  */
diff --git a/gcc/testsuite/g++.dg/ext/attr-assume-aligned.C b/gcc/testsuite/g++.dg/ext/attr-assume-aligned.C
new file mode 100644
index 00000000000..aa57cbb39c7
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/attr-assume-aligned.C
@@ -0,0 +1,5 @@
+// PR c++/99062
+// { dg-do compile }
+
+#define INT_MIN (-__INT_MAX__ - 1)
+void *f () __attribute__ ((assume_aligned (INT_MIN, 4))); // { dg-warning "is not positive" }
diff --git a/gcc/testsuite/gcc.dg/attr-assume_aligned-4.c b/gcc/testsuite/gcc.dg/attr-assume_aligned-4.c
index 2571ab8a683..f6eb6dc4e59 100644
--- a/gcc/testsuite/gcc.dg/attr-assume_aligned-4.c
+++ b/gcc/testsuite/gcc.dg/attr-assume_aligned-4.c
@@ -8,7 +8,7 @@ A (1) void fv_1 (void);       /* { dg-warning ".assume_aligned. attribute ignore
 
 A (1) int fi_1 (void);        /* { dg-warning ".assume_aligned. attribute ignored on a function returning .int." } */
 
-A (-1) void* fpv_m1 (void);   /* { dg-warning ".assume_aligned. attribute argument -1 is not a power of 2" } */
+A (-1) void* fpv_m1 (void);   /* { dg-warning ".assume_aligned. attribute argument -1 is not positive" } */
 
 A (0) void* fpv_0 (void);     /* { dg-warning ".assume_aligned. attribute argument 0 is not a power of 2" } */
 
@@ -23,7 +23,7 @@ A (16385) void* fpv_16kp1 (void);    /* { dg-warning ".assume_aligned. attribute
 
 A (32767) void* fpv_32km1 (void);     /* { dg-warning ".assume_aligned. attribute argument 32767 is not a power of 2" } */
 
-A (4, -1) void* fpv_4_m1 (void);      /* { dg-warning ".assume_aligned. attribute argument -1 is not in the range \\\[0, 3]" } */
+A (4, -1) void* fpv_4_m1 (void);      /* { dg-warning ".assume_aligned. attribute argument -1 is not positive" } */
 
 A (4, 0) void* fpv_4_0 (void);
 A (4, 1) void* fpv_4_1 (void);


                 reply	other threads:[~2021-03-29 12:38 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210329123822.9EA983858002@sourceware.org \
    --to=rguenth@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).