re PR c/50459 (alignof doesn't work on plain old constant, works with expressions...
authorMarek Polacek <polacek@redhat.com>
Fri, 9 May 2014 08:24:37 +0000 (08:24 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Fri, 9 May 2014 08:24:37 +0000 (08:24 +0000)
PR c/50459
c-family/
* c-common.c (check_user_alignment): Return -1 if alignment is error
node.
(handle_aligned_attribute): Don't call default_conversion on
FUNCTION_DECLs.
(handle_vector_size_attribute): Likewise.
(handle_tm_wrap_attribute): Handle case when wrap_decl is error node.
(handle_sentinel_attribute): Call default_conversion and allow even
integral types as an argument.
c/
* c-parser.c (c_parser_attributes): Parse the arguments as an
expression-list if the attribute takes identifier.
testsuite/
* c-c++-common/attributes-1.c: Move test line to a new test.
* c-c++-common/attributes-2.c: New test.
* c-c++-common/pr50459.c: New test.
* c-c++-common/pr59280.c: Add "undeclared" to dg-error.
* gcc.dg/nonnull-2.c: Likewise.
* gcc.dg/pr55570.c: Modify dg-error.
* gcc.dg/tm/wrap-2.c: Likewise.

From-SVN: r210262

12 files changed:
gcc/c-family/ChangeLog
gcc/c-family/c-common.c
gcc/c/ChangeLog
gcc/c/c-parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/attributes-1.c
gcc/testsuite/c-c++-common/attributes-2.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/pr50459.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/pr59280.c
gcc/testsuite/gcc.dg/nonnull-2.c
gcc/testsuite/gcc.dg/pr55570.c
gcc/testsuite/gcc.dg/tm/wrap-2.c

index fc84f31e4821155378194699d3f7e2dc21e025fd..3a978fa40b9d77d4419d4273a669578ade09a996 100644 (file)
@@ -1,3 +1,15 @@
+2014-05-09  Marek Polacek  <polacek@redhat.com>
+
+       PR c/50459
+       * c-common.c (check_user_alignment): Return -1 if alignment is error
+       node.
+       (handle_aligned_attribute): Don't call default_conversion on
+       FUNCTION_DECLs.
+       (handle_vector_size_attribute): Likewise.
+       (handle_tm_wrap_attribute): Handle case when wrap_decl is error node.
+       (handle_sentinel_attribute): Call default_conversion and allow even
+       integral types as an argument.
+
 2014-05-08  Marek Polacek  <polacek@redhat.com>
 
        PR c/61053
index d7c85fcaf7f33742e83715171e3e0ae573fe8ea1..a120b5cb008721e257fd69d523bee4e7bb1e762a 100644 (file)
@@ -7443,6 +7443,8 @@ check_user_alignment (const_tree align, bool allow_zero)
 {
   int i;
 
+  if (error_operand_p (align))
+    return -1;
   if (TREE_CODE (align) != INTEGER_CST
       || !INTEGRAL_TYPE_P (TREE_TYPE (align)))
     {
@@ -7564,7 +7566,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
@@ -8429,9 +8432,11 @@ handle_tm_wrap_attribute (tree *node, tree name, tree args,
   else
     {
       tree wrap_decl = TREE_VALUE (args);
-      if (TREE_CODE (wrap_decl) != IDENTIFIER_NODE
-         && TREE_CODE (wrap_decl) != VAR_DECL
-         && TREE_CODE (wrap_decl) != FUNCTION_DECL)
+      if (error_operand_p (wrap_decl))
+        ;
+      else if (TREE_CODE (wrap_decl) != IDENTIFIER_NODE
+              && TREE_CODE (wrap_decl) != VAR_DECL
+              && TREE_CODE (wrap_decl) != FUNCTION_DECL)
        error ("%qE argument not an identifier", name);
       else
        {
@@ -8558,7 +8563,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))
@@ -8970,8 +8976,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");
index 1c8c435f06186fd965fc01518bed669da6cdc423..4b7346114fab71fd5c18c603db80dd1a8a0bdf17 100644 (file)
@@ -1,3 +1,9 @@
+2014-05-09  Marek Polacek  <polacek@redhat.com>
+
+       PR c/50459
+       * c-parser.c (c_parser_attributes): Parse the arguments as an
+       expression-list if the attribute takes identifier.
+
 2014-05-08  Marek Polacek  <polacek@redhat.com>
 
        PR c/61053
index 6e8f33bdac1461ece539a68845f67e784e04ccc4..6e16d8b7f2fb256e5d16bfc5e4c192df278d0110 100644 (file)
@@ -3955,11 +3955,16 @@ c_parser_attributes (c_parser *parser)
             In objective-c the identifier may be a classname.  */
          if (c_parser_next_token_is (parser, CPP_NAME)
              && (c_parser_peek_token (parser)->id_kind == C_ID_ID
-                 || (c_dialect_objc () 
-                     && c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))
+                 || (c_dialect_objc ()
+                     && c_parser_peek_token (parser)->id_kind
+                        == C_ID_CLASSNAME))
              && ((c_parser_peek_2nd_token (parser)->type == CPP_COMMA)
                  || (c_parser_peek_2nd_token (parser)->type
-                     == CPP_CLOSE_PAREN)))
+                     == CPP_CLOSE_PAREN))
+             && (attribute_takes_identifier_p (attr_name)
+                 || (c_dialect_objc ()
+                     && c_parser_peek_token (parser)->id_kind
+                        == C_ID_CLASSNAME)))
            {
              tree arg1 = c_parser_peek_token (parser)->value;
              c_parser_consume_token (parser);
index 959763fef5aab703c522489a295f1a22b0d4698f..52639c054b63efe4625fa771d9fc199828cfe33d 100644 (file)
@@ -1,3 +1,14 @@
+2014-05-09  Marek Polacek  <polacek@redhat.com>
+
+       PR c/50459
+       * c-c++-common/attributes-1.c: Move test line to a new test.
+       * c-c++-common/attributes-2.c: New test.
+       * c-c++-common/pr50459.c: New test.
+       * c-c++-common/pr59280.c: Add "undeclared" to dg-error.
+       * gcc.dg/nonnull-2.c: Likewise.
+       * gcc.dg/pr55570.c: Modify dg-error.
+       * gcc.dg/tm/wrap-2.c: Likewise.
+
 2014-05-08  Jeff Law  <law@redhat.com>
 
        PR tree-optimization/61009
index af4dd12275c6441f4cc4e72765f02f0dfc8a9911..1657da10d5e40023250544aed9f5e1c03121292e 100644 (file)
@@ -9,8 +9,6 @@ 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" } */
diff --git a/gcc/testsuite/c-c++-common/attributes-2.c b/gcc/testsuite/c-c++-common/attributes-2.c
new file mode 100644 (file)
index 0000000..47b2c7b
--- /dev/null
@@ -0,0 +1,3 @@
+/* { dg-do compile } */
+
+void g() __attribute__((aligned(bar))); /* { dg-error "undeclared here|not declared" } */
diff --git a/gcc/testsuite/c-c++-common/pr50459.c b/gcc/testsuite/c-c++-common/pr50459.c
new file mode 100644 (file)
index 0000000..f837b63
--- /dev/null
@@ -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;
index 779f0fb858fcf5f9a6f6dcdabef250a338f2a20c..581a1cf7b594147ad112df739547ed42c0cdcd90 100644 (file)
@@ -1,4 +1,4 @@
 /* PR c/59280 */
 /* { dg-do compile } */
 
-void bar (char *) __attribute__((constructor(foo))); /* { dg-error "constructor priorities must be integers|was not declared|constructor priorities are not supported" } */
+void bar (char *) __attribute__((constructor(foo))); /* { dg-error "constructor priorities must be integers|was not declared|undeclared|constructor priorities are not supported" } */
index bd36d232d38995d9176ebf4fb9936b13233a4836..d570a467e6a0ae6b2a533038bc0d2a61737c1356 100644 (file)
@@ -6,7 +6,7 @@ extern void func1 () __attribute__((nonnull)); /* { dg-error "without arguments"
 
 extern void func2 (char *) __attribute__((nonnull(2))); /* { dg-error "out-of-range operand" } */
 
-extern void func3 (char *) __attribute__((nonnull(foo))); /* { dg-error "invalid operand number" } */
+extern void func3 (char *) __attribute__((nonnull(foo))); /* { dg-error "invalid operand number|undeclared" } */
 
 extern void func4 (int) __attribute__((nonnull(1))); /* { dg-error "references non-pointer" } */
 
index 903bb033df952f603322c18284d066b012e06e38..5f5555ee47b29ae28a3a115b6be790fbe33aca5e 100644 (file)
@@ -1,4 +1,4 @@
 /* PR c/55570 */
 /* { dg-do compile } */
 
-char array[16] __attribute__((aligned (SOME_NOT_DEFINED_MACRO))); /* { dg-error "requested alignment is not an integer constant" } */
+char array[16] __attribute__((aligned (SOME_NOT_DEFINED_MACRO))); /* { dg-error "undeclared here" } */
index 29486335a44f6a7d7ec95ff3db390146010f2dbc..372d666be7f4665846a0e79cee63f2b7e2979770 100644 (file)
@@ -10,7 +10,7 @@ int f7(void);
 void g1(void) W(f1);
 void g2(void) W(f2);   /* { dg-error "is not compatible" } */
 void g3(void) W(i3);   /* { dg-error "is not a function" } */
-void g4(void) W(f4);   /* { dg-error "is not a function" } */
+void g4(void) W(f4);   /* { dg-error "undeclared" } */
 void g5(void) W(1);    /* { dg-error "not an identifier" } */
 void g6(void) W("f1"); /* { dg-error "not an identifier" } */
 void g7(void) W(f7);   /* { dg-error "is not compatible" } */