From: Jeff Law <jeffreyalaw@gmail.com>
To: Martin Sebor <msebor@gmail.com>, gcc-patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] improve handling of aggregates in sprintf [PR 102238, 102919]
Date: Sun, 24 Oct 2021 20:18:41 -0600 [thread overview]
Message-ID: <80181666-b6f6-cf60-e044-cb374078f99d@gmail.com> (raw)
In-Reply-To: <6162e01f-6399-a48d-7cf8-c18d81f75d3f@gmail.com>
On 10/24/2021 5:43 PM, Martin Sebor via Gcc-patches wrote:
> The detection of overlapping sprintf calls has a limitation
> that leads to both false positives (PR 102919) and negatives
> (PR 102238) in corner cases involving members of aggregates.
> The false positives result from the overlap logic not using
> the size of the member used as an argument to %s to constrain
> the length of the directive output. The false negatives are
> due to the logic failing to determine the identity of a member
> from the address or reference to the enclosing object and
> an offset.
>
> The attached patch improves the detection logic to handle both
> sets of cases. In addition, it moves the utility functions used
> to implement the logic from the sprintf pass into pointer-query
> where they can be used for other purposes in the future (my
> work in progress).
>
> Tested on x86_64-linux and by building Glibc and verifying
> it doesn't cause any new warnings,
>
> Martin
>
> gcc-102238.diff
>
> PR tree-optimization/102238 - alias_offset in gimple-ssa-sprintf.c is broken
> PR tree-optimization/102919 - spurious -Wrestrict warning for sprintf into the same member array as argument plus offset
>
> gcc/ChangeLog:
>
> PR tree-optimization/102238
> PR tree-optimization/102919
> * gimple-ssa-sprintf.c (get_string_length): Ad an argument.
> (array_elt_at_offset): Move to pointer-query.
> (set_aggregate_size_and_offset): New function.
> (field_at_offset): Move to pointer-query.
> (get_origin_and_offset): Rename...
> (get_origin_and_offset_r): this. Add an argument. Make aggregate
> handling more robust.
> (get_origin_and_offset): New.
> (alias_offset): Add an argument.
> (format_string): Use subobject size determined by get_origin_and_offset.
> * pointer-query.cc (field_at_offset): Move from gimple-ssa-sprintf.c.
> Improve/correct handling of aggregates.
> (array_elt_at_offset): Same.
> * pointer-query.h (field_at_offset): Declare.
> (array_elt_at_offset): Declare.
>
> gcc/testsuite/ChangeLog:
>
> PR tree-optimization/102238
> PR tree-optimization/102919
> * gcc.dg/tree-ssa/builtin-sprintf-warn-23.c: Remove warnings.
> * gcc.dg/Wrestrict-23.c: New test.
Given you know this code better than anyone. OK.
jeff
prev parent reply other threads:[~2021-10-25 2:18 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-24 23:43 Martin Sebor
2021-10-25 2:18 ` Jeff Law [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=80181666-b6f6-cf60-e044-cb374078f99d@gmail.com \
--to=jeffreyalaw@gmail.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=msebor@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).