]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/53017 (Integer constant expression not constant enough for vector_size)
authorMarc Glisse <marc.glisse@inria.fr>
Mon, 3 Feb 2014 19:07:55 +0000 (20:07 +0100)
committerMarc Glisse <glisse@gcc.gnu.org>
Mon, 3 Feb 2014 19:07:55 +0000 (19:07 +0000)
2014-02-03  Marc Glisse  <marc.glisse@inria.fr>

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
gcc/c-family/ChangeLog
gcc/c-family/c-common.c
gcc/cp/ChangeLog
gcc/cp/tree.c
gcc/doc/extend.texi
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/attributes-1.c [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp0x/constexpr-attribute2.C [new file with mode: 0644]

index f3ebc0cb543173c544a84fc18946f92a8eebb72e..cc69822342f06a52d19812a30b601ce5d53b4a71 100644 (file)
@@ -1,3 +1,9 @@
+2014-02-03  Marc Glisse  <marc.glisse@inria.fr>
+
+       PR c++/53017
+       PR c++/59211
+       * doc/extend.texi (Function Attributes): Typo.
+
 2014-02-03  Cong Hou  <congh@google.com>
 
        PR tree-optimization/60000
index 381535aa65166300b8ed62f959e61fcd1e701228..58dc42ca223e22c4754223d2d69575c3f90141d0 100644 (file)
@@ -1,3 +1,12 @@
+2014-02-03  Marc Glisse  <marc.glisse@inria.fr>
+
+       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  <polacek@redhat.com>
 
        PR c/59963
index 5ce1a3ef75a6f19d3d810805d03316cc819f21b6..fc12788171cf3b79bf8a64321497971b735a67a7 100644 (file)
@@ -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);
index e73246a4a66ae0e1dd55ec8dbb2aec72a75801ec..5214d9a91ac479c9445ac85fe0f44e93a588c34e 100644 (file)
@@ -1,3 +1,10 @@
+2014-02-03  Marc Glisse  <marc.glisse@inria.fr>
+
+       PR c++/53017
+       PR c++/59211
+       * tree.c (handle_init_priority_attribute): Call default_conversion on
+       the attribute argument.
+
 2014-02-03  Paolo Carlini  <paolo.carlini@oracle.com>
 
        PR c++/58871
index fe2ddabae1deb3f5ef74203ba51146b9d1deb1f3..5567253a61a462416e8fcab3cbdcb1c6d3adef79 100644 (file)
@@ -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)
     {
index 48a8e990d1adc3ff5cf889d0485c3e669ed370ce..a42e90490c0b06bbf258d2b856c10f8edde4c971 100644 (file)
@@ -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
index 8c7af4969544b54f9d3b1abee20b2c8d85590ce6..b7c6252962a8723c181779ecca3a3c30e95078e4 100644 (file)
@@ -1,3 +1,10 @@
+2014-02-03  Marc Glisse  <marc.glisse@inria.fr>
+
+       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  <paolo.carlini@oracle.com>
 
        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 (file)
index 0000000..af4dd12
--- /dev/null
@@ -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 (file)
index 0000000..755188e
--- /dev/null
@@ -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)));