From patchwork Mon Aug 1 23:15:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lewis Hyatt X-Patchwork-Id: 338 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6a10:b5d6:b0:2b9:3548:2db5 with SMTP id v22csp2627888pxt; Mon, 1 Aug 2022 16:16:39 -0700 (PDT) X-Google-Smtp-Source: AA6agR4ILR4a3WXOT5gb/bOw8xLbuIjatxP4zbXMGLqq90cMrEsB3SoepvCFA+Og77oYrcdeHvXo X-Received: by 2002:a17:907:1deb:b0:730:81ea:1d09 with SMTP id og43-20020a1709071deb00b0073081ea1d09mr5997264ejc.183.1659395799011; Mon, 01 Aug 2022 16:16:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659395799; cv=none; d=google.com; s=arc-20160816; b=b7p9HiTPO2xIkG2IuU5XyQj0J9vqebNEVzHwa73SM4iIm+IOYGj5RzEIQDiwXUjKCU Dt2Ee+wdPm1u5so5D/o2L/vNiBFh/f+yYl2u32avE/CDDw0/PRqMi3RONmyYsVqQAw9r vr47CquWbui2ewvpPnC2BWUQ/5VRHKesrsSE1GJA7X8tfvZLOIgrMrOvpHuivlfU9NmR I2R8lCcbDho1Y0L90eje9j6otSeIdFnMvk/oFF6YCmqNYVj2gli1QEXH7z082HIIgLpI K1GqTgtQXTNAbxKFYkAU8IY5W08TfTUZYvY7zCMEML6MxL1ZRAAeL5rEKr9OFjz+Qxlo cWfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=IoizfAc6KqEbUAv+5srgKgIqhpm80RcvswfhdDqpqgA=; b=i4fzgnMX9dJRpyAOTq/NKSMSlDph7eiZeBtXQsr01489ZkLisD+IJZUUsogndIMAE1 He078ztn/G0ViH3g14jT7Pq7ktVIOqBOizpyVpWL0qOeOMhXlsypPdzKA7ilFWvYt558 z5DtL6f243YSrVwN/j7cK1p2pt7SPycMBuCq4IJEcF/dtLqGJphXvt0A07xrz4LJ4yTR FHXI3JfRWPU4CEq/NlGUzT5uoJrd3lCovjIGHEodIaEsDCAg/RiU7hGs3HdBIsRVw63u ObME3xBt3+Zhqrb8uE8KBagekVaQ5ANYXrEW3mkGB2aNFcAxU5mcBVot4EGuZWFGKwwh 93ug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=QcKN1x0+; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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. [8.43.85.97]) by mx.google.com with ESMTPS id du6-20020a17090772c600b0072ee40a2056si1143042ejc.862.2022.08.01.16.16.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Aug 2022 16:16:39 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=QcKN1x0+; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 C07C13857B88 for ; Mon, 1 Aug 2022 23:16:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C07C13857B88 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1659395797; bh=IoizfAc6KqEbUAv+5srgKgIqhpm80RcvswfhdDqpqgA=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=QcKN1x0+zJbVVCxoqYoPptJ9BvwKhvTVS2oOYBovk5ZMIqAYYvAH9AhVmRtdPGbjH 8wzsYX5HcOIsDDcWvYBkirpbKBouuaztNL+1QYfDhYgo1XmpsG6I5opShg5l0fJ9/w IVnvYNc2U10ABT/2/Uxd0ntDehNgyh13lZpDf6eY= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qv1-xf36.google.com (mail-qv1-xf36.google.com [IPv6:2607:f8b0:4864:20::f36]) by sourceware.org (Postfix) with ESMTPS id 47313385802B for ; Mon, 1 Aug 2022 23:15:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 47313385802B Received: by mail-qv1-xf36.google.com with SMTP id mk9so6774647qvb.11 for ; Mon, 01 Aug 2022 16:15:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc; bh=IoizfAc6KqEbUAv+5srgKgIqhpm80RcvswfhdDqpqgA=; b=mTz3k3e6WuEabZDtebOb8QqkPA6Z2S/ptsx6/GNzDCIip29vUzoE/jMAGyozWIXZ4o LR3LZ6l5ckTiVc0XwtWY61yxB5qSjgd3U0QQCHb9lhuqCHnTo2uwvt9f3FVL2BJihe6P 0Wto8nLA7qG1iDp/59teE9YC5o6iWp/PDsfLN8cjzl/EmhmxcnSqUIo3E/k5qjOehXIr kGtnIlrQTNCjWStkHm9AuoDc+cIDMfLHe2N+CrSeZ3PQzk4A9oAxNzX/wb6ZZBF1HtNw 0QnWqB/UyI7kTnKMHcmOSSETXakIx38JFUYikxeY5FlPAb8GW6XImgifidWSafP63eQs 2/uw== X-Gm-Message-State: ACgBeo1SJocFYcj8I1HCXytmq2xxyxUKwxx/RKfSwnd7eje0dEDHBzjt /JX7pgkEnzwFKVgJBI5Tn9elYy93ziU= X-Received: by 2002:a05:6214:2621:b0:476:6092:3687 with SMTP id gv1-20020a056214262100b0047660923687mr9913718qvb.21.1659395751231; Mon, 01 Aug 2022 16:15:51 -0700 (PDT) Received: from ldh-imac.local (96-67-140-173-static.hfc.comcastbusiness.net. [96.67.140.173]) by smtp.gmail.com with ESMTPSA id cq5-20020a05622a424500b0031d3d0b2a04sm7729839qtb.9.2022.08.01.16.15.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Aug 2022 16:15:50 -0700 (PDT) Date: Mon, 1 Aug 2022 19:15:48 -0400 To: gcc-patches@gcc.gnu.org Subject: [COMMITTED,gcc12] c: Fix location for _Pragma tokens [PR97498] Message-ID: <20220801231548.GA4426@ldh-imac.local> MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-3039.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, 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 Cc: Thomas Schwinge 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?1740002608843357756?= X-GMAIL-MSGID: =?utf-8?q?1740002608843357756?= Hello- This backport from r13-1596 to GCC 12 has been committed after pre-approval. This was a straightforward cherry-pick from master with no adjustments needed. I would like to note that subsequent to r13-1596, Thomas made a few commits to the libgomp testsuite to test for new diagnostic notes output after this patch; I have not backported these since I was not sure if that would be appropriate. I did verify that the libgomp testsuite changes work OK as-is on this branch, i.e. do not introduce any new failures, including with offloading enabled. -Lewis c: Fix location for _Pragma tokens [PR97498] The handling of #pragma GCC diagnostic uses input_location, which is not always as precise as needed; in particular the relative location of some tokens and a _Pragma directive will crucially determine whether a given diagnostic is enabled or suppressed in the desired way. PR97498 shows how the C frontend ends up with input_location pointing to the beginning of the line containing a _Pragma() directive, resulting in the wrong behavior if the diagnostic to be modified pertains to some tokens found earlier on the same line. This patch fixes that by addressing two issues: a) libcpp was not assigning a valid location to the CPP_PRAGMA token generated by the _Pragma directive. b) C frontend was not setting input_location to something reasonable. With this change, the C frontend is able to change input_location to point to the _Pragma token as needed. This is just a two-line fix (one for each of a) and b)), the testsuite changes were needed only because the location on the tested warnings has been somewhat improved, so the tests need to look for the new locations. gcc/c/ChangeLog: PR preprocessor/97498 * c-parser.cc (c_parser_pragma): Set input_location to the location of the pragma, rather than the start of the line. libcpp/ChangeLog: PR preprocessor/97498 * directives.cc (destringize_and_run): Override the location of the CPP_PRAGMA token from a _Pragma directive to the location of the expansion point, as is done for the tokens lexed from it. gcc/testsuite/ChangeLog: PR preprocessor/97498 * c-c++-common/pr97498.c: New test. * c-c++-common/gomp/pragma-3.c: Adapt for improved warning locations. * c-c++-common/gomp/pragma-5.c: Likewise. * gcc.dg/pragma-message.c: Likewise. libgomp/ChangeLog: * testsuite/libgomp.oacc-c-c++-common/reduction-5.c: Adapt for improved warning locations. * testsuite/libgomp.oacc-c-c++-common/vred2d-128.c: Likewise. (cherry picked from commit 0587cef3d7962a8b0f44779589ba2920dd3d71e5) diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc index 129dd727ef3..f679d53706a 100644 --- a/gcc/c/c-parser.cc +++ b/gcc/c/c-parser.cc @@ -12378,6 +12378,7 @@ c_parser_pragma (c_parser *parser, enum pragma_context context, bool *if_p) unsigned int id; const char *construct = NULL; + input_location = c_parser_peek_token (parser)->location; id = c_parser_peek_token (parser)->pragma_kind; gcc_assert (id != PRAGMA_NONE); diff --git a/gcc/testsuite/c-c++-common/gomp/pragma-3.c b/gcc/testsuite/c-c++-common/gomp/pragma-3.c index c1dee1bcc62..ae18e9b8886 100644 --- a/gcc/testsuite/c-c++-common/gomp/pragma-3.c +++ b/gcc/testsuite/c-c++-common/gomp/pragma-3.c @@ -1,13 +1,14 @@ /* { dg-additional-options "-fdump-tree-original" } */ /* PR preprocessor/103165 */ -#define inner(...) #__VA_ARGS__ ; _Pragma("omp error severity(warning) message (\"Test\") at(compilation)") +#define inner(...) #__VA_ARGS__ ; _Pragma("omp error severity(warning) message (\"Test\") at(compilation)") /* { dg-line inner_location } */ #define outer(...) inner(__VA_ARGS__) void f (void) { - const char *str = outer(inner(1,2)); /* { dg-warning "'pragma omp error' encountered: Test" } */ + const char *str = outer(inner(1,2)); + /* { dg-warning "'pragma omp error' encountered: Test" "inner expansion" { target *-*-* } inner_location } */ } #if 0 diff --git a/gcc/testsuite/c-c++-common/gomp/pragma-5.c b/gcc/testsuite/c-c++-common/gomp/pragma-5.c index af54b682789..8124f701502 100644 --- a/gcc/testsuite/c-c++-common/gomp/pragma-5.c +++ b/gcc/testsuite/c-c++-common/gomp/pragma-5.c @@ -1,13 +1,14 @@ /* { dg-additional-options "-fdump-tree-original" } */ /* PR preprocessor/103165 */ -#define inner(...) #__VA_ARGS__ ; _Pragma ( " omp error severity (warning) message (\"Test\") at(compilation)" ) +#define inner(...) #__VA_ARGS__ ; _Pragma ( " omp error severity (warning) message (\"Test\") at(compilation)" ) /* { dg-line inner_location } */ #define outer(...) inner(__VA_ARGS__) void f (void) { - const char *str = outer(inner(1,2)); /* { dg-warning "'pragma omp error' encountered: Test" } */ + const char *str = outer(inner(1,2)); + /* { dg-warning "'pragma omp error' encountered: Test" "inner expansion" { target *-*-* } inner_location } */ } #if 0 diff --git a/gcc/testsuite/c-c++-common/pr97498.c b/gcc/testsuite/c-c++-common/pr97498.c new file mode 100644 index 00000000000..f5fa420415b --- /dev/null +++ b/gcc/testsuite/c-c++-common/pr97498.c @@ -0,0 +1,4 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-Wunused-function" } */ +#pragma GCC diagnostic ignored "-Wunused-function" +static void f() {} _Pragma("GCC diagnostic error \"-Wunused-function\"") /* { dg-bogus "-Wunused-function" } */ diff --git a/gcc/testsuite/gcc.dg/pragma-message.c b/gcc/testsuite/gcc.dg/pragma-message.c index 2f44b617710..1b7cf09de0a 100644 --- a/gcc/testsuite/gcc.dg/pragma-message.c +++ b/gcc/testsuite/gcc.dg/pragma-message.c @@ -42,9 +42,11 @@ #pragma message ("Okay " THREE) /* { dg-message "Okay 3" } */ /* Create a TODO() that prints a message on compilation. */ -#define DO_PRAGMA(x) _Pragma (#x) -#define TODO(x) DO_PRAGMA(message ("TODO - " #x)) -TODO(Okay 4) /* { dg-message "TODO - Okay 4" } */ +#define DO_PRAGMA(x) _Pragma (#x) /* { dg-line pragma_loc1 } */ +#define TODO(x) DO_PRAGMA(message ("TODO - " #x)) /* { dg-line pragma_loc2 } */ +TODO(Okay 4) /* { dg-message "in expansion of macro 'TODO'" } */ +/* { dg-message "TODO - Okay 4" "test4.1" { target *-*-* } pragma_loc1 } */ +/* { dg-message "in expansion of macro 'DO_PRAGMA'" "test4.2" { target *-*-* } pragma_loc2 } */ #if 0 #pragma message ("Not printed") diff --git a/libcpp/directives.cc b/libcpp/directives.cc index f804a441f39..4104d5166e2 100644 --- a/libcpp/directives.cc +++ b/libcpp/directives.cc @@ -1930,6 +1930,7 @@ destringize_and_run (cpp_reader *pfile, const cpp_string *in, maxcount = 50; toks = XNEWVEC (cpp_token, maxcount); toks[0] = pfile->directive_result; + toks[0].src_loc = expansion_loc; do { diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/reduction-5.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/reduction-5.c index bae1dee6ad2..16aa0dd4ac1 100644 --- a/libgomp/testsuite/libgomp.oacc-c-c++-common/reduction-5.c +++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/reduction-5.c @@ -12,7 +12,7 @@ const int n = 100; -#define DO_PRAGMA(x) _Pragma (#x) +#define DO_PRAGMA(x) _Pragma (#x) /* { dg-line pragma_loc } */ #define check_reduction(gwv_par, gwv_loop) \ { \ @@ -46,7 +46,7 @@ main (void) /* Nvptx targets require a vector_length or 32 in to allow spinlocks with gangs. */ check_reduction (num_workers (nw) vector_length (vl), worker); - /* { dg-warning "region is vector partitioned but does not contain vector partitioned code" "" { target *-*-* } .-1 } */ + /* { dg-warning "region is vector partitioned but does not contain vector partitioned code" "test1" { target *-*-* } pragma_loc } */ check_reduction (vector_length (vl), vector); check_reduction (num_gangs (ng) num_workers (nw) vector_length (vl), gang worker vector); diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/vred2d-128.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/vred2d-128.c index 9c182d90a0d..84e6d51670b 100644 --- a/libgomp/testsuite/libgomp.oacc-c-c++-common/vred2d-128.c +++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/vred2d-128.c @@ -17,7 +17,7 @@ int a1[n], a2[n]; void name () \ { \ long i, j, t1, t2, t3; /* { dg-line vars } */ \ - _Pragma(outer) \ + _Pragma(outer) /* { dg-line outer } */ \ for (i = 0; i < n; i++) \ { \ t1 = 0; \ @@ -40,44 +40,44 @@ int a1[n], a2[n]; gentest (test1, "acc parallel loop gang vector_length (128) firstprivate (t1, t2)", "acc loop vector reduction(+:t1) reduction(-:t2)") -/* { dg-warning {'t1' is used uninitialized} {} { target *-*-* } .-1 } +/* { dg-warning {'t1' is used uninitialized} {} { target *-*-* } outer } { dg-note {'t1' was declared here} {} { target *-*-* } vars } { dg-note {in expansion of macro 'gentest'} {} { target { ! offloading_enabled } } .-4 } TODO See PR101551 for 'offloading_enabled' differences. */ -/* { dg-warning {'t2' is used uninitialized} {} { target *-*-* } .-5 } +/* { dg-warning {'t2' is used uninitialized} {} { target *-*-* } outer } { dg-note {'t2' was declared here} {} { target *-*-* } vars } { DUP_dg-note {in expansion of macro 'gentest'} {} { target { ! offloading_enabled } } .-8 } TODO See PR101551 for 'offloading_enabled' differences. */ gentest (test2, "acc parallel loop gang vector_length (128) firstprivate (t1, t2)", "acc loop worker vector reduction(+:t1) reduction(-:t2)") -/* { dg-warning {'t1' is used uninitialized} {} { target *-*-* } .-1 } +/* { DUPdg-warning {'t1' is used uninitialized} {} { target *-*-* } outer } { DUP_dg-note {'t1' was declared here} {} { target *-*-* } vars } { dg-note {in expansion of macro 'gentest'} {} { target { ! offloading_enabled } } .-4 } TODO See PR101551 for 'offloading_enabled' differences. */ -/* { dg-warning {'t2' is used uninitialized} {} { target *-*-* } .-5 } +/* { DUPdg-warning {'t2' is used uninitialized} {} { target *-*-* } outer } { DUP_dg-note {'t2' was declared here} {} { target *-*-* } vars } { DUP_dg-note {in expansion of macro 'gentest'} {} { target { ! offloading_enabled } } .-8 } TODO See PR101551 for 'offloading_enabled' differences. */ gentest (test3, "acc parallel loop gang worker vector_length (128) firstprivate (t1, t2)", "acc loop vector reduction(+:t1) reduction(-:t2)") -/* { dg-warning {'t1' is used uninitialized} {} { target *-*-* } .-1 } +/* { DUPdg-warning {'t1' is used uninitialized} {} { target *-*-* } outer } { DUP_dg-note {'t1' was declared here} {} { target *-*-* } vars } { dg-note {in expansion of macro 'gentest'} {} { target { ! offloading_enabled } } .-4 } TODO See PR101551 for 'offloading_enabled' differences. */ -/* { dg-warning {'t2' is used uninitialized} {} { target *-*-* } .-5 } +/* { DUPdg-warning {'t2' is used uninitialized} {} { target *-*-* } outer } { DUP_dg-note {'t2' was declared here} {} { target *-*-* } vars } { DUP_dg-note {in expansion of macro 'gentest'} {} { target { ! offloading_enabled } } .-8 } TODO See PR101551 for 'offloading_enabled' differences. */ gentest (test4, "acc parallel loop firstprivate (t1, t2)", "acc loop reduction(+:t1) reduction(-:t2)") -/* { dg-warning {'t1' is used uninitialized} {} { target *-*-* } .-1 } +/* { DUPdg-warning {'t1' is used uninitialized} {} { target *-*-* } outer } { DUP_dg-note {'t1' was declared here} {} { target *-*-* } vars } { dg-note {in expansion of macro 'gentest'} {} { target { ! offloading_enabled } } .-4 } TODO See PR101551 for 'offloading_enabled' differences. */ -/* { dg-warning {'t2' is used uninitialized} {} { target *-*-* } .-5 } +/* { DUPdg-warning {'t2' is used uninitialized} {} { target *-*-* } outer } { DUP_dg-note {'t2' was declared here} {} { target *-*-* } vars } { DUP_dg-note {in expansion of macro 'gentest'} {} { target { ! offloading_enabled } } .-8 } TODO See PR101551 for 'offloading_enabled' differences. */