From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12546 invoked by alias); 23 Nov 2017 20:24:41 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 12534 invoked by uid 89); 23 Nov 2017 20:24:40 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.7 required=5.0 tests=BAYES_00,GIT_PATCH_2,GIT_PATCH_3,KAM_LAZY_DOMAIN_SECURITY,KB_WAM_FROM_NAME_SINGLEWORD,SPF_HELO_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy= 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; Thu, 23 Nov 2017 20:24:39 +0000 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 50A7C8763A for ; Thu, 23 Nov 2017 20:24:38 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-116-247.ams2.redhat.com [10.36.116.247]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EA72917CC3 for ; Thu, 23 Nov 2017 20:24:37 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id vANKOUng001692 for ; Thu, 23 Nov 2017 21:24:30 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id vANKOTCh001691 for gcc-patches@gcc.gnu.org; Thu, 23 Nov 2017 21:24:29 +0100 Date: Thu, 23 Nov 2017 20:30:00 -0000 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Subject: [committed] Reject invalid #pragma omp declare simd in the C FE Message-ID: <20171123202429.GQ14653@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.7.1 (2016-10-04) X-IsSubscribed: yes X-SW-Source: 2017-11/txt/msg02162.txt.bz2 Hi! Unlike C++, C doesn't allow function declarations inside of if/while/for body without {}s around, or after a label, while with #pragma omp declare simd in between and -fopenmp it would happily accept it. That is wrong, the presence/absence of OpenMP pragmas shouldn't change parsing that way. Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk. 2017-11-23 Jakub Jelinek * c-parser.c (c_parser_omp_declare_simd): Reject declare simd in pragma_stmt context. * gcc.dg/gomp/declare-simd-1.c (f9): Remove. * gcc.dg/gomp/declare-simd-5.c: New test. --- gcc/c/c-parser.c.jj 2017-11-20 19:55:39.000000000 +0100 +++ gcc/c/c-parser.c 2017-11-23 17:43:51.623042138 +0100 @@ -17483,11 +17483,11 @@ c_parser_omp_declare_simd (c_parser *par break; case pragma_struct: case pragma_param: + case pragma_stmt: c_parser_error (parser, "%<#pragma omp declare simd%> must be followed by " "function declaration or definition"); break; case pragma_compound: - case pragma_stmt: if (c_parser_next_token_is (parser, CPP_KEYWORD) && c_parser_peek_token (parser)->keyword == RID_EXTENSION) { --- gcc/testsuite/gcc.dg/gomp/declare-simd-1.c.jj 2016-04-06 14:46:29.000000000 +0200 +++ gcc/testsuite/gcc.dg/gomp/declare-simd-1.c 2017-11-23 17:46:04.914434577 +0100 @@ -58,18 +58,6 @@ f7 (int x) /* { dg-final { scan-assembler-times "_ZGVeM16v_f7:" 1 { target { i?86-*-* x86_64-*-* } } } } */ /* { dg-final { scan-assembler-times "_ZGVeN16v_f7:" 1 { target { i?86-*-* x86_64-*-* } } } } */ -int -f9 (int x) -{ - if (x) - #pragma omp declare simd simdlen (8) aligned (b : 8 * sizeof (int)) - extern int f10 (int a, int *b, int c); - while (x < 10) - #pragma omp declare simd simdlen (8) aligned (b : 8 * sizeof (int)) - extern int f11 (int a, int *b, int c); - return x; -} - #pragma omp declare simd uniform (a) aligned (b : 8 * sizeof (int)) linear (c : 4) simdlen (8) int f12 (int c; int *b; int a; int a, int *b, int c); --- gcc/testsuite/gcc.dg/gomp/declare-simd-5.c.jj 2017-11-23 17:47:01.886747780 +0100 +++ gcc/testsuite/gcc.dg/gomp/declare-simd-5.c 2017-11-23 17:51:10.749747753 +0100 @@ -0,0 +1,35 @@ +/* Test parsing of #pragma omp declare simd */ +/* { dg-do compile } */ + +int +f1 (int x) +{ + if (x) + #pragma omp declare simd simdlen (8) aligned (b : 8 * sizeof (int)) + extern int f3 (int a, int *b, int c); /* { dg-error "must be followed by function declaration or definition" } */ + while (x < 10) + #pragma omp declare simd simdlen (8) aligned (b : 8 * sizeof (int)) + extern int f4 (int a, int *b, int c); /* { dg-error "must be followed by function declaration or definition" } */ + { +lab: + #pragma omp declare simd simdlen (8) aligned (b : 8 * sizeof (int)) + extern int f5 (int a, int *b, int c); /* { dg-error "must be followed by function declaration or definition" } */ + x++; /* { dg-error "expected expression before" "" { target *-*-* } .-1 } */ + } + return x; +} + +int +f2 (int x) +{ + if (x) + extern int f6 (int a, int *b, int c); /* { dg-error "expected expression before" } */ + while (x < 10) + extern int f7 (int a, int *b, int c); /* { dg-error "expected expression before" } */ + { +lab: + extern int f8 (int a, int *b, int c); /* { dg-error "a label can only be part of a statement and a declaration is not a statement" } */ + x++; + } + return x; +} Jakub