From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Dwmyx+fzJYT3Lmx4tCQGJnse1dOGSAonS0HXBzYGwQg=; b=mgIk+a2IcampAL0gI+sCgLHGs5UM0WLJ6/BHplel92AjkCtJFlwcxMzxehwM0x3z8b LDO+mnCen43NZnEPvLKHWldScOWCPdYxPcEtJjtG4iN/X6Rpk8qiuXDdSWLPVQEaTQE8 zo5H0iGMPrRedI/NuIyriMUSV1a/euUNj3b7KuSPhjjZLcIleeZyTqB9hwiLm9evezqv rbgEj1Lp70tvOQIJKRbdowF7u48VS/SrgVMD6k36zy9UFFqOhzUcnhn3ZlhHtwoPThhZ y8485+EMsnAviOo/CBW9sWRGgY+lHgk+3zOi5+NOP8eQjflB2gZJgCXFKm4QbYxRkNrC eOeg== 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-Google-Smtp-Source: AMrXdXs7sLVmYL74SxJZtKf/eAaVngrIPsPhnJ8jLTIYty1x5MlpGQcENjCuBDVrQtmdI2QhNG9+2Q== 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) From: Lewis Hyatt 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 Content-Transfer-Encoding: 8bit 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 List-Id: 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