From 5d77fb196b3b6a2aabbb50ce6502a46078162f67 Mon Sep 17 00:00:00 2001 From: Marc Glisse Date: Mon, 3 Feb 2014 20:07:55 +0100 Subject: [PATCH] re PR c++/53017 (Integer constant expression not constant enough for vector_size) 2014-02-03 Marc Glisse PR c++/53017 PR c++/59211 gcc/c-family/ * c-common.c (handle_aligned_attribute, handle_alloc_size_attribute, handle_vector_size_attribute, handle_nonnull_attribute): Call default_conversion on the attribute argument. (handle_nonnull_attribute): Increment the argument number. gcc/cp/ * tree.c (handle_init_priority_attribute): Call default_conversion on the attribute argument. gcc/ * doc/extend.texi (Function Attributes): Typo. gcc/testsuite/ * c-c++-common/attributes-1.c: New testcase. * g++.dg/cpp0x/constexpr-attribute2.C: Likewise. From-SVN: r207436 --- gcc/ChangeLog | 6 +++++ gcc/c-family/ChangeLog | 9 +++++++ gcc/c-family/c-common.c | 26 +++++++++++++++--- gcc/cp/ChangeLog | 7 +++++ gcc/cp/tree.c | 1 + gcc/doc/extend.texi | 2 +- gcc/testsuite/ChangeLog | 7 +++++ gcc/testsuite/c-c++-common/attributes-1.c | 23 ++++++++++++++++ gcc/testsuite/g++.dg/cpp0x/constexpr-attribute2.C | 32 +++++++++++++++++++++++ 9 files changed, 108 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/c-c++-common/attributes-1.c create mode 100644 gcc/testsuite/g++.dg/cpp0x/constexpr-attribute2.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index f3ebc0cb543..cc69822342f 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2014-02-03 Marc Glisse + + PR c++/53017 + PR c++/59211 + * doc/extend.texi (Function Attributes): Typo. + 2014-02-03 Cong Hou PR tree-optimization/60000 diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index 381535aa651..58dc42ca223 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,12 @@ +2014-02-03 Marc Glisse + + PR c++/53017 + PR c++/59211 + * c-common.c (handle_aligned_attribute, handle_alloc_size_attribute, + handle_vector_size_attribute, handle_nonnull_attribute): Call + default_conversion on the attribute argument. + (handle_nonnull_attribute): Increment the argument number. + 2014-01-31 Marek Polacek PR c/59963 diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index 5ce1a3ef75a..fc12788171c 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -7526,10 +7526,18 @@ handle_aligned_attribute (tree *node, tree ARG_UNUSED (name), tree args, tree decl = NULL_TREE; tree *type = NULL; int is_type = 0; - tree align_expr = (args ? TREE_VALUE (args) - : size_int (ATTRIBUTE_ALIGNED_VALUE / BITS_PER_UNIT)); + tree align_expr; int i; + if (args) + { + align_expr = TREE_VALUE (args); + if (align_expr && TREE_CODE (align_expr) != IDENTIFIER_NODE) + align_expr = default_conversion (align_expr); + } + else + align_expr = size_int (ATTRIBUTE_ALIGNED_VALUE / BITS_PER_UNIT); + if (DECL_P (*node)) { decl = *node; @@ -8023,6 +8031,9 @@ handle_alloc_size_attribute (tree *node, tree ARG_UNUSED (name), tree args, for (; args; args = TREE_CHAIN (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 || TREE_INT_CST_HIGH (position) @@ -8467,6 +8478,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) + size = default_conversion (size); if (!tree_fits_uhwi_p (size)) { @@ -8560,11 +8573,16 @@ handle_nonnull_attribute (tree *node, tree ARG_UNUSED (name), /* Argument list specified. Verify that each argument number references a pointer argument. */ - for (attr_arg_num = 1; args; args = TREE_CHAIN (args)) + for (attr_arg_num = 1; args; attr_arg_num++, args = TREE_CHAIN (args)) { unsigned HOST_WIDE_INT arg_num = 0, ck_num; - if (!get_nonnull_operand (TREE_VALUE (args), &arg_num)) + tree arg = TREE_VALUE (args); + if (arg && TREE_CODE (arg) != IDENTIFIER_NODE + && TREE_CODE (arg) != FUNCTION_DECL) + arg = default_conversion (arg); + + if (!get_nonnull_operand (arg, &arg_num)) { error ("nonnull argument has invalid operand number (argument %lu)", (unsigned long) attr_arg_num); diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index e73246a4a66..5214d9a91ac 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2014-02-03 Marc Glisse + + PR c++/53017 + PR c++/59211 + * tree.c (handle_init_priority_attribute): Call default_conversion on + the attribute argument. + 2014-02-03 Paolo Carlini PR c++/58871 diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index fe2ddabae1d..5567253a61a 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -3250,6 +3250,7 @@ handle_init_priority_attribute (tree* node, int pri; STRIP_NOPS (initp_expr); + initp_expr = default_conversion (initp_expr); if (!initp_expr || TREE_CODE (initp_expr) != INTEGER_CST) { diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index 48a8e990d1a..a42e90490c0 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -2241,7 +2241,7 @@ For instance, @smallexample void* my_calloc(size_t, size_t) __attribute__((alloc_size(1,2))) -void my_realloc(void*, size_t) __attribute__((alloc_size(2))) +void* my_realloc(void*, size_t) __attribute__((alloc_size(2))) @end smallexample @noindent diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 8c7af496954..b7c6252962a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2014-02-03 Marc Glisse + + PR c++/53017 + PR c++/59211 + * c-c++-common/attributes-1.c: New testcase. + * g++.dg/cpp0x/constexpr-attribute2.C: Likewise. + 2014-02-03 Paolo Carlini PR c++/58871 diff --git a/gcc/testsuite/c-c++-common/attributes-1.c b/gcc/testsuite/c-c++-common/attributes-1.c new file mode 100644 index 00000000000..af4dd12275c --- /dev/null +++ b/gcc/testsuite/c-c++-common/attributes-1.c @@ -0,0 +1,23 @@ +/* { dg-do compile } */ +/* { dg-prune-output "undeclared here \\(not in a function\\)|\[^\n\r\]* was not declared in this scope" } */ + +void* my_calloc(unsigned, unsigned) __attribute__((alloc_size(1,bar))); /* { dg-warning "outside range" } */ +void* my_realloc(void*, unsigned) __attribute__((alloc_size(bar))); /* { dg-warning "outside range" } */ + +typedef char vec __attribute__((vector_size(bar))); /* { dg-warning "ignored" } */ + +void f1(char*) __attribute__((nonnull(bar))); /* { dg-error "invalid operand" } */ +void f2(char*) __attribute__((nonnull(1,bar))); /* { dg-error "invalid operand" } */ + +void g() __attribute__((aligned(bar))); /* { dg-error "invalid value|not an integer" } */ + +void foo(void); +void* my_calloc(unsigned, unsigned) __attribute__((alloc_size(1,foo))); /* { dg-warning "outside range" } */ +void* my_realloc(void*, unsigned) __attribute__((alloc_size(foo))); /* { dg-warning "outside range" } */ + +typedef char vec __attribute__((vector_size(foo))); /* { dg-warning "ignored" } */ + +void f1(char*) __attribute__((nonnull(foo))); /* { dg-error "invalid operand" } */ +void f2(char*) __attribute__((nonnull(1,foo))); /* { dg-error "invalid operand" } */ + +void g() __attribute__((aligned(foo))); /* { dg-error "invalid value|not an integer" } */ diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-attribute2.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-attribute2.C new file mode 100644 index 00000000000..755188ee0fb --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-attribute2.C @@ -0,0 +1,32 @@ +// { dg-options -std=gnu++11 } + +struct t { t(); }; + +constexpr int prio = 123; +constexpr int size = 8; +constexpr int pos = 1; +enum A { zero = 0, one, two }; +__attribute__((init_priority(prio))) t a; + +enum class E1 : int { + first = 101, + second, + third, +}; +__attribute__((init_priority(E1::second))) t b; // Should not compile? + +enum E2 { + E2_first = 141, + E2_second, + E2_third, +}; +__attribute__((init_priority(E2_second))) t c; + +void* my_calloc(unsigned, unsigned) __attribute__((alloc_size(pos,two))); +void* my_realloc(void*, unsigned) __attribute__((alloc_size(two))); + +typedef char vec __attribute__((vector_size(size))); + +void f(char*) __attribute__((nonnull(pos))); + +void g() __attribute__((aligned(size))); -- 2.11.4.GIT