public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Alejandro Colomar <alx.manpages@gmail.com>
To: Richard Biener <richard.guenther@gmail.com>,
	Martin Sebor <msebor@redhat.com>
Cc: gcc@gcc.gnu.org
Subject: Re: Spurious warning for zero-sized array parameters to a function
Date: Fri, 9 Dec 2022 18:15:44 +0100	[thread overview]
Message-ID: <07916b70-7ec9-cce4-e40a-b418cd65373f@gmail.com> (raw)
In-Reply-To: <CAFiYyc3RocRktS8itLR_AfiOEUwCaj1pRMpO_T-vGvtK16bMwA@mail.gmail.com>


[-- Attachment #1.1: Type: text/plain, Size: 1667 bytes --]

Hi Richard,

On 12/7/22 09:17, Richard Biener wrote:
[...]

>> The warnings are invalid.  While it's true that I'm referencing a pointer of
>> size 0, it's false that I'm "accessing 1 byte" in that region.  I guess this is
>> all about the bogus design of 'static' in ISO C, where you can have an array
>> parameter of size 0, which is very useful in cases like this one.
> 
> It looks like we run into pass_waccess::maybe_check_access_sizes doing
> 
>        if (sizidx == -1)
>          {
>            /* If only the pointer attribute operand was specified and
>               not size, set SIZE to the greater of MINSIZE or size of
>               one element of the pointed to type to detect smaller
>               objects (null pointers are diagnosed in this case only
>               if the pointer is also declared with attribute nonnull.  */
>            if (access.second.minsize
>                && access.second.minsize != HOST_WIDE_INT_M1U)
>              access_nelts = build_int_cstu (sizetype, access.second.minsize);
>            else if (VOID_TYPE_P (argtype) && access.second.mode == access_none)
>              /* Treat access mode none on a void* argument as expecting
>                 as little as zero bytes.  */
>              access_nelts = size_zero_node;
>            else
>              access_nelts = size_one_node;
> 
> and use size_one_node as fallback - it either doesn't consider [0] "valid" or
> for some reason chooses to interpret it as "unknown".  Can you file a bugreport
> please?

Sure;  will do!

Cheers,

Alex

> 
> Martin?
> 
> Richard.

-- 
<http://www.alejandro-colomar.es/>

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2022-12-09 17:15 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-06 16:18 Alejandro Colomar
2022-12-07  8:17 ` Richard Biener
2022-12-09 17:15   ` Alejandro Colomar [this message]
2022-12-09 20:04 ` msebor
2022-12-09 20:19   ` Alejandro Colomar
2022-12-09 20:21     ` Alejandro Colomar

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=07916b70-7ec9-cce4-e40a-b418cd65373f@gmail.com \
    --to=alx.manpages@gmail.com \
    --cc=gcc@gcc.gnu.org \
    --cc=msebor@redhat.com \
    --cc=richard.guenther@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).