From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oi1-x229.google.com (mail-oi1-x229.google.com [IPv6:2607:f8b0:4864:20::229]) by sourceware.org (Postfix) with ESMTPS id 8E3DC3857C77 for ; Fri, 2 Jul 2021 22:15:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8E3DC3857C77 Received: by mail-oi1-x229.google.com with SMTP id w127so13000778oig.12 for ; Fri, 02 Jul 2021 15:15:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=rrpIMhH3YEzwx4SNQMAK6/1fboiZ5THDargOw2jz4i0=; b=uRprh2o9Q0COIVV8L8yMHFdYSl2JrM3a4XBzfpLgo/cqF1llH8fGlGHpF3GRi1efYc 1O6++dIy91lER/xzHniDRCRF+kEerLZnIxHY/tTPpsCK/XvT5R0sca/A5OuHpItCA4/N 3l4sIVs6VjL0tKZhDQpJ5p7sPY6A4KkYz9vIrwsocmglsT96IEUN7lLazWqgwTnKkK5y tnLYmszvkwNsFRlIXSuqQrzZzUfSVpV2HY1FJAmuiyUD/sZcobnE8TyoxRsZMFHznhOZ Q8eeo+uz0cDfd/IGsUgJI7QU3IJmJbF7WVY61LHafQoUc0OdEXHSoDM5x7e8WsGkTEB8 wYzw== X-Gm-Message-State: AOAM533FIyDu+Y9eQCzz2fDZWgPUy2xbv2kVQOgsdh2ApjBF5jdH2nYT Gy75Db/ddF0hm3u54nlJzCU= X-Google-Smtp-Source: ABdhPJzqwG2Lsq35xyZRzbxpPsof0Q1Bh1QkCPKhsPJILFdamF7dC1TwgpwSY2RmluZhV+Qwoo5nZA== X-Received: by 2002:aca:f105:: with SMTP id p5mr1352415oih.148.1625264137032; Fri, 02 Jul 2021 15:15:37 -0700 (PDT) Received: from [192.168.0.41] (75-166-102-22.hlrn.qwest.net. [75.166.102.22]) by smtp.gmail.com with ESMTPSA id e74sm859964ote.14.2021.07.02.15.15.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 02 Jul 2021 15:15:36 -0700 (PDT) Subject: Re: [PING][PATCH 2/4] remove %G and %K from calls in front end and middle end (PR 98512) To: David Malcolm , gcc-patches Cc: Jeff Law , Aldy Hernandez References: <2e49b6c6-a403-a207-c41e-58f78df96b84@gmail.com> <945093c7-de5e-0350-6030-e4e79ea41161@gmail.com> <5aff247f-dfcb-cecf-e07e-b5fca877f911@gmail.com> <36e75bb4-2c3c-5b3a-9fe1-9cdb046666a3@gmail.com> <12ed261b-d35e-4c07-949a-67e085cec750@gmail.com> <7b58bb26-fab6-fc65-32e5-e09139474ba5@gmail.com> <9fd191802dfa8724ec0e09bac796c8c375ebf678.camel@redhat.com> <8632a55d-dacc-7173-4576-7c9ae96e63d8@gmail.com> From: Martin Sebor Message-ID: <35c4293b-4805-9091-d27c-7d86aab98dde@gmail.com> Date: Fri, 2 Jul 2021 16:15:35 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/mixed; boundary="------------0D13A591D5556AA519BCCC3A" Content-Language: en-US X-Spam-Status: No, score=-9.3 required=5.0 tests=BAYES_00, BODY_8BITS, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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-List-Received-Date: Fri, 02 Jul 2021 22:15:39 -0000 This is a multi-part message in MIME format. --------------0D13A591D5556AA519BCCC3A Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit On 7/2/21 2:52 PM, David Malcolm wrote: ... >>>> @@ -11425,10 +11425,10 @@ expand_expr_real_1 (tree exp, rtx >>>> target, machine_mode tmode, >>>>                                          DECL_ATTRIBUTES >>>> (fndecl))) != NULL) >>>>           { >>>>             const char *ident = lang_hooks.decl_printable_name >>>> (fndecl, 1); >>>> -           warning_at (tree_nonartificial_location (exp), >>>> +           warning_at (EXPR_LOCATION (exp), >>> >>> Are we preserving the existing behavior for >>> __attribute__((__artificial__)) here? >>> Is this behavior handled somewhere else in the patch kit? >> >> Yes.  The warning infrastructure (set_inlining_locations) uses >> the location of the site into which the statement has been inlined >> regardless of whether the inlined function is artificial. > > Do we have test coverage for this, though? > > [...] >> Attached is the revised patch for reference.  Since it just removes >> the uses of the %K and %G directives made redundant by the first >> patch in the series I'll go ahead and commit it as obvious in a day >> or so after patch 1 unless someone has further questions or requests >> for changes. > > Please can you look into the "__artificial__" test coverage, and > address the line number thing above. There are a bunch of tests for it but I couldn't find one that verifies the inlining stack. I always struggle with the DejaGnu directives for these things (I couldn't get dg-multiline-output to do what I wanted) so I cribbed the approach from plugin/diagnostic-test-inlining-*.c. Since I was changing the directives I got rid of the line numbers from their comments but instead hardcoded them in the search pattern, making the tests tighter. That's a good thing but it does of course mean that when new lines are added to the tests the directives will fail and the patterns will need to be updated. Attached is a patch with just the test I'm adding. Martin --------------0D13A591D5556AA519BCCC3A Content-Type: text/x-patch; charset=UTF-8; name="Wfree-nonheap-object-6.c.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="Wfree-nonheap-object-6.c.diff" diff --git a/gcc/testsuite/gcc.dg/Wfree-nonheap-object-6.c b/gcc/testsuite/gcc.dg/Wfree-nonheap-object-6.c new file mode 100644 index 00000000000..c109558838b --- /dev/null +++ b/gcc/testsuite/gcc.dg/Wfree-nonheap-object-6.c @@ -0,0 +1,49 @@ +/* Similar to Wfree-nonheap-object-5.c but with attribute artificial: + verify that warnings for the same call site from distinct callers + include the correct function names in the inlining stack. + { dg-do compile } + { dg-options "-O1 -Wall" } */ + +struct A +{ + void *p; +}; + +__attribute__ ((always_inline, artificial)) +inline void f0 (struct A *p) +{ + __builtin_free (p->p); // { dg-warning "\\\[-Wfree-nonheap-object" } +} + +// Expect two instances of the text below: +// { dg-regexp "In function 'f0'," "first f0 prefix" { target *-*-* } 0 } +// { dg-regexp "In function 'f0'," "second f0 prefix" { target *-*-* } 0 } + +__attribute__ ((always_inline, artificial)) +inline void f1 (struct A *p) { f0 (p); } +__attribute__ ((always_inline, artificial)) +inline void f2 (struct A *p) { f1 (p); } + +extern int array[]; +// Also expect two instances of the note: +// { dg-regexp "declared here" "first note for array" { target *-*-* } .-2 } +// { dg-regexp "declared here" "second note for array" { target *-*-* } .-3 } + +void foo (struct A *p) +{ + p->p = array + 1; + f0 (p); +} + +// { dg-regexp " +inlined from 'foo' at \[^:\]+Wfree-nonheap-object-6.c:35:\\d+:" "inlined from foo" } + + +void bar (struct A *p) +{ + p->p = array + 2; + f2 (p); +} + +// { dg-regexp " +inlined from 'f1' at \[^:\]+Wfree-nonheap-object-6.c:23:\\d+," "inlined from f1" } +// { dg-regexp " +inlined from 'f2' at \[^:\]+Wfree-nonheap-object-6.c:25:\\d+," "inlined from f2" } +// { dg-regexp " +inlined from 'bar' at \[^:\]+Wfree-nonheap-object-6.c:44:\\d+:" "inlined from bar" } --------------0D13A591D5556AA519BCCC3A--