Return-Path: Received: from movementarian.org ([178.79.150.28]:50836 "EHLO movementarian.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727722AbfHOAxa (ORCPT ); Wed, 14 Aug 2019 20:53:30 -0400 Date: Thu, 15 Aug 2019 01:53:28 +0100 From: John Levon Subject: noreturn attribute doesn't work in smatch Message-ID: <20190815005328.GA8004@movementarian.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Sender: smatch-owner@vger.kernel.org List-ID: To: smatch@vger.kernel.org, linux-sparse@vger.kernel.org Cc: yuri.pankov@nexenta.com ./smatch: a.c:20 main() error: double free of 'str' given: ``` #include #include __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