This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/50459] alignof doesn't work on plain old constant, works with expressions containing it
- From: "mpolacek at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sun, 13 Apr 2014 17:46:13 +0000
- Subject: [Bug c/50459] alignof doesn't work on plain old constant, works with expressions containing it
- Auto-submitted: auto-generated
- References: <bug-50459-4 at http dot gcc dot gnu dot org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50459
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |mpolacek at gcc dot gnu.org
--- Comment #1 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
The problem on the C side of things is that the values of the enum are
represented by CONST_DECL nodes and check_user_alignment doesn't look through
it. So maybe something like the following? (Tested x86_64-linux, no
regressions.)
diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index 1d56bc0..d70ca3d 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -7418,6 +7418,13 @@ check_user_alignment (const_tree align, bool allow_zero)
{
int i;
+ if (TREE_CODE (align) == IDENTIFIER_NODE)
+ {
+ tree t = lookup_name (CONST_CAST_TREE (align));
+ if (t && TREE_CODE (t) == CONST_DECL)
+ align = DECL_INITIAL (t);
+ }
+
if (TREE_CODE (align) != INTEGER_CST
|| !INTEGRAL_TYPE_P (TREE_TYPE (align)))
{