public inbox for smatch@vger.kernel.org
 help / color / mirror / Atom feed
* noreturn attribute doesn't work in smatch
@ 2019-08-15  0:53 John Levon
  2019-08-15 11:12 ` John Levon
  0 siblings, 1 reply; 6+ messages in thread
From: John Levon @ 2019-08-15  0:53 UTC (permalink / raw)
  To: smatch, linux-sparse; +Cc: yuri.pankov


./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

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-08-22 15:29 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-08-15  0:53 noreturn attribute doesn't work in smatch John Levon
2019-08-15 11:12 ` 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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox