@@ -7539,7 +7539,8 @@ handle_aligned_attribute (tree *node, tree ARG_UNUSED (name), tree args,
if (args)
{
align_expr = TREE_VALUE (args);
- if (align_expr && TREE_CODE (align_expr) != IDENTIFIER_NODE)
+ if (align_expr && TREE_CODE (align_expr) != IDENTIFIER_NODE
+ && TREE_CODE (align_expr) != FUNCTION_DECL)
align_expr = default_conversion (align_expr);
}
else
@@ -8533,7 +8534,8 @@ handle_vector_size_attribute (tree *node, tree name, tree args,
*no_add_attrs = true;
size = TREE_VALUE (args);
- if (size && TREE_CODE (size) != IDENTIFIER_NODE)
+ if (size && TREE_CODE (size) != IDENTIFIER_NODE
+ && TREE_CODE (size) != FUNCTION_DECL)
size = default_conversion (size);
if (!tree_fits_uhwi_p (size))
@@ -8944,8 +8946,12 @@ handle_sentinel_attribute (tree *node, tree name, tree args,
if (args)
{
tree position = TREE_VALUE (args);
+ if (position && TREE_CODE (position) != IDENTIFIER_NODE
+ && TREE_CODE (position) != FUNCTION_DECL)
+ position = default_conversion (position);
- if (TREE_CODE (position) != INTEGER_CST)
+ if (TREE_CODE (position) != INTEGER_CST
+ || !INTEGRAL_TYPE_P (TREE_TYPE (position)))
{
warning (OPT_Wattributes,
"requested position is not an integer constant");
@@ -3912,6 +3912,7 @@ c_parser_attributes (c_parser *parser)
|| c_parser_next_token_is (parser, CPP_KEYWORD))
{
tree attr, attr_name, attr_args;
+ bool attr_takes_id_p;
vec<tree, va_gc> *expr_list;
if (c_parser_next_token_is (parser, CPP_COMMA))
{
@@ -3922,6 +3923,7 @@ c_parser_attributes (c_parser *parser)
attr_name = c_parser_attribute_any_word (parser);
if (attr_name == NULL)
break;
+ attr_takes_id_p = attribute_takes_identifier_p (attr_name);
if (is_cilkplus_vector_p (attr_name))
{
c_token *v_token = c_parser_peek_token (parser);
@@ -3950,6 +3952,15 @@ c_parser_attributes (c_parser *parser)
== CPP_CLOSE_PAREN)))
{
tree arg1 = c_parser_peek_token (parser)->value;
+ if (!attr_takes_id_p)
+ {
+ /* This is for enum values, so that they can be used as
+ an attribute parameter; lookup_name will find their
+ CONST_DECLs. */
+ tree ln = lookup_name (arg1);
+ if (ln)
+ arg1 = ln;
+ }
c_parser_consume_token (parser);
if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
attr_args = build_tree_list (NULL_TREE, arg1);
@@ -0,0 +1,14 @@
+/* PR c/50459 */
+/* { dg-do compile } */
+/* { dg-options "-Wall -Wextra" } */
+
+enum { A = 128, B = 1 };
+void *fn1 (void) __attribute__((assume_aligned (A)));
+void *fn2 (void) __attribute__((assume_aligned (A, 4)));
+void fn3 (void) __attribute__((constructor (A)));
+void fn4 (void) __attribute__((destructor (A)));
+void *fn5 (int) __attribute__((alloc_size (B)));
+void *fn6 (int) __attribute__((alloc_align (B)));
+void fn7 (const char *, ...) __attribute__ ((sentinel (B)));
+int __attribute__((vector_size (A))) a;
+int __attribute__((aligned (A))) foo;