From patchwork Thu Dec 27 14:59:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Segher Boessenkool X-Patchwork-Id: 1018915 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-493128-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=kernel.crashing.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="w3lPlD47"; dkim-atps=neutral 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 43QY0F58v8z9s7h for ; Fri, 28 Dec 2018 01:59:41 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; q=dns; s=default; b=GBcrxY2ofvL1QprycGz NKW31TY56u/uMmPA945AgyKnGSTOfswIjKNjixItzYKbdnT2j83RJpu77uiKLjc7 /w4ofCBeisGpiJXW9jagqO5txXA4A84d8oDxeVXzAbnFXx7E+7Of2vYY4pxJ4nh3 5sc6Jwq6cdH5TwMl1oYml1cI= 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:from :to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; s=default; bh=Pcx8xrFyVwtTERQmhzCn96hZj rg=; b=w3lPlD47/EppqOltko0Mgf28r+h565cK+WHKnnaW7nFG9zbVGbjweV+Wm WHSqtD2kABtbiK1iDb/THXqU7925bCqTnwwtinSgM5KFhx36INIKF0LIkB9FVKtA s/+Lr6lTYWXauCEcb8ThfHJRrVSoKJfcIyzzddM2lIyQ1ecC1o= Received: (qmail 125447 invoked by alias); 27 Dec 2018 14:59:30 -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 125327 invoked by uid 89); 27 Dec 2018 14:59:29 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY autolearn=ham version=3.3.2 spammy=origin, D*r, lab, Follow X-HELO: gcc1-power7.osuosl.org Received: from gcc1-power7.osuosl.org (HELO gcc1-power7.osuosl.org) (140.211.15.137) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 27 Dec 2018 14:59:24 +0000 Received: by gcc1-power7.osuosl.org (Postfix, from userid 10019) id 4BC2D12403FF; Thu, 27 Dec 2018 14:59:23 +0000 (UTC) From: Segher Boessenkool To: gcc-patches@gcc.gnu.org Cc: Segher Boessenkool Subject: [PATCH 1/8] asm qualifiers (PR55681) Date: Thu, 27 Dec 2018 14:59:06 +0000 Message-Id: <2ea395426865aeb7b02f16facf70908a852e7fbc.1545922222.git.segher@kernel.crashing.org> In-Reply-To: References: In-Reply-To: References: X-IsSubscribed: yes PR55681 observes that currently only one qualifier is allowed for inline asm, so that e.g. "volatile asm" is allowed, "const asm" is also okay (with a warning), but "const volatile asm" gives an error. Also "goto" has to be last. This patch changes things so that only "asm-qualifiers" are allowed, that is "volatile" and "goto", in any combination, in any order, but without repetitions. 2018-12-06 Segher Boessenkool PR inline-asm/55681 * doc/extend.texi (Basic Asm): Update grammar. (Extended Asm): Update grammar. gcc/c/ PR inline-asm/55681 * c-parser.c (c_parser_asm_statement): Update grammar. Allow any combination of volatile and goto, in any order, without repetitions. gcc/cp/ PR inline-asm/55681 * parser.c (cp_parser_asm_definition): Update grammar. Allow any combination of volatile and goto, in any order, without repetitions. gcc/testsuite/ PR inline-asm/55681 * gcc.dg/asm-qual-1.c: Test that "const" and "restrict" are refused. * gcc.dg/asm-qual-2.c: New test, test that asm-qualifiers are allowed in any order, but that duplicates are not allowed. --- gcc/c/c-parser.c | 74 +++++++++++++++++++++---------------- gcc/cp/parser.c | 77 ++++++++++++++++++++++++++------------- gcc/doc/extend.texi | 8 ++-- gcc/testsuite/gcc.dg/asm-qual-1.c | 10 +++-- gcc/testsuite/gcc.dg/asm-qual-2.c | 21 +++++++++++ 5 files changed, 127 insertions(+), 63 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/asm-qual-2.c diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c index 4772086..7ec53b3 100644 --- a/gcc/c/c-parser.c +++ b/gcc/c/c-parser.c @@ -6261,60 +6261,72 @@ c_parser_for_statement (c_parser *parser, bool ivdep, unsigned short unroll, } /* Parse an asm statement, a GNU extension. This is a full-blown asm - statement with inputs, outputs, clobbers, and volatile tag + statement with inputs, outputs, clobbers, and volatile and goto tag allowed. + asm-qualifier: + volatile + goto + + asm-qualifier-list: + asm-qualifier-list asm-qualifier + asm-qualifier + asm-statement: - asm type-qualifier[opt] ( asm-argument ) ; - asm type-qualifier[opt] goto ( asm-goto-argument ) ; + asm asm-qualifier-list[opt] ( asm-argument ) ; asm-argument: asm-string-literal asm-string-literal : asm-operands[opt] asm-string-literal : asm-operands[opt] : asm-operands[opt] - asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt] - - asm-goto-argument: + asm-string-literal : asm-operands[opt] : asm-operands[opt] \ + : asm-clobbers[opt] asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \ : asm-goto-operands - Qualifiers other than volatile are accepted in the syntax but - warned for. */ + The form with asm-goto-operands is valid if and only if the + asm-qualifier-list contains goto, and is the only allowed form in that case. + Duplicate asm-qualifiers are not allowed. */ static tree c_parser_asm_statement (c_parser *parser) { tree quals, str, outputs, inputs, clobbers, labels, ret; - bool simple, is_goto; + bool simple, is_volatile, is_goto; location_t asm_loc = c_parser_peek_token (parser)->location; int section, nsections; gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM)); c_parser_consume_token (parser); - if (c_parser_next_token_is_keyword (parser, RID_VOLATILE)) - { - quals = c_parser_peek_token (parser)->value; - c_parser_consume_token (parser); - } - else if (c_parser_next_token_is_keyword (parser, RID_CONST) - || c_parser_next_token_is_keyword (parser, RID_RESTRICT)) - { - warning_at (c_parser_peek_token (parser)->location, - 0, - "%E qualifier ignored on asm", - c_parser_peek_token (parser)->value); - quals = NULL_TREE; - c_parser_consume_token (parser); - } - else - quals = NULL_TREE; + quals = NULL_TREE; + is_volatile = false; is_goto = false; - if (c_parser_next_token_is_keyword (parser, RID_GOTO)) - { - c_parser_consume_token (parser); - is_goto = true; - } + for (bool done = false; !done; ) + switch (c_parser_peek_token (parser)->keyword) + { + case RID_VOLATILE: + if (!is_volatile) + { + is_volatile = true; + quals = c_parser_peek_token (parser)->value; + c_parser_consume_token (parser); + } + else + done = true; + break; + case RID_GOTO: + if (!is_goto) + { + is_goto = true; + c_parser_consume_token (parser); + } + else + done = true; + break; + default: + done = true; + } /* ??? Follow the C++ parser rather than using the lex_untranslated_string kludge. */ diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 9907180..3bc5795 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -19067,22 +19067,34 @@ cp_parser_using_directive (cp_parser* parser) /* Parse an asm-definition. + asm-qualifier: + volatile + goto + + asm-qualifier-list: + asm-qualifier + asm-qualifier-list asm-qualifier + asm-definition: asm ( string-literal ) ; GNU Extension: asm-definition: - asm volatile [opt] ( string-literal ) ; - asm volatile [opt] ( string-literal : asm-operand-list [opt] ) ; - asm volatile [opt] ( string-literal : asm-operand-list [opt] - : asm-operand-list [opt] ) ; - asm volatile [opt] ( string-literal : asm-operand-list [opt] - : asm-operand-list [opt] + asm asm-qualifier-list [opt] ( string-literal ) ; + asm asm-qualifier-list [opt] ( string-literal : asm-operand-list [opt] ) ; + asm asm-qualifier-list [opt] ( string-literal : asm-operand-list [opt] + : asm-operand-list [opt] ) ; + asm asm-qualifier-list [opt] ( string-literal : asm-operand-list [opt] + : asm-operand-list [opt] : asm-clobber-list [opt] ) ; - asm volatile [opt] goto ( string-literal : : asm-operand-list [opt] - : asm-clobber-list [opt] - : asm-goto-list ) ; */ + asm asm-qualifier-list [opt] ( string-literal : : asm-operand-list [opt] + : asm-clobber-list [opt] + : asm-goto-list ) ; + + The form with asm-goto-list is valid if and only if the asm-qualifier-list + contains goto, and is the only allowed form in that case. No duplicates are + allowed in an asm-qualifier-list. */ static void cp_parser_asm_definition (cp_parser* parser) @@ -19111,23 +19123,36 @@ cp_parser_asm_definition (cp_parser* parser) } /* See if the next token is `volatile'. */ - if (cp_parser_allow_gnu_extensions_p (parser) - && cp_lexer_next_token_is_keyword (parser->lexer, RID_VOLATILE)) - { - /* Remember that we saw the `volatile' keyword. */ - volatile_p = true; - /* Consume the token. */ - cp_lexer_consume_token (parser->lexer); - } - if (cp_parser_allow_gnu_extensions_p (parser) - && parser->in_function_body - && cp_lexer_next_token_is_keyword (parser->lexer, RID_GOTO)) - { - /* Remember that we saw the `goto' keyword. */ - goto_p = true; - /* Consume the token. */ - cp_lexer_consume_token (parser->lexer); - } + if (cp_parser_allow_gnu_extensions_p (parser)) + for (bool done = false; !done ; ) + switch (cp_lexer_peek_token (parser->lexer)->keyword) + { + case RID_VOLATILE: + if (!volatile_p) + { + /* Remember that we saw the `volatile' keyword. */ + volatile_p = true; + /* Consume the token. */ + cp_lexer_consume_token (parser->lexer); + } + else + done = true; + break; + case RID_GOTO: + if (!goto_p && parser->in_function_body) + { + /* Remember that we saw the `goto' keyword. */ + goto_p = true; + /* Consume the token. */ + cp_lexer_consume_token (parser->lexer); + } + else + done = true; + break; + default: + done = true; + } + /* Look for the opening `('. */ if (!cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN)) return; diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index afde889..40b1989 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -8147,7 +8147,7 @@ for a C symbol, or to place a C variable in a specific register. A basic @code{asm} statement has the following syntax: @example -asm @r{[} volatile @r{]} ( @var{AssemblerInstructions} ) +asm @var{asm-qualifiers} ( @var{AssemblerInstructions} ) @end example The @code{asm} keyword is a GNU extension. @@ -8275,17 +8275,19 @@ Extended @code{asm} syntax uses colons (@samp{:}) to delimit the operand parameters after the assembler template: @example -asm @r{[}volatile@r{]} ( @var{AssemblerTemplate} +asm @var{asm-qualifiers} ( @var{AssemblerTemplate} : @var{OutputOperands} @r{[} : @var{InputOperands} @r{[} : @var{Clobbers} @r{]} @r{]}) -asm @r{[}volatile@r{]} goto ( @var{AssemblerTemplate} +asm @var{asm-qualifiers} ( @var{AssemblerTemplate} : : @var{InputOperands} : @var{Clobbers} : @var{GotoLabels}) @end example +where in the last form, @var{asm-qualifiers} contains @code{goto} (and in the +first form, not). The @code{asm} keyword is a GNU extension. When writing code that can be compiled with @option{-ansi} and the diff --git a/gcc/testsuite/gcc.dg/asm-qual-1.c b/gcc/testsuite/gcc.dg/asm-qual-1.c index 5ec9a29..cb37283 100644 --- a/gcc/testsuite/gcc.dg/asm-qual-1.c +++ b/gcc/testsuite/gcc.dg/asm-qual-1.c @@ -1,4 +1,4 @@ -/* Test that qualifiers other than volatile are ignored on asm. */ +/* Test that qualifiers other than volatile are disallowed on asm. */ /* Origin: Joseph Myers */ /* { dg-do compile } */ /* { dg-options "-std=gnu99" } */ @@ -7,6 +7,10 @@ void f (void) { asm volatile (""); - asm const (""); /* { dg-warning "const qualifier ignored on asm" } */ - asm restrict (""); /* { dg-warning "restrict qualifier ignored on asm" } */ + + asm const (""); /* { dg-error {expected '\(' before 'const'} } */ + /* { dg-error {expected identifier} {} {target *-*-*} .-1 } */ + + asm restrict (""); /* { dg-error {expected '\(' before 'restrict'} } */ + /* { dg-error {expected identifier} {} {target *-*-*} .-1 } */ } diff --git a/gcc/testsuite/gcc.dg/asm-qual-2.c b/gcc/testsuite/gcc.dg/asm-qual-2.c new file mode 100644 index 0000000..37df2ad --- /dev/null +++ b/gcc/testsuite/gcc.dg/asm-qual-2.c @@ -0,0 +1,21 @@ +/* Test that qualifiers on asm are allowed in any order. */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu99" } */ + +void +f (void) +{ + asm volatile goto ("" :::: lab); + asm goto volatile ("" :::: lab); + + /* Duplicates are not allowed. */ + asm goto volatile volatile ("" :::: lab); /* { dg-error "" } */ + asm volatile goto volatile ("" :::: lab); /* { dg-error "" } */ + asm volatile volatile goto ("" :::: lab); /* { dg-error "" } */ + asm goto goto volatile ("" :::: lab); /* { dg-error "" } */ + asm goto volatile goto ("" :::: lab); /* { dg-error "" } */ + asm volatile goto goto ("" :::: lab); /* { dg-error "" } */ + +lab: + ; +} From patchwork Thu Dec 27 14:59:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Segher Boessenkool X-Patchwork-Id: 1018917 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-493130-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=kernel.crashing.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="K3LUTJ5C"; dkim-atps=neutral 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 43QY0q0W5jz9s7h for ; Fri, 28 Dec 2018 02:00:10 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; q=dns; s=default; b=qcBBbGkbGzamTj57nkP fUVsnose0EccPxz8hfgFluoWf3x1zxTRmRs3tXBusNX2Pq8JLKj9UI3bLh/ws7oW M2CYfCgX8/9zQpfhxp+drvoCmaFHdeMo1i6vlkQE/yPOc9LngTb+NNQDAtD22re3 qOJ/2/nBxHMc94kVW0Etwoiw= 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:from :to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; s=default; bh=CfIpaYxQ8N7xpxipv6xBpY7oK bs=; b=K3LUTJ5Ccor2HqLD9YrvIrC2/ufRXjI2YjwSQxtZFQ8nld1SdXsvDOTwY edtBAOhnbH1mye225WhtJmbUVHnINKxi3ZvsaMsQIDAWtLrEBrXyopXEKmTa1Vha AZwqC0FSKc0WR1VXb26YrhN1aMeiie5k9dixqhxBlqvCGXHFHk= Received: (qmail 126438 invoked by alias); 27 Dec 2018 14:59:38 -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 126349 invoked by uid 89); 27 Dec 2018 14:59:37 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY autolearn=ham version=3.3.2 spammy=tiny, jump, Document, decisions X-HELO: gcc1-power7.osuosl.org Received: from gcc1-power7.osuosl.org (HELO gcc1-power7.osuosl.org) (140.211.15.137) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 27 Dec 2018 14:59:29 +0000 Received: by gcc1-power7.osuosl.org (Postfix, from userid 10019) id 5D2A7124067A; Thu, 27 Dec 2018 14:59:28 +0000 (UTC) From: Segher Boessenkool To: gcc-patches@gcc.gnu.org Cc: Segher Boessenkool Subject: [PATCH 2/8] asm inline Date: Thu, 27 Dec 2018 14:59:07 +0000 Message-Id: <420ded3dc643d9e1ee6239ca5a8d1942c69bfe76.1545922222.git.segher@kernel.crashing.org> In-Reply-To: References: In-Reply-To: References: X-IsSubscribed: yes The Linux kernel people want a feature that makes GCC pretend some inline assembler code is tiny (while it would think it is huge), so that such code will be inlined essentially always instead of essentially never. This patch lets you say "asm inline" instead of just "asm", with the result that that inline assembler is always counted as minimum cost for inlining. It implements this for C and C++, making "inline" another asm-qualifier (supplementing "volatile" and "goto"). 2018-12-06 Segher Boessenkool * doc/extend.texi (Using Assembly Language with C): Document asm inline. (Size of an asm): Fix typo. Document asm inline. * gimple-pretty-print.c (dump_gimple_asm): Handle asm inline. * gimple.h (enum gf_mask): Add GF_ASM_INLINE. (gimple_asm_set_volatile): Fix typo. (gimple_asm_inline_p): New. (gimple_asm_set_inline): New. * gimplify.c (gimplify_asm_expr): Propagate the asm inline flag from tree to gimple. * ipa-icf-gimple.c (func_checker::compare_gimple_asm): Compare the gimple_asm_inline_p flag, too. * tree-core.h (tree_base): Document that protected_flag is ASM_INLINE_P in an ASM_EXPR. * tree-inline.c (estimate_num_insns): If gimple_asm_inline_p return a minimum size for an asm. * tree.h (ASM_INLINE_P): New. gcc/c/ * c-parser.c (c_parser_asm_statement): Detect the inline keyword after asm. Pass a flag for it to build_asm_expr. * c-tree.h (build_asm_expr): Update declaration. * c-typeck.c (build_asm_stmt): Add is_inline parameter. Use it to set ASM_INLINE_P. gcc/cp/ * cp-tree.h (finish_asm_stmt): Update declaration. * parser.c (cp_parser_asm_definition): Detect the inline keyword after asm. Pass a flag for it to finish_asm_stmt. * pt.c (tsubst_expr): Pass the ASM_INLINE_P flag to finish_asm_stmt. * semantics.c (finish_asm_stmt): Add inline_p parameter. Use it to set ASM_INLINE_P. gcc/testsuite/ * c-c++-common/torture/asm-inline.c: New testcase. * gcc.dg/asm-qual-2.c: Test asm inline, too. --- gcc/c/c-parser.c | 21 ++++++++-- gcc/c/c-tree.h | 3 +- gcc/c/c-typeck.c | 7 +++- gcc/cp/cp-tree.h | 2 +- gcc/cp/parser.c | 15 ++++++- gcc/cp/pt.c | 2 +- gcc/cp/semantics.c | 5 ++- gcc/doc/extend.texi | 15 ++++++- gcc/gimple-pretty-print.c | 2 + gcc/gimple.h | 26 +++++++++++- gcc/gimplify.c | 1 + gcc/ipa-icf-gimple.c | 3 ++ gcc/testsuite/c-c++-common/torture/asm-inline.c | 53 +++++++++++++++++++++++++ gcc/testsuite/gcc.dg/asm-qual-2.c | 25 ++++++++++++ gcc/tree-core.h | 3 ++ gcc/tree-inline.c | 3 ++ gcc/tree.h | 3 ++ 17 files changed, 174 insertions(+), 15 deletions(-) create mode 100644 gcc/testsuite/c-c++-common/torture/asm-inline.c diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c index 7ec53b3..51cc2be 100644 --- a/gcc/c/c-parser.c +++ b/gcc/c/c-parser.c @@ -6261,11 +6261,12 @@ c_parser_for_statement (c_parser *parser, bool ivdep, unsigned short unroll, } /* Parse an asm statement, a GNU extension. This is a full-blown asm - statement with inputs, outputs, clobbers, and volatile and goto tag - allowed. + statement with inputs, outputs, clobbers, and volatile, inline, and goto + tags allowed. asm-qualifier: volatile + inline goto asm-qualifier-list: @@ -6292,7 +6293,7 @@ static tree c_parser_asm_statement (c_parser *parser) { tree quals, str, outputs, inputs, clobbers, labels, ret; - bool simple, is_volatile, is_goto; + bool simple, is_volatile, is_inline, is_goto; location_t asm_loc = c_parser_peek_token (parser)->location; int section, nsections; @@ -6301,6 +6302,7 @@ c_parser_asm_statement (c_parser *parser) quals = NULL_TREE; is_volatile = false; + is_inline = false; is_goto = false; for (bool done = false; !done; ) switch (c_parser_peek_token (parser)->keyword) @@ -6315,6 +6317,16 @@ c_parser_asm_statement (c_parser *parser) else done = true; break; + case RID_INLINE: + if (!is_inline) + { + is_inline = true; + quals = c_parser_peek_token (parser)->value; + c_parser_consume_token (parser); + } + else + done = true; + break; case RID_GOTO: if (!is_goto) { @@ -6403,7 +6415,8 @@ c_parser_asm_statement (c_parser *parser) c_parser_skip_to_end_of_block_or_statement (parser); ret = build_asm_stmt (quals, build_asm_expr (asm_loc, str, outputs, inputs, - clobbers, labels, simple)); + clobbers, labels, simple, + is_inline)); error: parser->lex_untranslated_string = false; diff --git a/gcc/c/c-tree.h b/gcc/c/c-tree.h index ae1a1e6..7f34bdc 100644 --- a/gcc/c/c-tree.h +++ b/gcc/c/c-tree.h @@ -677,7 +677,8 @@ extern tree build_compound_literal (location_t, tree, tree, bool, extern void check_compound_literal_type (location_t, struct c_type_name *); extern tree c_start_case (location_t, location_t, tree, bool); extern void c_finish_case (tree, tree); -extern tree build_asm_expr (location_t, tree, tree, tree, tree, tree, bool); +extern tree build_asm_expr (location_t, tree, tree, tree, tree, tree, bool, + bool); extern tree build_asm_stmt (tree, tree); extern int c_types_compatible_p (tree, tree); extern tree c_begin_compound_stmt (bool); diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c index 8205916..3ebb28e 100644 --- a/gcc/c/c-typeck.c +++ b/gcc/c/c-typeck.c @@ -9990,10 +9990,12 @@ build_asm_stmt (tree cv_qualifier, tree args) some INPUTS, and some CLOBBERS. The latter three may be NULL. SIMPLE indicates whether there was anything at all after the string in the asm expression -- asm("blah") and asm("blah" : ) - are subtly different. We use a ASM_EXPR node to represent this. */ + are subtly different. We use a ASM_EXPR node to represent this. + LOC is the location of the asm, and IS_INLINE says whether this + is asm inline. */ tree build_asm_expr (location_t loc, tree string, tree outputs, tree inputs, - tree clobbers, tree labels, bool simple) + tree clobbers, tree labels, bool simple, bool is_inline) { tree tail; tree args; @@ -10111,6 +10113,7 @@ build_asm_expr (location_t loc, tree string, tree outputs, tree inputs, as volatile. */ ASM_INPUT_P (args) = simple; ASM_VOLATILE_P (args) = (noutputs == 0); + ASM_INLINE_P (args) = is_inline; return args; } diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 85ba5b8..0f24b4f 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -6897,7 +6897,7 @@ extern tree begin_compound_stmt (unsigned int); extern void finish_compound_stmt (tree); extern tree finish_asm_stmt (int, tree, tree, tree, tree, - tree); + tree, bool); extern tree finish_label_stmt (tree); extern void finish_label_decl (tree); extern cp_expr finish_parenthesized_expr (cp_expr); diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 3bc5795..3fd9a02 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -19069,6 +19069,7 @@ cp_parser_using_directive (cp_parser* parser) asm-qualifier: volatile + inline goto asm-qualifier-list: @@ -19109,6 +19110,7 @@ cp_parser_asm_definition (cp_parser* parser) bool extended_p = false; bool invalid_inputs_p = false; bool invalid_outputs_p = false; + bool inline_p = false; bool goto_p = false; required_token missing = RT_NONE; @@ -19138,6 +19140,17 @@ cp_parser_asm_definition (cp_parser* parser) else done = true; break; + case RID_INLINE: + if (!inline_p && parser->in_function_body) + { + /* Remember that we saw the `inline' keyword. */ + inline_p = true; + /* Consume the token. */ + cp_lexer_consume_token (parser->lexer); + } + else + done = true; + break; case RID_GOTO: if (!goto_p && parser->in_function_body) { @@ -19279,7 +19292,7 @@ cp_parser_asm_definition (cp_parser* parser) if (parser->in_function_body) { asm_stmt = finish_asm_stmt (volatile_p, string, outputs, - inputs, clobbers, labels); + inputs, clobbers, labels, inline_p); /* If the extended syntax was not used, mark the ASM_EXPR. */ if (!extended_p) { diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index e9a9ac9..446f4fb 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -16990,7 +16990,7 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl, tree labels = tsubst_copy_asm_operands (ASM_LABELS (t), args, complain, in_decl); tmp = finish_asm_stmt (ASM_VOLATILE_P (t), string, outputs, inputs, - clobbers, labels); + clobbers, labels, ASM_INLINE_P (t)); tree asm_expr = tmp; if (TREE_CODE (asm_expr) == CLEANUP_POINT_EXPR) asm_expr = TREE_OPERAND (asm_expr, 0); diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 1744ec0..1f6c9be 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -1461,11 +1461,11 @@ finish_compound_stmt (tree stmt) /* Finish an asm-statement, whose components are a STRING, some OUTPUT_OPERANDS, some INPUT_OPERANDS, some CLOBBERS and some LABELS. Also note whether the asm-statement should be - considered volatile. */ + considered volatile, and whether it is asm inline. */ tree finish_asm_stmt (int volatile_p, tree string, tree output_operands, - tree input_operands, tree clobbers, tree labels) + tree input_operands, tree clobbers, tree labels, bool inline_p) { tree r; tree t; @@ -1619,6 +1619,7 @@ finish_asm_stmt (int volatile_p, tree string, tree output_operands, output_operands, input_operands, clobbers, labels); ASM_VOLATILE_P (r) = volatile_p || noutputs == 0; + ASM_INLINE_P (r) = inline_p; r = maybe_cleanup_point_expr_void (r); return add_stmt (r); } diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index 40b1989..4ff37c4 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -8160,6 +8160,10 @@ various @option{-std} options, use @code{__asm__} instead of @item volatile The optional @code{volatile} qualifier has no effect. All basic @code{asm} blocks are implicitly volatile. + +@item inline +If you use the @code{inline} qualifier, then for inlining purposes the size +of the asm is taken as the smallest size possible (@pxref{Size of an asm}). @end table @subsubheading Parameters @@ -8303,6 +8307,10 @@ values to produce output values. However, your @code{asm} statements may also produce side effects. If so, you may need to use the @code{volatile} qualifier to disable certain optimizations. @xref{Volatile}. +@item inline +If you use the @code{inline} qualifier, then for inlining purposes the size +of the asm is taken as the smallest size possible (@pxref{Size of an asm}). + @item goto This qualifier informs the compiler that the @code{asm} statement may perform a jump to one of the labels listed in the @var{GotoLabels}. @@ -9714,7 +9722,7 @@ does this by counting the number of instructions in the pattern of the @code{asm} and multiplying that by the length of the longest instruction supported by that processor. (When working out the number of instructions, it assumes that any occurrence of a newline or of -whatever statement separator character is supported by the assembler -- +whatever statement separator character is supported by the assembler --- typically @samp{;} --- indicates the end of an instruction.) Normally, GCC's estimate is adequate to ensure that correct @@ -9725,6 +9733,11 @@ space in the object file than is needed for a single instruction. If this happens then the assembler may produce a diagnostic saying that a label is unreachable. +@cindex @code{asm inline} +This size is also used for inlining decisions. If you use @code{asm inline} +instead of just @code{asm}, then for inlining purposes the size of the asm +is taken as the minimum size, ignoring how many instructions GCC thinks it is. + @node Alternate Keywords @section Alternate Keywords @cindex alternate keywords diff --git a/gcc/gimple-pretty-print.c b/gcc/gimple-pretty-print.c index 6695526..487770f 100644 --- a/gcc/gimple-pretty-print.c +++ b/gcc/gimple-pretty-print.c @@ -2040,6 +2040,8 @@ dump_gimple_asm (pretty_printer *buffer, gasm *gs, int spc, dump_flags_t flags) pp_string (buffer, "__asm__"); if (gimple_asm_volatile_p (gs)) pp_string (buffer, " __volatile__"); + if (gimple_asm_inline_p (gs)) + pp_string (buffer, " __inline__"); if (gimple_asm_nlabels (gs)) pp_string (buffer, " goto"); pp_string (buffer, "(\""); diff --git a/gcc/gimple.h b/gcc/gimple.h index 265e3e2..224463b 100644 --- a/gcc/gimple.h +++ b/gcc/gimple.h @@ -137,6 +137,7 @@ enum gimple_rhs_class enum gf_mask { GF_ASM_INPUT = 1 << 0, GF_ASM_VOLATILE = 1 << 1, + GF_ASM_INLINE = 1 << 2, GF_CALL_FROM_THUNK = 1 << 0, GF_CALL_RETURN_SLOT_OPT = 1 << 1, GF_CALL_TAILCALL = 1 << 2, @@ -3925,7 +3926,7 @@ gimple_asm_string (const gasm *asm_stmt) } -/* Return true ASM_STMT ASM_STMT is an asm statement marked volatile. */ +/* Return true if ASM_STMT is marked volatile. */ static inline bool gimple_asm_volatile_p (const gasm *asm_stmt) @@ -3934,7 +3935,7 @@ gimple_asm_volatile_p (const gasm *asm_stmt) } -/* If VOLATLE_P is true, mark asm statement ASM_STMT as volatile. */ +/* If VOLATILE_P is true, mark asm statement ASM_STMT as volatile. */ static inline void gimple_asm_set_volatile (gasm *asm_stmt, bool volatile_p) @@ -3946,6 +3947,27 @@ gimple_asm_set_volatile (gasm *asm_stmt, bool volatile_p) } +/* Return true if ASM_STMT is marked inline. */ + +static inline bool +gimple_asm_inline_p (const gasm *asm_stmt) +{ + return (asm_stmt->subcode & GF_ASM_INLINE) != 0; +} + + +/* If INLINE_P is true, mark asm statement ASM_STMT as inline. */ + +static inline void +gimple_asm_set_inline (gasm *asm_stmt, bool inline_p) +{ + if (inline_p) + asm_stmt->subcode |= GF_ASM_INLINE; + else + asm_stmt->subcode &= ~GF_ASM_INLINE; +} + + /* If INPUT_P is true, mark asm ASM_STMT as an ASM_INPUT. */ static inline void diff --git a/gcc/gimplify.c b/gcc/gimplify.c index 43cb891..fce0ce9 100644 --- a/gcc/gimplify.c +++ b/gcc/gimplify.c @@ -6360,6 +6360,7 @@ gimplify_asm_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p) gimple_asm_set_volatile (stmt, ASM_VOLATILE_P (expr) || noutputs == 0); gimple_asm_set_input (stmt, ASM_INPUT_P (expr)); + gimple_asm_set_inline (stmt, ASM_INLINE_P (expr)); gimplify_seq_add_stmt (pre_p, stmt); } diff --git a/gcc/ipa-icf-gimple.c b/gcc/ipa-icf-gimple.c index 161080c..37b9fe7 100644 --- a/gcc/ipa-icf-gimple.c +++ b/gcc/ipa-icf-gimple.c @@ -994,6 +994,9 @@ func_checker::compare_gimple_asm (const gasm *g1, const gasm *g2) if (gimple_asm_input_p (g1) != gimple_asm_input_p (g2)) return false; + if (gimple_asm_inline_p (g1) != gimple_asm_inline_p (g2)) + return false; + if (gimple_asm_ninputs (g1) != gimple_asm_ninputs (g2)) return false; diff --git a/gcc/testsuite/c-c++-common/torture/asm-inline.c b/gcc/testsuite/c-c++-common/torture/asm-inline.c new file mode 100644 index 0000000..dea8965 --- /dev/null +++ b/gcc/testsuite/c-c++-common/torture/asm-inline.c @@ -0,0 +1,53 @@ +/* { dg-do compile } */ +/* -O0 does no inlining, and -O3 does it too aggressively for this test: */ +/* { dg-skip-if "" { *-*-* } { "-O0" "-O3" } { "" } } +/* The normal asm is not inlined: */ +/* { dg-final { scan-assembler-times "w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w" 2 } } */ +/* But the asm inline is inlined: */ +/* { dg-final { scan-assembler-times "x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x" 8 } } */ + +static void f(void) +{ + asm ("w\nw\nw\nw\nw\nw\nw\nw\nw\nw\nw\nw\nw\nw\nw\n" + "w\nw\nw\nw\nw\nw\nw\nw\nw\nw\nw\nw\nw\nw\nw"); +} + +int f0(void) { f(); return 0; } +int f1(void) { f(); return 1; } +int f2(void) { f(); return 2; } +int f3(void) { f(); return 3; } + +static void fg(void) +{ + asm goto("w\nw\nw\nw\nw\nw\nw\nw\nw\nw\nw\nw\nw\nw\nw\n" + "w\nw\nw\nw\nw\nw\nw\nw\nw\nw\nw\nw\nw\nw\nw" :::: q); + q: ; +} + +int fg0(void) { fg(); return 0; } +int fg1(void) { fg(); return 1; } +int fg2(void) { fg(); return 2; } +int fg3(void) { fg(); return 3; } + +static void g(void) +{ + asm inline("x\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\n" + "x\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx"); +} + +int g0(void) { g(); return 0; } +int g1(void) { g(); return 1; } +int g2(void) { g(); return 2; } +int g3(void) { g(); return 3; } + +static void gg(void) +{ + asm inline goto("x\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\n" + "x\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx" :::: q); + q: ; +} + +int gg0(void) { gg(); return 0; } +int gg1(void) { gg(); return 1; } +int gg2(void) { gg(); return 2; } +int gg3(void) { gg(); return 3; } diff --git a/gcc/testsuite/gcc.dg/asm-qual-2.c b/gcc/testsuite/gcc.dg/asm-qual-2.c index 37df2ad..79135c3 100644 --- a/gcc/testsuite/gcc.dg/asm-qual-2.c +++ b/gcc/testsuite/gcc.dg/asm-qual-2.c @@ -6,7 +6,18 @@ void f (void) { asm volatile goto ("" :::: lab); + asm volatile inline ("" :::); + asm inline volatile ("" :::); + asm inline goto ("" :::: lab); asm goto volatile ("" :::: lab); + asm goto inline ("" :::: lab); + + asm volatile inline goto ("" :::: lab); + asm volatile goto inline ("" :::: lab); + asm inline volatile goto ("" :::: lab); + asm inline goto volatile ("" :::: lab); + asm goto volatile inline ("" :::: lab); + asm goto inline volatile ("" :::: lab); /* Duplicates are not allowed. */ asm goto volatile volatile ("" :::: lab); /* { dg-error "" } */ @@ -16,6 +27,20 @@ f (void) asm goto volatile goto ("" :::: lab); /* { dg-error "" } */ asm volatile goto goto ("" :::: lab); /* { dg-error "" } */ + asm inline volatile volatile ("" :::); /* { dg-error "" } */ + asm volatile inline volatile ("" :::); /* { dg-error "" } */ + asm volatile volatile inline ("" :::); /* { dg-error "" } */ + asm inline inline volatile ("" :::); /* { dg-error "" } */ + asm inline volatile inline ("" :::); /* { dg-error "" } */ + asm volatile inline inline ("" :::); /* { dg-error "" } */ + + asm goto inline inline ("" :::: lab); /* { dg-error "" } */ + asm inline goto inline ("" :::: lab); /* { dg-error "" } */ + asm inline inline goto ("" :::: lab); /* { dg-error "" } */ + asm goto goto inline ("" :::: lab); /* { dg-error "" } */ + asm goto inline goto ("" :::: lab); /* { dg-error "" } */ + asm inline goto goto ("" :::: lab); /* { dg-error "" } */ + lab: ; } diff --git a/gcc/tree-core.h b/gcc/tree-core.h index 356330a..84f75e6 100644 --- a/gcc/tree-core.h +++ b/gcc/tree-core.h @@ -1161,6 +1161,9 @@ struct GTY(()) tree_base { OMP_CLAUSE_LINEAR_VARIABLE_STRIDE in OMP_CLAUSE_LINEAR + ASM_INLINE_P in + ASM_EXPR + side_effects_flag: TREE_SIDE_EFFECTS in diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c index 7555dce..324c168 100644 --- a/gcc/tree-inline.c +++ b/gcc/tree-inline.c @@ -4149,6 +4149,9 @@ estimate_num_insns (gimple *stmt, eni_weights *weights) with very long asm statements. */ if (count > 1000) count = 1000; + /* If this asm is asm inline, count anything as minimum size. */ + if (gimple_asm_inline_p (as_a (stmt))) + count = MIN (1, count); return MAX (1, count); } diff --git a/gcc/tree.h b/gcc/tree.h index 8e70314..324ef5b 100644 --- a/gcc/tree.h +++ b/gcc/tree.h @@ -1263,6 +1263,9 @@ extern tree maybe_wrap_with_location (tree, location_t); ASM_OPERAND with no operands. */ #define ASM_INPUT_P(NODE) (ASM_EXPR_CHECK (NODE)->base.static_flag) #define ASM_VOLATILE_P(NODE) (ASM_EXPR_CHECK (NODE)->base.public_flag) +/* Nonzero if we want to consider this asm as minimum length and cost + for inlining decisions. */ +#define ASM_INLINE_P(NODE) (ASM_EXPR_CHECK (NODE)->base.protected_flag) /* COND_EXPR accessors. */ #define COND_EXPR_COND(NODE) (TREE_OPERAND (COND_EXPR_CHECK (NODE), 0)) From patchwork Thu Dec 27 14:59:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Segher Boessenkool X-Patchwork-Id: 1018916 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-493129-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=kernel.crashing.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="j5UA+epi"; dkim-atps=neutral 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 43QY0Y75Bpz9s7h for ; Fri, 28 Dec 2018 01:59:57 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; q=dns; s=default; b=yh6iFhfZCvi/5Q1t7bG 2Z4nwXGJPvPtEmktFKr8y1PpGgOO77dJpvpcWhBZSYjRl4QmOZp52nn2txf7IajT lwqCtu2BCTkeSERVWxWKIugf3Xt9lvnqr0mVqkjiHzX12hiyNkN+2bnkhqogMIgY ar4knatqsfb2rPXXE+dPw+8I= 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:from :to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; s=default; bh=MV6gKWlxsFt4dp0neO8QOYzhC iw=; b=j5UA+epiGe6nL9TblHeEss05kLnGxU6MgQdp7Gn1RH1sTvRqgP6Dyl1oy o6F+BUraJ5QwWC3+XFWx8bSJ8+k/RloHXgLleDU2LdkMQZpOOMKwM7DxyWq2WjYt 8BkB9+eQALgvgw+6N2279iR4j7nMZEJt1QKrGFRsBfwF7Mx0ZQ= Received: (qmail 126137 invoked by alias); 27 Dec 2018 14:59:36 -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 126059 invoked by uid 89); 27 Dec 2018 14:59:35 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY autolearn=ham version=3.3.2 spammy=setting, accidentally X-HELO: gcc1-power7.osuosl.org Received: from gcc1-power7.osuosl.org (HELO gcc1-power7.osuosl.org) (140.211.15.137) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 27 Dec 2018 14:59:34 +0000 Received: by gcc1-power7.osuosl.org (Postfix, from userid 10019) id C782C12403FF; Thu, 27 Dec 2018 14:59:32 +0000 (UTC) From: Segher Boessenkool To: gcc-patches@gcc.gnu.org Cc: Segher Boessenkool Subject: [PATCH 3/8] c: Delete a stray line in asm inline Date: Thu, 27 Dec 2018 14:59:08 +0000 Message-Id: <35014fbfa36ce89dd26fdf43387416a907be4782.1545922222.git.segher@kernel.crashing.org> In-Reply-To: References: In-Reply-To: References: X-IsSubscribed: yes I noticed I accidentally copied a line too many from the "volatile" handling to the "inline" handling. This fixes it. Tested on powerpc64-linux {-m32,-m64}; committing as trivial and obvious. Segher 2018-12-08 Segher Boessenkool gcc/c/ * c-parser (c_parser_asm_statement) [RID_INLINE]: Delete stray line setting "quals". --- gcc/c/c-parser.c | 1 - 1 file changed, 1 deletion(-) diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c index 51cc2be..e45f70b 100644 --- a/gcc/c/c-parser.c +++ b/gcc/c/c-parser.c @@ -6321,7 +6321,6 @@ c_parser_asm_statement (c_parser *parser) if (!is_inline) { is_inline = true; - quals = c_parser_peek_token (parser)->value; c_parser_consume_token (parser); } else From patchwork Thu Dec 27 14:59:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Segher Boessenkool X-Patchwork-Id: 1018918 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-493131-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=kernel.crashing.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="Ryi1YJDC"; dkim-atps=neutral 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 43QY1N4WStz9s7h for ; Fri, 28 Dec 2018 02:00:40 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; q=dns; s=default; b=MXiLuUPh8Yw1BPIrJwx +diOhgfDz87UWHssbbthJxzLM0c8P9Uz+KmtqYRoQfQ+UTgj7kWnK5mHvDvShbA5 C1qrShkUy5cAXSmK91IfGZGrgr6f6tNUUHfjF6b7Hc5kjlDCAbZ20/3yTLsJYYZl /MEZsWCBGDHL+uHccy5uC5z4= 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:from :to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; s=default; bh=Sf89IKQb6zbr8Bgyu5sK9tafh wE=; b=Ryi1YJDC9cBKd95PaNXLXdX6Uz1qtqjH7bZTn+N4ZaUWAroPapOVu57MD /3Yd/OQ7qvyl43DigiaAr8N894rKOD1tynDl8grJZedytE+NWgOtw3vx4GW/P/HH QsOD1C+oVu1b5j7Zt3TLFV7hT5cJn6n8lFWzFIoCJ/+7VatFTU= Received: (qmail 126989 invoked by alias); 27 Dec 2018 14:59:43 -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 126773 invoked by uid 89); 27 Dec 2018 14:59:41 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY autolearn=ham version=3.3.2 spammy=jason X-HELO: gcc1-power7.osuosl.org Received: from gcc1-power7.osuosl.org (HELO gcc1-power7.osuosl.org) (140.211.15.137) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 27 Dec 2018 14:59:38 +0000 Received: by gcc1-power7.osuosl.org (Postfix, from userid 10019) id EE591124068C; Thu, 27 Dec 2018 14:59:36 +0000 (UTC) From: Segher Boessenkool To: gcc-patches@gcc.gnu.org Cc: Segher Boessenkool Subject: [PATCH 4/8] c/c++, asm: Write the asm-qualifier loop without "done" boolean Date: Thu, 27 Dec 2018 14:59:09 +0000 Message-Id: <5bbbd04162b8546d9c72da11cf33e6e61d1128d7.1545922222.git.segher@kernel.crashing.org> In-Reply-To: References: In-Reply-To: References: X-IsSubscribed: yes As suggested by Jason. Segher 2018-12-10 Segher Boessenkool c/ * c-parser.c (c_parser_asm_statement): Rewrite the loop to work without "done" boolean variable. cp/ * parser.c (cp_parser_asm_definition): Rewrite the loop to work without "done" boolean variable. --- gcc/c/c-parser.c | 65 +++++++++++++++++++++++++-------------------------- gcc/cp/parser.c | 71 +++++++++++++++++++++++++------------------------------- 2 files changed, 62 insertions(+), 74 deletions(-) diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c index e45f70b..b632f68 100644 --- a/gcc/c/c-parser.c +++ b/gcc/c/c-parser.c @@ -6304,40 +6304,37 @@ c_parser_asm_statement (c_parser *parser) is_volatile = false; is_inline = false; is_goto = false; - for (bool done = false; !done; ) - switch (c_parser_peek_token (parser)->keyword) - { - case RID_VOLATILE: - if (!is_volatile) - { - is_volatile = true; - quals = c_parser_peek_token (parser)->value; - c_parser_consume_token (parser); - } - else - done = true; - break; - case RID_INLINE: - if (!is_inline) - { - is_inline = true; - c_parser_consume_token (parser); - } - else - done = true; - break; - case RID_GOTO: - if (!is_goto) - { - is_goto = true; - c_parser_consume_token (parser); - } - else - done = true; - break; - default: - done = true; - } + for (;;) + { + switch (c_parser_peek_token (parser)->keyword) + { + case RID_VOLATILE: + if (is_volatile) + break; + is_volatile = true; + quals = c_parser_peek_token (parser)->value; + c_parser_consume_token (parser); + continue; + + case RID_INLINE: + if (is_inline) + break; + is_inline = true; + c_parser_consume_token (parser); + continue; + + case RID_GOTO: + if (is_goto) + break; + is_goto = true; + c_parser_consume_token (parser); + continue; + + default: + break; + } + break; + } /* ??? Follow the C++ parser rather than using the lex_untranslated_string kludge. */ diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 3fd9a02..7660565 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -19124,47 +19124,38 @@ cp_parser_asm_definition (cp_parser* parser) cp_function_chain->invalid_constexpr = true; } - /* See if the next token is `volatile'. */ + /* Handle the asm-qualifier-list. */ if (cp_parser_allow_gnu_extensions_p (parser)) - for (bool done = false; !done ; ) - switch (cp_lexer_peek_token (parser->lexer)->keyword) - { - case RID_VOLATILE: - if (!volatile_p) - { - /* Remember that we saw the `volatile' keyword. */ - volatile_p = true; - /* Consume the token. */ - cp_lexer_consume_token (parser->lexer); - } - else - done = true; - break; - case RID_INLINE: - if (!inline_p && parser->in_function_body) - { - /* Remember that we saw the `inline' keyword. */ - inline_p = true; - /* Consume the token. */ - cp_lexer_consume_token (parser->lexer); - } - else - done = true; - break; - case RID_GOTO: - if (!goto_p && parser->in_function_body) - { - /* Remember that we saw the `goto' keyword. */ - goto_p = true; - /* Consume the token. */ - cp_lexer_consume_token (parser->lexer); - } - else - done = true; - break; - default: - done = true; - } + for (;;) + { + switch (cp_lexer_peek_token (parser->lexer)->keyword) + { + case RID_VOLATILE: + if (volatile_p) + break; + volatile_p = true; + cp_lexer_consume_token (parser->lexer); + continue; + + case RID_INLINE: + if (inline_p || !parser->in_function_body) + break; + inline_p = true; + cp_lexer_consume_token (parser->lexer); + continue; + + case RID_GOTO: + if (goto_p || !parser->in_function_body) + break; + goto_p = true; + cp_lexer_consume_token (parser->lexer); + continue; + + default: + break; + } + break; + } /* Look for the opening `('. */ if (!cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN)) From patchwork Thu Dec 27 14:59:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Segher Boessenkool X-Patchwork-Id: 1018919 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-493132-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=kernel.crashing.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="qyq8QqpC"; dkim-atps=neutral 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 43QY1f1Q08z9s7h for ; Fri, 28 Dec 2018 02:00:53 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; q=dns; s=default; b=HK+pJDj52keZnuDl8l2 cboeEeIM6D7QqtZBFnKp2VIhnFTqLIdJT1PnO32hjrcUam9u65eoEgX/aTELAyVj J+2DjTE5sh9m02r1nwY4FVtwnpkHQ4wph4fOHfRL2wIkBnk1dQVv0x2CZQV0rf7J uu8K4yWu9T1l47jLiDTbhkfI= 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:from :to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; s=default; bh=ZJqJtVq3jipx174xcRHWoZHZk sE=; b=qyq8QqpCB5LLXDlgrMr32PJAGL8eHmijwoYVfZ0bqEYPvr5Iaw8zIYTuJ v8l1XbZkhOL+Hnc5W1+X1gK9hY65FGVopyFYaVkACW4jD3sxVU6Pct9YwN3L5eHS kxi2Mcqzvb2MXq4r+tnyf8rS8cj4yyAbP0a/k6fWIs6qHwuJpQ= Received: (qmail 127471 invoked by alias); 27 Dec 2018 14:59:48 -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 127347 invoked by uid 89); 27 Dec 2018 14:59:47 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY autolearn=ham version=3.3.2 spammy=Keep, ditto, Ditto X-HELO: gcc1-power7.osuosl.org Received: from gcc1-power7.osuosl.org (HELO gcc1-power7.osuosl.org) (140.211.15.137) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 27 Dec 2018 14:59:41 +0000 Received: by gcc1-power7.osuosl.org (Postfix, from userid 10019) id 66BE512403FF; Thu, 27 Dec 2018 14:59:40 +0000 (UTC) From: Segher Boessenkool To: gcc-patches@gcc.gnu.org Cc: Segher Boessenkool Subject: [PATCH 5/8] c/c++, asm: Use nicer error for duplicate asm qualifiers Date: Thu, 27 Dec 2018 14:59:10 +0000 Message-Id: <30a12d359164450406601e125d128fc43af4d605.1545922222.git.segher@kernel.crashing.org> In-Reply-To: References: In-Reply-To: References: X-IsSubscribed: yes Also as suggested by Jason. Segher 2018-12-10 Segher Boessenkool c/ * c-parser.c (c_parser_asm_statement): Keep track of the location each asm qualifier is first seen; use that to give nicer "duplicate asm qualifier" messages. Delete 'quals" variable, instead pass the "is_volatile_ flag to build_asm_stmt directly. * c-tree.h (build_asm_stmt): Make the first arg bool instead of tree. * c-typeck.c (build_asm_stmt): Ditto; adjust. cp/ * parser.c (cp_parser_asm_definition): Rewrite the loop to work without "done" boolean variable. * parser.c (cp_parser_asm_definition): Keep track of the location each asm qualifier is first seen; use that to give nicer "duplicate asm qualifier" messages. --- gcc/c/c-parser.c | 57 ++++++++++++++++++++++++++++++++++++-------------------- gcc/c/c-tree.h | 2 +- gcc/c/c-typeck.c | 4 ++-- gcc/cp/parser.c | 45 ++++++++++++++++++++++++++++++++------------ 4 files changed, 73 insertions(+), 35 deletions(-) diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c index b632f68..ca04910 100644 --- a/gcc/c/c-parser.c +++ b/gcc/c/c-parser.c @@ -6292,41 +6292,54 @@ c_parser_for_statement (c_parser *parser, bool ivdep, unsigned short unroll, static tree c_parser_asm_statement (c_parser *parser) { - tree quals, str, outputs, inputs, clobbers, labels, ret; - bool simple, is_volatile, is_inline, is_goto; + tree str, outputs, inputs, clobbers, labels, ret; + bool simple; location_t asm_loc = c_parser_peek_token (parser)->location; int section, nsections; gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM)); c_parser_consume_token (parser); - quals = NULL_TREE; - is_volatile = false; - is_inline = false; - is_goto = false; + /* Handle the asm-qualifier-list. */ + location_t volatile_loc = UNKNOWN_LOCATION; + location_t inline_loc = UNKNOWN_LOCATION; + location_t goto_loc = UNKNOWN_LOCATION; for (;;) { - switch (c_parser_peek_token (parser)->keyword) + c_token *token = c_parser_peek_token (parser); + location_t loc = token->location; + switch (token->keyword) { case RID_VOLATILE: - if (is_volatile) - break; - is_volatile = true; - quals = c_parser_peek_token (parser)->value; + if (volatile_loc) + { + error_at (loc, "duplicate asm qualifier %qE", token->value); + inform (volatile_loc, "first seen here"); + } + else + volatile_loc = loc; c_parser_consume_token (parser); continue; case RID_INLINE: - if (is_inline) - break; - is_inline = true; + if (inline_loc) + { + error_at (loc, "duplicate asm qualifier %qE", token->value); + inform (inline_loc, "first seen here"); + } + else + inline_loc = loc; c_parser_consume_token (parser); continue; case RID_GOTO: - if (is_goto) - break; - is_goto = true; + if (goto_loc) + { + error_at (loc, "duplicate asm qualifier %qE", token->value); + inform (goto_loc, "first seen here"); + } + else + goto_loc = loc; c_parser_consume_token (parser); continue; @@ -6336,6 +6349,10 @@ c_parser_asm_statement (c_parser *parser) break; } + bool is_volatile = (volatile_loc != UNKNOWN_LOCATION); + bool is_inline = (inline_loc != UNKNOWN_LOCATION); + bool is_goto = (goto_loc != UNKNOWN_LOCATION); + /* ??? Follow the C++ parser rather than using the lex_untranslated_string kludge. */ parser->lex_untranslated_string = true; @@ -6410,9 +6427,9 @@ c_parser_asm_statement (c_parser *parser) if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>")) c_parser_skip_to_end_of_block_or_statement (parser); - ret = build_asm_stmt (quals, build_asm_expr (asm_loc, str, outputs, inputs, - clobbers, labels, simple, - is_inline)); + ret = build_asm_stmt (is_volatile, + build_asm_expr (asm_loc, str, outputs, inputs, + clobbers, labels, simple, is_inline)); error: parser->lex_untranslated_string = false; diff --git a/gcc/c/c-tree.h b/gcc/c/c-tree.h index 7f34bdc..aa66aa2 100644 --- a/gcc/c/c-tree.h +++ b/gcc/c/c-tree.h @@ -679,7 +679,7 @@ extern tree c_start_case (location_t, location_t, tree, bool); extern void c_finish_case (tree, tree); extern tree build_asm_expr (location_t, tree, tree, tree, tree, tree, bool, bool); -extern tree build_asm_stmt (tree, tree); +extern tree build_asm_stmt (bool, tree); extern int c_types_compatible_p (tree, tree); extern tree c_begin_compound_stmt (bool); extern tree c_end_compound_stmt (location_t, tree, bool); diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c index 3ebb28e..7b90b5c 100644 --- a/gcc/c/c-typeck.c +++ b/gcc/c/c-typeck.c @@ -9979,9 +9979,9 @@ process_init_element (location_t loc, struct c_expr value, bool implicit, (guaranteed to be 'volatile' or null) and ARGS (represented using an ASM_EXPR node). */ tree -build_asm_stmt (tree cv_qualifier, tree args) +build_asm_stmt (bool is_volatile, tree args) { - if (!ASM_VOLATILE_P (args) && cv_qualifier) + if (is_volatile) ASM_VOLATILE_P (args) = 1; return add_stmt (args); } diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 7660565..44fdace 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -19106,12 +19106,9 @@ cp_parser_asm_definition (cp_parser* parser) tree clobbers = NULL_TREE; tree labels = NULL_TREE; tree asm_stmt; - bool volatile_p = false; bool extended_p = false; bool invalid_inputs_p = false; bool invalid_outputs_p = false; - bool inline_p = false; - bool goto_p = false; required_token missing = RT_NONE; /* Look for the `asm' keyword. */ @@ -19125,29 +19122,50 @@ cp_parser_asm_definition (cp_parser* parser) } /* Handle the asm-qualifier-list. */ + location_t volatile_loc = UNKNOWN_LOCATION; + location_t inline_loc = UNKNOWN_LOCATION; + location_t goto_loc = UNKNOWN_LOCATION; if (cp_parser_allow_gnu_extensions_p (parser)) for (;;) { + cp_token *token = cp_lexer_peek_token (parser->lexer); + location_t loc = token->location; switch (cp_lexer_peek_token (parser->lexer)->keyword) { case RID_VOLATILE: - if (volatile_p) - break; - volatile_p = true; + if (volatile_loc) + { + error_at (loc, "duplicate asm qualifier %qT", token->u.value); + inform (volatile_loc, "first seen here"); + } + else + volatile_loc = loc; cp_lexer_consume_token (parser->lexer); continue; case RID_INLINE: - if (inline_p || !parser->in_function_body) + if (!parser->in_function_body) break; - inline_p = true; + if (inline_loc) + { + error_at (loc, "duplicate asm qualifier %qT", token->u.value); + inform (inline_loc, "first seen here"); + } + else + inline_loc = loc; cp_lexer_consume_token (parser->lexer); continue; case RID_GOTO: - if (goto_p || !parser->in_function_body) + if (!parser->in_function_body) break; - goto_p = true; + if (goto_loc) + { + error_at (loc, "duplicate asm qualifier %qT", token->u.value); + inform (goto_loc, "first seen here"); + } + else + goto_loc = loc; cp_lexer_consume_token (parser->lexer); continue; @@ -19157,6 +19175,10 @@ cp_parser_asm_definition (cp_parser* parser) break; } + bool volatile_p = (volatile_loc != UNKNOWN_LOCATION); + bool inline_p = (inline_loc != UNKNOWN_LOCATION); + bool goto_p = (goto_loc != UNKNOWN_LOCATION); + /* Look for the opening `('. */ if (!cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN)) return; @@ -19248,8 +19270,7 @@ cp_parser_asm_definition (cp_parser* parser) CPP_CLOSE_PAREN)) clobbers = cp_parser_asm_clobber_list (parser); } - else if (goto_p - && cp_lexer_next_token_is (parser->lexer, CPP_SCOPE)) + else if (goto_p && cp_lexer_next_token_is (parser->lexer, CPP_SCOPE)) /* The labels are coming next. */ labels_p = true; From patchwork Thu Dec 27 14:59:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Segher Boessenkool X-Patchwork-Id: 1018920 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-493133-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=kernel.crashing.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="IjZsiYf0"; dkim-atps=neutral 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 43QY1t5TW7z9s7h for ; Fri, 28 Dec 2018 02:01:06 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; q=dns; s=default; b=hnpTBFrNA4Cxz5iaKO6 moiIMLfJ2dynfekkUBeSC9PO+jKDilFSL9r0zDQ+MFEReVF5UKaGzGYy24WGvL0Z VnXiLX4KORWKLXtyzqGzagaxrGxW7MQqlJcuRjON/4H7w8WGuKNBNYrZUtSP4UOR aE9SxFnWHOGPHInfFxkV0h14= 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:from :to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; s=default; bh=4EnKkZna+ckCPM45KVFluYcYt BE=; b=IjZsiYf0uTESopWXkens9aZGevnN9TVXrdiaxXGOufCs1thZefgkDOdFD kd5l8/E+2QTEgoZcJBjc2UA3D113D4FBWzQt9dJtc8ReqRHNRa4mCbZvP/jnGlEX mpxBOV7hAcjcYTRzAjIdIUxXemsMNFZvv2OqFUT33GdHGa7DLg= Received: (qmail 127618 invoked by alias); 27 Dec 2018 14:59:49 -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 127491 invoked by uid 89); 27 Dec 2018 14:59:48 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY autolearn=ham version=3.3.2 spammy=89, 87, falling, talk X-HELO: gcc1-power7.osuosl.org Received: from gcc1-power7.osuosl.org (HELO gcc1-power7.osuosl.org) (140.211.15.137) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 27 Dec 2018 14:59:45 +0000 Received: by gcc1-power7.osuosl.org (Postfix, from userid 10019) id B517B124068B; Thu, 27 Dec 2018 14:59:43 +0000 (UTC) From: Segher Boessenkool To: gcc-patches@gcc.gnu.org Cc: Segher Boessenkool Subject: [PATCH 6/8] c/c++, asm: Use nicer error for const and restrict Date: Thu, 27 Dec 2018 14:59:11 +0000 Message-Id: In-Reply-To: References: In-Reply-To: References: X-IsSubscribed: yes Not all qualifiers are asm qualifiers. We can talk about that in a nicer way than just giving a generic parser error. This also adds two testcases for C++, that previously were for C only. 2018-12-10 Segher Boessenkool c/ * c-parser.c (c_parser_asm_statement) : Give a more specific error message (instead of just falling through). cp/ * parser.c (cp_parser_asm_definition) : Give a more specific error message (instead of just falling through). testsuite/ * g++.dg/asm-qual-1.C: New testcase. * g++.dg/asm-qual-2.C: New testcase. * gcc.dg/asm-qual-1.c: Update. --- gcc/c/c-parser.c | 6 +++++ gcc/cp/parser.c | 6 +++++ gcc/testsuite/g++.dg/asm-qual-1.C | 13 +++++++++++ gcc/testsuite/g++.dg/asm-qual-2.C | 46 +++++++++++++++++++++++++++++++++++++++ gcc/testsuite/gcc.dg/asm-qual-1.c | 6 ++--- 5 files changed, 73 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/g++.dg/asm-qual-1.C create mode 100644 gcc/testsuite/g++.dg/asm-qual-2.C diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c index ca04910..4baad62 100644 --- a/gcc/c/c-parser.c +++ b/gcc/c/c-parser.c @@ -6343,6 +6343,12 @@ c_parser_asm_statement (c_parser *parser) c_parser_consume_token (parser); continue; + case RID_CONST: + case RID_RESTRICT: + error_at (loc, "%qE is not an asm qualifier", token->value); + c_parser_consume_token (parser); + continue; + default: break; } diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 44fdace..36d82b8 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -19169,6 +19169,12 @@ cp_parser_asm_definition (cp_parser* parser) cp_lexer_consume_token (parser->lexer); continue; + case RID_CONST: + case RID_RESTRICT: + error_at (loc, "%qT is not an asm qualifier", token->u.value); + cp_lexer_consume_token (parser->lexer); + continue; + default: break; } diff --git a/gcc/testsuite/g++.dg/asm-qual-1.C b/gcc/testsuite/g++.dg/asm-qual-1.C new file mode 100644 index 0000000..3fba592 --- /dev/null +++ b/gcc/testsuite/g++.dg/asm-qual-1.C @@ -0,0 +1,13 @@ +// Test that qualifiers other than volatile are disallowed on asm. +// { dg-do compile } +// { dg-options "-std=gnu++98" } + +void +f () +{ + asm volatile (""); + + asm const (""); // { dg-error {'const' is not an asm qualifier} } + + asm __restrict (""); // { dg-error {'__restrict' is not an asm qualifier} } +} diff --git a/gcc/testsuite/g++.dg/asm-qual-2.C b/gcc/testsuite/g++.dg/asm-qual-2.C new file mode 100644 index 0000000..52968bd --- /dev/null +++ b/gcc/testsuite/g++.dg/asm-qual-2.C @@ -0,0 +1,46 @@ +// Test that qualifiers on asm are allowed in any order. +// { dg-do compile } +// { dg-options "-std=c++98" } + +void +f () +{ + asm volatile goto ("" :::: lab); + asm volatile inline ("" :::); + asm inline volatile ("" :::); + asm inline goto ("" :::: lab); + asm goto volatile ("" :::: lab); + asm goto inline ("" :::: lab); + + asm volatile inline goto ("" :::: lab); + asm volatile goto inline ("" :::: lab); + asm inline volatile goto ("" :::: lab); + asm inline goto volatile ("" :::: lab); + asm goto volatile inline ("" :::: lab); + asm goto inline volatile ("" :::: lab); + + /* Duplicates are not allowed. */ + asm goto volatile volatile ("" :::: lab); /* { dg-error "" } */ + asm volatile goto volatile ("" :::: lab); /* { dg-error "" } */ + asm volatile volatile goto ("" :::: lab); /* { dg-error "" } */ + asm goto goto volatile ("" :::: lab); /* { dg-error "" } */ + asm goto volatile goto ("" :::: lab); /* { dg-error "" } */ + asm volatile goto goto ("" :::: lab); /* { dg-error "" } */ + + asm inline volatile volatile ("" :::); /* { dg-error "" } */ + asm volatile inline volatile ("" :::); /* { dg-error "" } */ + asm volatile volatile inline ("" :::); /* { dg-error "" } */ + asm inline inline volatile ("" :::); /* { dg-error "" } */ + asm inline volatile inline ("" :::); /* { dg-error "" } */ + asm volatile inline inline ("" :::); /* { dg-error "" } */ + + asm goto inline inline ("" :::: lab); /* { dg-error "" } */ + asm inline goto inline ("" :::: lab); /* { dg-error "" } */ + asm inline inline goto ("" :::: lab); /* { dg-error "" } */ + asm goto goto inline ("" :::: lab); /* { dg-error "" } */ + asm goto inline goto ("" :::: lab); /* { dg-error "" } */ + asm inline goto goto ("" :::: lab); /* { dg-error "" } */ + +lab: + ; +} diff --git a/gcc/testsuite/gcc.dg/asm-qual-1.c b/gcc/testsuite/gcc.dg/asm-qual-1.c index cb37283..eff6b45 100644 --- a/gcc/testsuite/gcc.dg/asm-qual-1.c +++ b/gcc/testsuite/gcc.dg/asm-qual-1.c @@ -8,9 +8,7 @@ f (void) { asm volatile (""); - asm const (""); /* { dg-error {expected '\(' before 'const'} } */ - /* { dg-error {expected identifier} {} {target *-*-*} .-1 } */ + asm const (""); /* { dg-error {'const' is not an asm qualifier} } */ - asm restrict (""); /* { dg-error {expected '\(' before 'restrict'} } */ - /* { dg-error {expected identifier} {} {target *-*-*} .-1 } */ + asm restrict (""); /* { dg-error {'restrict' is not an asm qualifier} } */ } From patchwork Thu Dec 27 14:59:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Segher Boessenkool X-Patchwork-Id: 1018921 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-493134-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=kernel.crashing.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="wYdixSLi"; dkim-atps=neutral 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 43QY275TNMz9s7h for ; Fri, 28 Dec 2018 02:01:19 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; q=dns; s=default; b=qy525GeIXZAP9vvWP+V MYorqCODqJmmwiaVTjKNLo4WCWyN7NMzPHo4wcddKv2MDalqadqjNBxpvTuZScAe Y7ducmv1BWDEZe5ej5+0KiZd9h9NmFXdgIPMs5zKpWbXqrArtq8G/IOrkt/BQ+o0 L7KMKL6AnRpFUQ8goglSQTII= 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:from :to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; s=default; bh=xRy45UuNecqT+ZywDXgNR4xMV BQ=; b=wYdixSLiafaToYSRHZOJC3y5zxny2WqP5a5VeNQ0yVjfr5yN9ERg6WC6G PtPE29iPps0rTfWZ2O7GYEHkUIyWC5rHQT2sZGMTsKS2SCV3cPxDg8qE0yc2u7Bk ewC1gHFpXGAc7Qq/u8XS4ijjXOYD1IAKiOSHboC+UMoUr+9iU4= Received: (qmail 127933 invoked by alias); 27 Dec 2018 14:59:52 -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 127814 invoked by uid 89); 27 Dec 2018 14:59:51 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY autolearn=ham version=3.3.2 spammy= X-HELO: gcc1-power7.osuosl.org Received: from gcc1-power7.osuosl.org (HELO gcc1-power7.osuosl.org) (140.211.15.137) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 27 Dec 2018 14:59:48 +0000 Received: by gcc1-power7.osuosl.org (Postfix, from userid 10019) id 39F0F124067A; Thu, 27 Dec 2018 14:59:48 +0000 (UTC) From: Segher Boessenkool To: gcc-patches@gcc.gnu.org Cc: Segher Boessenkool Subject: [PATCH 7/8] c++, asm: Do not handle any asm-qualifiers in top-level asm Date: Thu, 27 Dec 2018 14:59:12 +0000 Message-Id: <7d103b408f9dda95b9d9f5182281ae6bb3947716.1545922222.git.segher@kernel.crashing.org> In-Reply-To: References: In-Reply-To: References: X-IsSubscribed: yes Previously, "volatile" was allowed. Changing this simplifies the code, makes things more regular, and makes the C and C++ frontends handle this the same way. 2018-12-10 Segher Boessenkool cp/ * parser.c (cp_parser_asm_definition): Do not allow any asm qualifiers on top-level asm. testsuite/ * g++.dg/asm-qual-3.C: New testcase. * gcc.dg/asm-qual-3.c: New testcase. --- gcc/cp/parser.c | 7 ++----- gcc/testsuite/g++.dg/asm-qual-3.C | 12 ++++++++++++ gcc/testsuite/gcc.dg/asm-qual-3.c | 9 +++++++++ 3 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/g++.dg/asm-qual-3.C create mode 100644 gcc/testsuite/gcc.dg/asm-qual-3.c diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 36d82b8..afc7b96 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -19125,7 +19125,8 @@ cp_parser_asm_definition (cp_parser* parser) location_t volatile_loc = UNKNOWN_LOCATION; location_t inline_loc = UNKNOWN_LOCATION; location_t goto_loc = UNKNOWN_LOCATION; - if (cp_parser_allow_gnu_extensions_p (parser)) + + if (cp_parser_allow_gnu_extensions_p (parser) && parser->in_function_body) for (;;) { cp_token *token = cp_lexer_peek_token (parser->lexer); @@ -19144,8 +19145,6 @@ cp_parser_asm_definition (cp_parser* parser) continue; case RID_INLINE: - if (!parser->in_function_body) - break; if (inline_loc) { error_at (loc, "duplicate asm qualifier %qT", token->u.value); @@ -19157,8 +19156,6 @@ cp_parser_asm_definition (cp_parser* parser) continue; case RID_GOTO: - if (!parser->in_function_body) - break; if (goto_loc) { error_at (loc, "duplicate asm qualifier %qT", token->u.value); diff --git a/gcc/testsuite/g++.dg/asm-qual-3.C b/gcc/testsuite/g++.dg/asm-qual-3.C new file mode 100644 index 0000000..95c9b57 --- /dev/null +++ b/gcc/testsuite/g++.dg/asm-qual-3.C @@ -0,0 +1,12 @@ +// Test that asm-qualifiers are not allowed on toplevel asm. +// { dg-do compile } +// { dg-options "-std=gnu++98" } + +asm const (""); // { dg-error {expected '\(' before 'const'} } +asm volatile (""); // { dg-error {expected '\(' before 'volatile'} } +asm restrict (""); // { dg-error {expected '\(' before 'restrict'} } +asm inline (""); // { dg-error {expected '\(' before 'inline'} } +asm goto (""); // { dg-error {expected '\(' before 'goto'} } + +// There are many other things wrong with this code, so: +// { dg-excess-errors "" } diff --git a/gcc/testsuite/gcc.dg/asm-qual-3.c b/gcc/testsuite/gcc.dg/asm-qual-3.c new file mode 100644 index 0000000..f85d8bf --- /dev/null +++ b/gcc/testsuite/gcc.dg/asm-qual-3.c @@ -0,0 +1,9 @@ +/* Test that asm-qualifiers are not allowed on toplevel asm. */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu99" } */ + +asm const (""); /* { dg-error {expected '\(' before 'const'} } */ +asm volatile (""); /* { dg-error {expected '\(' before 'volatile'} } */ +asm restrict (""); /* { dg-error {expected '\(' before 'restrict'} } */ +asm inline (""); /* { dg-error {expected '\(' before 'inline'} } */ +asm goto (""); /* { dg-error {expected '\(' before 'goto'} } */ From patchwork Thu Dec 27 14:59:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Segher Boessenkool X-Patchwork-Id: 1018922 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-493135-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=kernel.crashing.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="kk3cwY+Q"; dkim-atps=neutral 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 43QY2N5n5Kz9s7h for ; Fri, 28 Dec 2018 02:01:32 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; q=dns; s=default; b=YfqugeOtv9bhVMujCWW izKM7YLw9I7kI5N1KCR72/txKOOXc6Z/uO9PdCFGfXHSnj5MTC0qmQHLwWN7hpm0 3P0k9NQt4fUhNdFK0WYfOi8M2lhw8O30oRMq5rDqC7iwKbdxyJii7O4I9LgJ1SMP RhuMv6nTiUl/w5GOzWPAarkg= 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:from :to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; s=default; bh=fFzFE38ObzdL3R40aqFZG8xs+ Fw=; b=kk3cwY+Qux6vhgiFWMuVkL4Rsq1q2tyWB9S2sXD1dtykzVkltb3Wx3O/V uafXYCkobNucL5oLkJcCBH6sLDgOz/qfy8YISiYzeMPLp1QQ6FLF9pPF0j20LHv7 WYA0WKxHesu51b4J3mOG2p7OgybgYZ00O+joVdYrz8flyoPMmA= Received: (qmail 128384 invoked by alias); 27 Dec 2018 14:59:56 -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 128281 invoked by uid 89); 27 Dec 2018 14:59:55 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY autolearn=ham version=3.3.2 spammy= X-HELO: gcc1-power7.osuosl.org Received: from gcc1-power7.osuosl.org (HELO gcc1-power7.osuosl.org) (140.211.15.137) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 27 Dec 2018 14:59:54 +0000 Received: by gcc1-power7.osuosl.org (Postfix, from userid 10019) id DC3F012403FF; Thu, 27 Dec 2018 14:59:52 +0000 (UTC) From: Segher Boessenkool To: gcc-patches@gcc.gnu.org Cc: Segher Boessenkool Subject: [PATCH 8/8] c: Don't error for const or restrict as asm-qualifier Date: Thu, 27 Dec 2018 14:59:13 +0000 Message-Id: In-Reply-To: References: In-Reply-To: References: X-IsSubscribed: yes 2018-12-27 Segher Boessenkool c/ * c-parser.c (c_parser_asm_statement): Output a warning instead of an error for const and restrict. testsuite/ * gcc.dg/asm-qual-1.c: Adjust. --- gcc/c/c-parser.c | 2 +- gcc/testsuite/gcc.dg/asm-qual-1.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c index 4baad62..a960169 100644 --- a/gcc/c/c-parser.c +++ b/gcc/c/c-parser.c @@ -6345,7 +6345,7 @@ c_parser_asm_statement (c_parser *parser) case RID_CONST: case RID_RESTRICT: - error_at (loc, "%qE is not an asm qualifier", token->value); + warning_at (loc, 0, "%qE is not an asm qualifier", token->value); c_parser_consume_token (parser); continue; diff --git a/gcc/testsuite/gcc.dg/asm-qual-1.c b/gcc/testsuite/gcc.dg/asm-qual-1.c index eff6b45..4982a6b 100644 --- a/gcc/testsuite/gcc.dg/asm-qual-1.c +++ b/gcc/testsuite/gcc.dg/asm-qual-1.c @@ -8,7 +8,7 @@ f (void) { asm volatile (""); - asm const (""); /* { dg-error {'const' is not an asm qualifier} } */ + asm const (""); /* { dg-warning {'const' is not an asm qualifier} } */ - asm restrict (""); /* { dg-error {'restrict' is not an asm qualifier} } */ + asm restrict (""); /* { dg-warning {'restrict' is not an asm qualifier} } */ }