From patchwork Fri Dec 30 17:21:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lewis Hyatt X-Patchwork-Id: 37717 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2991611wrt; Fri, 30 Dec 2022 09:22:30 -0800 (PST) X-Google-Smtp-Source: AMrXdXsKPGsjIc5HMDDq8cemh+tpbPT4vUNRbyvQU9uorLqecz5DqtGImYnMlzGykaxDQocAI2dp X-Received: by 2002:aa7:d04f:0:b0:46f:97fb:1321 with SMTP id n15-20020aa7d04f000000b0046f97fb1321mr28143836edo.35.1672420950663; Fri, 30 Dec 2022 09:22:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672420950; cv=none; d=google.com; s=arc-20160816; b=bv+HxXN8f63BBEmGhhHHF6ptU4S3NYswCeFyKx/92Ppe7ir/WyLOx4+qZAk5CxqdzX HliFN1Ul5lTDGjIXLm8J2HE0gWE+1d0ieETFUtz6t88ChSVGDatrVpYwKsADrgFC7nfX CGPlpfj/MNINeodpTNVEB8K8AGEslV3FjIkN2VKRm4DBPffhpjjfiGiiDGqFMkqWGr9I 1/LoFEBIeh2ApstwhzdIIolKIlIkc6R/YMiFXFG6xlECLcgZzAK9NrHgr5OZdFJpXGsZ bz9YCk9HCrFdqYgCNeYBXyzAy2zb0pYA0il5UKlSgcVz2Dv3QdXCZ+OMKEL/VGQduJDQ 5/eg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:delivered-to:dkim-signature:dkim-filter; bh=Dwmyx+fzJYT3Lmx4tCQGJnse1dOGSAonS0HXBzYGwQg=; b=wA7UnYzh+U/k1pCJQ6hG/aqbkzXkg6CNqeqq0ivwdkzNWYM71Q+yWevimq8+N6BtAR T7lQESYb7G3rf5cAf78h+4UoyOWTHhfJGJ9KxrkEEG7L/uiyQwFsiLc85lVpXS79m8T/ K7LXWNRC0KgBoaxs+j3kmMaKc6lXv1MGW9upIDVC53V3FRXePOU1VMD3MROkYHlLlGwU 2zOuB1P11x3f5pYaxLpSJkh2M9JUTV+W7IemcVjGHwl7t06YJj4V1ag/SRjmo2tsvK21 8PaZmYA1nnjs6LybjrCYM1dUYcwGvfWpzeVBLBKuNMbvL8JnXARM+kMEvSG3+BRpALbK 69yA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=xU9AbnvW; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id hd16-20020a170907969000b007826de24087si17864037ejc.228.2022.12.30.09.22.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Dec 2022 09:22:30 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=xU9AbnvW; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6DBFC3858C30 for ; Fri, 30 Dec 2022 17:22:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6DBFC3858C30 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1672420949; bh=Dwmyx+fzJYT3Lmx4tCQGJnse1dOGSAonS0HXBzYGwQg=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=xU9AbnvW9AotMiFXN7F42EEMLAClNXfQY2KskD47CWCITUhilkFPub4bpMvSG6Acn ymB/sCF7GxMZKSwytuZqDXAfHJt2Rf+PQstZPzw6ChnVqR0qZkxJj9goajHaYv+AoI CbPRm2cWT3ynSlvBbYdSqOZ7Op2xRYAwIcihkm6w= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qv1-xf34.google.com (mail-qv1-xf34.google.com [IPv6:2607:f8b0:4864:20::f34]) by sourceware.org (Postfix) with ESMTPS id 7955C3858D1E for ; Fri, 30 Dec 2022 17:21:45 +0000 (GMT) Received: by mail-qv1-xf34.google.com with SMTP id d13so15080560qvj.8 for ; Fri, 30 Dec 2022 09:21:45 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Dwmyx+fzJYT3Lmx4tCQGJnse1dOGSAonS0HXBzYGwQg=; b=EZPB2Jh/N+eznfyTenNlPdwXyFNxrsMIOiP2i4KRPEvWl28ux/AtIHXAXtvP4K6/iE W9ry4tAyk/MqqHlOjusTzVLy121fTpiNtmHuxfemS/oxM46mrEjHQfjm0sFkg7km1Kph 85cN185Wef14h4ItD/ya1A/+WYYjwQKKKTmgnwqKxaXnxRrRnXZR2BMzDs9uCnWWcrT9 ngL0qUc7Ns3FQK98gVmwbx7GvIR8wEP48Q5rgEJdh2w4RJ0KJGouwXyvw5kX0rF4+Tir 4SuBIIVKgv99+/+BVZmLg/dPCgn38X79xuacgX2bXJcN6uTdDmLVPBVddQFnd59bhHiy Zl/g== X-Gm-Message-State: AFqh2kohJJ5VCEKoIOKem0dAp0zstcMyNZamAj/qB5QPysu/GSg5JQ9O pwPvsDJrVtrq4Zi6a9GAmT41+0WU/AM= X-Received: by 2002:ad4:5d6c:0:b0:4e8:c749:7f3a with SMTP id fn12-20020ad45d6c000000b004e8c7497f3amr65565626qvb.50.1672420904774; Fri, 30 Dec 2022 09:21:44 -0800 (PST) Received: from localhost.localdomain (96-67-140-173-static.hfc.comcastbusiness.net. [96.67.140.173]) by smtp.gmail.com with ESMTPSA id u7-20020a05620a430700b006cbc6e1478csm15407998qko.57.2022.12.30.09.21.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Dec 2022 09:21:44 -0800 (PST) To: gcc-patches@gcc.gnu.org Cc: Lewis Hyatt Subject: [PATCH] preprocessor: Don't register pragmas in directives-only mode [PR108244] Date: Fri, 30 Dec 2022 12:21:37 -0500 Message-Id: X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Spam-Status: No, score=-3038.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: Lewis Hyatt via Gcc-patches From: Lewis Hyatt Reply-To: Lewis Hyatt Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1753660470705755251?= X-GMAIL-MSGID: =?utf-8?q?1753660470705755251?= libcpp's directives-only mode does not expect deferred pragmas to be registered, but to date the c-family registration process has not checked for this case. That issue became more visible since r13-1544, which added the commonly used GCC diagnostic pragmas to the set of those registered in preprocessing modes. Fix it by checking for directives-only mode in c-family/c-pragma.cc. gcc/c-family/ChangeLog: PR preprocessor/108244 * c-pragma.cc (c_register_pragma_1): Don't attempt to register any deferred pragmas if -fdirectives-only. (init_pragma): Likewise. gcc/testsuite/ChangeLog: * c-c++-common/cpp/pr108244-1.c: New test. * c-c++-common/cpp/pr108244-2.c: New test. * c-c++-common/cpp/pr108244-3.c: New test. --- Notes: Hello- https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108244 The PR notes a regression in GCC 13 which is fixed by the attached patch. Bootstrap+regtest all languages on x86-64 Linux looks good. Please let me know if it is OK? Thanks. -Lewis gcc/c-family/c-pragma.cc | 54 ++++++++++++--------- gcc/testsuite/c-c++-common/cpp/pr108244-1.c | 5 ++ gcc/testsuite/c-c++-common/cpp/pr108244-2.c | 5 ++ gcc/testsuite/c-c++-common/cpp/pr108244-3.c | 6 +++ 4 files changed, 46 insertions(+), 24 deletions(-) create mode 100644 gcc/testsuite/c-c++-common/cpp/pr108244-1.c create mode 100644 gcc/testsuite/c-c++-common/cpp/pr108244-2.c create mode 100644 gcc/testsuite/c-c++-common/cpp/pr108244-3.c diff --git a/gcc/c-family/c-pragma.cc b/gcc/c-family/c-pragma.cc index 142a46441ac..91fabf0a513 100644 --- a/gcc/c-family/c-pragma.cc +++ b/gcc/c-family/c-pragma.cc @@ -1647,7 +1647,8 @@ c_register_pragma_1 (const char *space, const char *name, if (flag_preprocess_only) { - if (!(allow_expansion || ihandler.early_handler.handler_1arg)) + if (cpp_get_options (parse_in)->directives_only + || !(allow_expansion || ihandler.early_handler.handler_1arg)) return; pragma_pp_data pp_data; @@ -1811,34 +1812,39 @@ c_pp_invoke_early_pragma_handler (unsigned int id) void init_pragma (void) { - if (flag_openacc) + + if (!cpp_get_options (parse_in)->directives_only) { - const int n_oacc_pragmas = ARRAY_SIZE (oacc_pragmas); - int i; + if (flag_openacc) + { + const int n_oacc_pragmas = ARRAY_SIZE (oacc_pragmas); + int i; - for (i = 0; i < n_oacc_pragmas; ++i) - cpp_register_deferred_pragma (parse_in, "acc", oacc_pragmas[i].name, - oacc_pragmas[i].id, true, true); - } + for (i = 0; i < n_oacc_pragmas; ++i) + cpp_register_deferred_pragma (parse_in, "acc", oacc_pragmas[i].name, + oacc_pragmas[i].id, true, true); + } - if (flag_openmp) - { - const int n_omp_pragmas = ARRAY_SIZE (omp_pragmas); - int i; + if (flag_openmp) + { + const int n_omp_pragmas = ARRAY_SIZE (omp_pragmas); + int i; - for (i = 0; i < n_omp_pragmas; ++i) - cpp_register_deferred_pragma (parse_in, "omp", omp_pragmas[i].name, - omp_pragmas[i].id, true, true); - } - if (flag_openmp || flag_openmp_simd) - { - const int n_omp_pragmas_simd = sizeof (omp_pragmas_simd) - / sizeof (*omp_pragmas); - int i; + for (i = 0; i < n_omp_pragmas; ++i) + cpp_register_deferred_pragma (parse_in, "omp", omp_pragmas[i].name, + omp_pragmas[i].id, true, true); + } + if (flag_openmp || flag_openmp_simd) + { + const int n_omp_pragmas_simd + = sizeof (omp_pragmas_simd) / sizeof (*omp_pragmas); + int i; - for (i = 0; i < n_omp_pragmas_simd; ++i) - cpp_register_deferred_pragma (parse_in, "omp", omp_pragmas_simd[i].name, - omp_pragmas_simd[i].id, true, true); + for (i = 0; i < n_omp_pragmas_simd; ++i) + cpp_register_deferred_pragma (parse_in, "omp", + omp_pragmas_simd[i].name, + omp_pragmas_simd[i].id, true, true); + } } if (!flag_preprocess_only) diff --git a/gcc/testsuite/c-c++-common/cpp/pr108244-1.c b/gcc/testsuite/c-c++-common/cpp/pr108244-1.c new file mode 100644 index 00000000000..1678004a4d9 --- /dev/null +++ b/gcc/testsuite/c-c++-common/cpp/pr108244-1.c @@ -0,0 +1,5 @@ +/* { dg-do preprocess } */ +/* { dg-additional-options "-fdirectives-only" } */ +#pragma GCC diagnostic push +#ifdef t +#endif diff --git a/gcc/testsuite/c-c++-common/cpp/pr108244-2.c b/gcc/testsuite/c-c++-common/cpp/pr108244-2.c new file mode 100644 index 00000000000..017682ad186 --- /dev/null +++ b/gcc/testsuite/c-c++-common/cpp/pr108244-2.c @@ -0,0 +1,5 @@ +/* { dg-do preprocess } */ +/* { dg-additional-options "-fdirectives-only" } */ +#pragma message "hello" +#ifdef t +#endif diff --git a/gcc/testsuite/c-c++-common/cpp/pr108244-3.c b/gcc/testsuite/c-c++-common/cpp/pr108244-3.c new file mode 100644 index 00000000000..e9e784b40d5 --- /dev/null +++ b/gcc/testsuite/c-c++-common/cpp/pr108244-3.c @@ -0,0 +1,6 @@ +/* { dg-do preprocess } */ +/* { dg-additional-options "-fdirectives-only -fopenmp" } */ +/* { dg-require-effective-target "fopenmp" } */ +#pragma omp parallel +#ifdef t +#endif