From patchwork Fri May 7 07:53:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1475379 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=nswSczSD; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Fc2l16PvNz9rx6 for ; Fri, 7 May 2021 17:53:47 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1F9303857818; Fri, 7 May 2021 07:53:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1F9303857818 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1620374024; bh=zL539VWzvgV3IOmZYRodjdd6I/moOlvfrn1p3T6XboM=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=nswSczSDNHcwK0dhnaQfxX8d0f0ZgDIlP33FInkpQ0h9hDV/V25tnOM5AMcANR/fU cUvQ6MStQDrLusGH9nCFQyH3IKOdR5yCT0cfZxFj+WFXLML2UgqTFS03aKagajyFKa FmLX5SofdpIpuZ00IPjTm9i64mHjdLIbLEJkZLDo= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id F35FF3857C66 for ; Fri, 7 May 2021 07:53:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org F35FF3857C66 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-4-9v1uilQYOMm-7dD64R_ZYg-1; Fri, 07 May 2021 03:53:38 -0400 X-MC-Unique: 9v1uilQYOMm-7dD64R_ZYg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5A8936D24F; Fri, 7 May 2021 07:53:37 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-114-59.ams2.redhat.com [10.36.114.59]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3D23C690F3; Fri, 7 May 2021 07:53:33 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.16.1/8.16.1) with ESMTPS id 1477rTaS2655862 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 7 May 2021 09:53:30 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.16.1/8.16.1/Submit) id 1477rTdv2655861; Fri, 7 May 2021 09:53:29 +0200 Date: Fri, 7 May 2021 09:53:29 +0200 To: Nathan Sidwell , Jason Merrill , "Joseph S. Myers" , Marek Polacek , David Malcolm Subject: [PATCH] libcpp: Fix up pragma preprocessing [PR100450] Message-ID: <20210507075329.GG1179226@tucnak> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-6.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_SHORT, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Hi! Since the r0-85991-ga25a8f3be322fe0f838947b679f73d6efc2a412c https://gcc.gnu.org/legacy-ml/gcc-patches/2008-02/msg01329.html changes, so that we handle macros inside of pragmas that should expand macros, during preprocessing we print those pragmas token by token, with CPP_PRAGMA printed as fputs ("#pragma ", print.outf); if (space) fprintf (print.outf, "%s %s", space, name); else fprintf (print.outf, "%s", name); where name is some identifier (so e.g. print #pragma omp parallel or #pragma omp for etc.). Because it ends in an identifier, we need to handle it like an identifier (i.e. CPP_NAME) for the decision whether a space needs to be emitted in between that #pragma whatever or #pragma whatever whatever and following token, otherwise the attached testcase is preprocessed as #pragma omp forreduction(+:red) rather than #pragma omp for reduction(+:red) The cpp_avoid_paste function is only called for this purpose. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk and release branches (in particular 8 which freezes later today)? 2021-05-07 Jakub Jelinek PR c/100450 * lex.c (cpp_avoid_paste): Handle token1 CPP_PRAGMA like CPP_NAME. * c-c++-common/gomp/pr100450.c: New test. Jakub --- libcpp/lex.c.jj 2021-05-04 21:02:13.633917100 +0200 +++ libcpp/lex.c 2021-05-06 20:32:07.695035739 +0200 @@ -3709,6 +3709,7 @@ cpp_avoid_paste (cpp_reader *pfile, cons case CPP_DEREF: return c == '*'; case CPP_DOT: return c == '.' || c == '%' || b == CPP_NUMBER; case CPP_HASH: return c == '#' || c == '%'; /* Digraph form. */ + case CPP_PRAGMA: case CPP_NAME: return ((b == CPP_NUMBER && name_p (pfile, &token2->val.str)) || b == CPP_NAME --- gcc/testsuite/c-c++-common/gomp/pr100450.c.jj 2021-05-06 20:33:45.302961055 +0200 +++ gcc/testsuite/c-c++-common/gomp/pr100450.c 2021-05-06 20:33:39.882020738 +0200 @@ -0,0 +1,20 @@ +/* PR c/100450 */ +/* { dg-do compile } */ +/* { dg-options "-fopenmp -save-temps -Wunknown-pragmas" } */ + +#define TEST(T) { \ + {T} \ +} +#define CLAUSES reduction(+:red) +#define PARALLEL_FOR(X) TEST({ \ +_Pragma("omp for CLAUSES") \ +X \ +}) + +void foo() +{ + int red = 0; + int A[3] = {}; + #pragma omp parallel shared(red) + PARALLEL_FOR( for(int i=0; i < 3; i++) red += A[i]; ) +}