From: David Malcolm <dmalcolm@redhat.com>
To: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>,
David Malcolm via Gcc-patches <gcc-patches@gcc.gnu.org>,
Tim Lange <mail@tim-lange.me>
Subject: Re: [PATCH] analyzer: consider empty ranges and zero byte accesses [PR106845]
Date: Sun, 11 Sep 2022 09:40:32 +0100 [thread overview]
Message-ID: <e5b744b659ebcce174fa671510827ddca2b2fbf9.camel@redhat.com> (raw)
In-Reply-To: <2B5E71EE-0E60-4A19-9546-D0BA7377AD6D@gmail.com>
On Sun, 2022-09-11 at 10:21 +0200, Bernhard Reutner-Fischer wrote:
> On 11 September 2022 10:04:51 CEST, David Malcolm via Gcc-patches
> <gcc-patches@gcc.gnu.org> wrote:
>
> > > +++ b/gcc/testsuite/gcc.dg/analyzer/pr106845.c
> > > @@ -0,0 +1,11 @@
> > > +int buf_size;
> > > +
> > > +int
> > > +main (void)
> > > +{
> > > + char buf[buf_size];
> > > +
> > > + __builtin_memset (&buf[1], 0, buf_size);
> > > +
> > > + return 0;
> > > +}
> >
> > ...it took me a moment to realize that the analyzer "sees" that
> > this is
> > "main", and thus buf_size is 0.
>
> Is this a valid assumption?
Not always, but often.
I suppose we could add an option for this.
>
> What if I have a lib (preloaded maybe) that sets it to 42?
...or, say, a C++ ctor for a global object that runs before main, that
has side-effects (see e.g. PR analyzer/97115).
>
> BTW, do we handle -Wl,-init,youre_toast
> where main isn't the entry point?
The analyzer currently has no knowledge of this; it blithely assumes
that no code runs before "main". It also doesn't report about "leaks"
that happen when returning from main, whereas in theory someone could,
say, implement the guts of their program in an atexit handler.
I'm making assumptions in order to try to be more useful for the common
cases, potentially at the expense of the less common ones.
I'm not particularly familiar with the pre-main startup and post-main
shutdown of a process; feel free to file a bug if you want -fanalyzer
to be able to handle this kind of thing (links to pertinent docs would
be helpful!)
Thanks
Dave
>
> Just curious..
> thanks,
>
> >
> > Interestingly, if I rename it to not be "main" (and thus buf_size
> > could
> > be non-zero), we still don't complain:
> > https://godbolt.org/z/PezfTo9Mz
> > Presumably this is a known limitation of the symbolic bounds
> > checking?
> >
> > Thanks
> > Dave
> >
>
next prev parent reply other threads:[~2022-09-11 8:40 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-10 22:19 Tim Lange
2022-09-11 8:04 ` David Malcolm
2022-09-11 8:21 ` Bernhard Reutner-Fischer
2022-09-11 8:40 ` David Malcolm [this message]
2022-09-11 12:08 ` Tim Lange
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=e5b744b659ebcce174fa671510827ddca2b2fbf9.camel@redhat.com \
--to=dmalcolm@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=mail@tim-lange.me \
--cc=rep.dot.nop@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).