Many attributes that accept integer constant as a parameter call
default_conversion for such constants to perform the usual arithmetic
conversions.  The call to default_conversion is always guarded so as
to prevent a NULL_TREE, an IDENTIFIER_NODE, or a FUNCTION_DECL from
getting into this function.  But the alloc_align attribute was missing
the FUNCTION_DECL check, so we were crashing when someone passed a
function decl as a parameter to it.

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2016-07-28  Marek Polacek  <pola...@redhat.com>

        PR c/71574
        * c-common.c (handle_alloc_align_attribute): Also check FUNCTION_DECL.

        * c-c++-common/pr71574.c: New test.

diff --git gcc/c-family/c-common.c gcc/c-family/c-common.c
index 16e3965..efd9815 100644
--- gcc/c-family/c-common.c
+++ gcc/c-family/c-common.c
@@ -8370,7 +8370,8 @@ handle_alloc_align_attribute (tree *node, tree, tree 
args, int,
 {
   unsigned arg_count = type_num_arguments (*node);
   tree position = TREE_VALUE (args);
-  if (position && TREE_CODE (position) != IDENTIFIER_NODE)
+  if (position && TREE_CODE (position) != IDENTIFIER_NODE
+      && TREE_CODE (position) != FUNCTION_DECL)
     position = default_conversion (position);
 
   if (!tree_fits_uhwi_p (position)
diff --git gcc/testsuite/c-c++-common/pr71574.c 
gcc/testsuite/c-c++-common/pr71574.c
index e69de29..320ae38 100644
--- gcc/testsuite/c-c++-common/pr71574.c
+++ gcc/testsuite/c-c++-common/pr71574.c
@@ -0,0 +1,12 @@
+/* PR c/71574 */
+/* { dg-do compile } */
+
+int fn1 (void);
+int fn2 (void) __attribute__ ((alloc_align (fn1))); /* { dg-warning "parameter 
outside range" } */
+int fn3 (void) __attribute__ ((alloc_size (fn1))); /* { dg-warning "parameter 
outside range" } */
+int fn4 (void) __attribute__ ((assume_aligned (fn1))); /* { dg-warning "not 
integer constant" } */
+int fn5 (char *, char *) __attribute__((nonnull (fn1))); /* { dg-error 
"nonnull argument has invalid operand" } */
+int fn6 (const char *, ...) __attribute__ ((sentinel (fn1))); /* { dg-warning 
"not an integer constant" } */
+
+typedef int __attribute__((vector_size (fn1))) v4si; /* { dg-warning 
"attribute ignored" } */
+typedef int T __attribute__((aligned (fn1))); /* { dg-error "requested 
alignment is not" } */

        Marek

Reply via email to