From patchwork Wed Apr 23 09:54:52 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 341751 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 9542B1400F4 for ; Wed, 23 Apr 2014 19:55:21 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; q=dns; s=default; b=wnFMdlv8Q8bvNl6Rc XcHT7kEMNNWME5gFFaMnrEvtLsac83S546UpQtAbwRVy5CTmM1xo4WxiXs9m+lR1 YBn5KQ2aZgitjZSvA8lHwdUDHrkv0SOx2dqAx56u1ndvHAtUKpMAtLKH+f0JYAOh ilFkmdKoWyYq9WGCJZfSEZ7I8Q= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=default; bh=cjqpY3BodI0ggRTMEdlot3F hlgg=; b=fLVDEBFU4xq4+f7QCWhsgJyW5y45kjXtywPUQT9bZHUcyrGnv8vRDPk lOh4HCzXD5ps0XoWmx8Vd4CIDyGrzkktS4Iv8odEuCDPmXwbRbUNTVSgGIElV4Is heNDVXN6uyckf1XcgbulZpu+ig2tXtIACx3+D0EPELv3/xBQ6AV4= Received: (qmail 527 invoked by alias); 23 Apr 2014 09:55:08 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 493 invoked by uid 89); 23 Apr 2014 09:55:08 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.1 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 23 Apr 2014 09:55:05 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s3N9t1Zx014141 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 23 Apr 2014 05:55:01 -0400 Received: from redhat.com (ovpn-116-53.ams2.redhat.com [10.36.116.53]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id s3N9srNV023100 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NO); Wed, 23 Apr 2014 05:54:57 -0400 Date: Wed, 23 Apr 2014 11:54:52 +0200 From: Marek Polacek To: Jason Merrill Cc: GCC Patches , "Joseph S. Myers" , Marc Glisse Subject: Re: [C PATCH] Make attributes accept enum values (PR c/50459) Message-ID: <20140423095452.GA2103@redhat.com> References: <20140414151045.GA20332@redhat.com> <534D3B2E.3000601@redhat.com> <20140415195615.GC20332@redhat.com> <534EC086.2000902@redhat.com> <20140417160050.GG20332@redhat.com> <53528072.6020006@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <53528072.6020006@redhat.com> User-Agent: Mutt/1.5.21 (2010-09-15) On Sat, Apr 19, 2014 at 09:56:02AM -0400, Jason Merrill wrote: > On 04/17/2014 12:00 PM, Marek Polacek wrote: > > == 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); > > Instead, we should add !attr_takes_id_p to the if condition > immediately above so that we parse the arguments as an > expression-list. Ah, indeed. So like this? I had to add some ugliness because of Obj-C and also tweak a few tests, since we now print slightly different error message if the identifier in attribute argument isn't declared. Regtested/bootstrapped on x86_64-linux. 2014-04-22 Marek Polacek 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: Remove dg-error line. * 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. Marek diff --git gcc/c-family/c-common.c gcc/c-family/c-common.c index c0e247b..df44faa 100644 --- gcc/c-family/c-common.c +++ gcc/c-family/c-common.c @@ -7418,6 +7418,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))) { @@ -7539,7 +7541,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 @@ -8404,9 +8407,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 { @@ -8533,7 +8538,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 +8950,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"); diff --git gcc/c/c-parser.c gcc/c/c-parser.c index 5653e49..8d91d6b 100644 --- gcc/c/c-parser.c +++ gcc/c/c-parser.c @@ -3943,11 +3943,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); diff --git gcc/testsuite/c-c++-common/attributes-1.c gcc/testsuite/c-c++-common/attributes-1.c index af4dd12..8458e47 100644 --- gcc/testsuite/c-c++-common/attributes-1.c +++ gcc/testsuite/c-c++-common/attributes-1.c @@ -9,7 +9,7 @@ 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 g() __attribute__((aligned(bar))); void foo(void); void* my_calloc(unsigned, unsigned) __attribute__((alloc_size(1,foo))); /* { dg-warning "outside range" } */ diff --git gcc/testsuite/c-c++-common/pr50459.c gcc/testsuite/c-c++-common/pr50459.c index e69de29..f837b63 100644 --- gcc/testsuite/c-c++-common/pr50459.c +++ gcc/testsuite/c-c++-common/pr50459.c @@ -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; diff --git gcc/testsuite/c-c++-common/pr59280.c gcc/testsuite/c-c++-common/pr59280.c index 779f0fb..581a1cf 100644 --- gcc/testsuite/c-c++-common/pr59280.c +++ gcc/testsuite/c-c++-common/pr59280.c @@ -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" } */ diff --git gcc/testsuite/gcc.dg/nonnull-2.c gcc/testsuite/gcc.dg/nonnull-2.c index bd36d232..d570a46 100644 --- gcc/testsuite/gcc.dg/nonnull-2.c +++ gcc/testsuite/gcc.dg/nonnull-2.c @@ -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" } */ diff --git gcc/testsuite/gcc.dg/pr55570.c gcc/testsuite/gcc.dg/pr55570.c index 903bb03..5f5555e 100644 --- gcc/testsuite/gcc.dg/pr55570.c +++ gcc/testsuite/gcc.dg/pr55570.c @@ -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" } */ diff --git gcc/testsuite/gcc.dg/tm/wrap-2.c gcc/testsuite/gcc.dg/tm/wrap-2.c index 2948633..372d666 100644 --- gcc/testsuite/gcc.dg/tm/wrap-2.c +++ gcc/testsuite/gcc.dg/tm/wrap-2.c @@ -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" } */