public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Gavin Ray <ray.gavin97@gmail.com>
To: gcc@gcc.gnu.org
Subject: -fanalyzer: Questions on C vs CPP + use of GCC attr's like malloc()/access()
Date: Wed, 23 Nov 2022 20:49:16 -0500	[thread overview]
Message-ID: <CAFtvWZNgv_HTMoYBd7=PoXLN-3TP=sN02o55FF2jq+jfxG5cSw@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1005 bytes --]

Hey all, just a few questions about the fantastic GCC Static Analyzer:

- It's stated that support for C++ vs C is very limited. Does this apply if
  you're writing C++ that is very similar-looking to C and uses few of C++'s
  advanced features?

- I noticed that in C++, the "gnu::malloc" attributes don't seem to report
  "warning: leak of 'xxx_alloc()' [CWE-401] [-Wanalyzer-malloc-leak]", is
this
  normal?

- Is it worthwhile to spend time annotating your method signatures with
  attributes like "malloc" and "access"? Do these aid the -fanalyzer passes?

For instance:

[[gnu::malloc]] [[gnu::malloc(HeapPage_free, 1)]] [[gnu::returns_nonnull]]
struct HeapPage* HeapPage_alloc();

[[gnu::access(read_write, 1, 3)]]
struct RecordID
HeapPage_insert_record(struct HeapPage* page, const char* record,
                       uint32_t record_length);

That's quite a significant bit of annotation-noise tacked on to the
function, so
I wanted to be sure it's worth the investment!

Thank you =)
Gavin Ray

             reply	other threads:[~2022-11-24  1:49 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-24  1:49 Gavin Ray [this message]
2022-11-25 17:33 ` David Malcolm
2022-11-25 18:55   ` Gavin Ray
2022-11-26 14:09     ` Jonathan Wakely
2022-11-26 15:48       ` Gavin Ray
2022-11-26 17:47         ` Jonathan Wakely
2022-11-26 18:51           ` David Malcolm

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='CAFtvWZNgv_HTMoYBd7=PoXLN-3TP=sN02o55FF2jq+jfxG5cSw@mail.gmail.com' \
    --to=ray.gavin97@gmail.com \
    --cc=gcc@gcc.gnu.org \
    /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).