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'} } */