From: John Levon <levon@movementarian.org>
To: smatch@vger.kernel.org, linux-sparse@vger.kernel.org
Cc: yuri.pankov@nexenta.com
Subject: noreturn attribute doesn't work in smatch
Date: Thu, 15 Aug 2019 01:53:28 +0100 [thread overview]
Message-ID: <20190815005328.GA8004@movementarian.org> (raw)
./smatch: a.c:20 main() error: double free of 'str'
given:
```
#include <stdlib.h>
#include <string.h>
__attribute__((__noreturn__)) void
die(void)
{
exit(1);
}
int
main(void)
{
char *str = strdup("test");
if (str != NULL) {
free(str);
die();
}
free(str);
return (0);
}
```
As far as I can figure out, this looks like a sparse problem: an
'inline' or 'extern' specifier in this position gets marked as the
relevant MOD_* flag for the function, but the noreturn doesn't bubble
up in the same way. Some quick lame attempts to add ctx->is_noreturn did
not go well.
I think this might be the underlying issue behind sparse's failing test
validation/function-redecl2.c but I'm not positive.
We can do:
```
#ifdef __CHECKER__
#define SMATCH_NORETURN __attribute__((__noreturn__))
#else
#define SMATCH_NORETURN /* would break gcc otherwise */
#endif
__attribute__((__noreturn__)) void
die(void) SMATCH_NORETURN
{
```
but it's ... unlovely.
Any thoughts?
thanks
john
next reply other threads:[~2019-08-15 0:53 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-15 0:53 John Levon [this message]
2019-08-15 11:12 ` noreturn attribute doesn't work in smatch John Levon
2019-08-22 13:30 ` Dan Carpenter
2019-08-22 13:46 ` John Levon
2019-08-22 15:05 ` Dan Carpenter
2019-08-22 15:29 ` John Levon
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=20190815005328.GA8004@movementarian.org \
--to=levon@movementarian.org \
--cc=linux-sparse@vger.kernel.org \
--cc=smatch@vger.kernel.org \
--cc=yuri.pankov@nexenta.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).