From: Marek Polacek <polacek@redhat.com>
To: David Malcolm <dmalcolm@redhat.com>
Cc: gcc-patches@gcc.gnu.org, Joseph Myers <joseph@codesourcery.com>
Subject: Re: [PATCH v3] c, analyzer: support named constants in analyzer [PR106302]
Date: Tue, 15 Nov 2022 13:39:37 -0500 [thread overview]
Message-ID: <Y3Pc6QdWeRiHrdT8@redhat.com> (raw)
In-Reply-To: <af77b16e0296d57c2df5a5edb7c2aa25c3290cb1.camel@redhat.com>
On Tue, Nov 15, 2022 at 01:35:05PM -0500, David Malcolm wrote:
> On Mon, 2022-11-14 at 15:42 -0500, Marek Polacek wrote:
> > On Fri, Nov 11, 2022 at 10:23:10PM -0500, David Malcolm wrote:
> > > Changes since v1: ported the doc changes from texinfo to sphinx
> > >
> > > Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.
> > >
> > > Are the C frontend parts OK for trunk? (I can self-approve the
> > > analyzer parts)
> >
> > Sorry for the delay.
> >
> > > The patch adds an interface for frontends to call into the analyzer
> > > as
> > > the translation unit finishes. The analyzer can then call back
> > > into the
> > > frontend to ask about the values of the named constants it cares
> > > about
> > > whilst the frontend's data structures are still around.
> > >
> > > The patch implements this for the C frontend, which looks up the
> > > names
> > > by looking for named CONST_DECLs (which handles enum values).
> > > Failing
> > > that, it attempts to look up the values of macros but only the
> > > simplest
> > > cases are supported (a non-traditional macro with a single
> > > CPP_NUMBER
> > > token). It does this by building a buffer containing the macro
> > > definition and rerunning a lexer on it.
> > >
> > > The analyzer gracefully handles the cases where named values aren't
> > > found (such as anything more complicated than described above).
> > >
> > > The patch ports the analyzer to use this mechanism for "O_RDONLY",
> > > "O_WRONLY", and "O_ACCMODE". I have successfully tested my socket
> > > patch
> > > to also use this for "SOCK_STREAM" and "SOCK_DGRAM", so the
> > > technique
> > > seems to work.
> >
> > So this works well for code like
> >
> > enum __socket_type {
> > SOCK_STREAM = 1,
> >
> > #define SOCK_STREAM SOCK_STREAM
> > };
> >
> > ?
>
> Yes: c_translation_unit::lookup_constant_by_id does the "lookup_name"
> first, and this finds the CONST_DECL, so it doesn't need to look at
> macros for this case.
Ah, nice.
> I've added a testcase for this in the v3 patch (gcc.dg/analyzer/named-
> constants-via-enum-and-macro.c)
Thanks.
> Thanks for the review. Here's a v3 version of the patch.
>
> Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.
>
> Are the C FE parts OK for trunk?
Ok, thanks.
Marek
next prev parent reply other threads:[~2022-11-15 18:39 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-31 19:07 [PATCH] " David Malcolm
2022-11-08 3:02 ` [PATCH] analyzer: add warnings relating to sockets [PR106140] David Malcolm
2022-11-12 3:27 ` [PATCH v2] " David Malcolm
2022-11-15 19:02 ` David Malcolm
2022-11-08 3:06 ` PING: Re: [PATCH] c, analyzer: support named constants in analyzer [PR106302] David Malcolm
2022-11-12 3:23 ` [PATCH v2] " David Malcolm
2022-11-12 3:32 ` David Malcolm
2022-11-14 20:42 ` Marek Polacek
2022-11-15 18:35 ` [PATCH v3] " David Malcolm
2022-11-15 18:39 ` Marek Polacek [this message]
2022-11-17 3:05 ` [PATCH] c: fix ICE with -fanalyzer and -Wunused-macros [PR107711] David Malcolm
2022-11-17 15:30 ` Marek Polacek
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=Y3Pc6QdWeRiHrdT8@redhat.com \
--to=polacek@redhat.com \
--cc=dmalcolm@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=joseph@codesourcery.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).