From 08ce2613c89fa8ed84f478a6714af81bd44c89f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonin=20D=C3=A9cimo?= Date: Fri, 1 Mar 2019 00:25:05 +0100 Subject: [PATCH] Use clang analyzer_noreturn on assertion handler If the assertion handler is not tagged, a lot of false positives are generated by clang static analyzer. > The Clang-specific 'analyzer_noreturn' attribute is almost identical > to 'noreturn' except that it is ignored by the compiler for the > purposes of code generation. > > This attribute is useful for annotating assertion handlers that > actually can return, but for the purpose of using the analyzer we > want to pretend that such functions do not return. https://clang-analyzer.llvm.org/annotations.html#custom_assertions --- include/log.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/include/log.h b/include/log.h index adf431ab6..efafdd44d 100644 --- a/include/log.h +++ b/include/log.h @@ -20,6 +20,15 @@ typedef enum { #define ATTRIB_PRINTF(start, end) #endif +#if !defined(CLANG_ANALYZER_NORETURN) && defined(__has_feature) +#if __has_feature(attribute_analyzer_noreturn) +#define CLANG_ANALYZER_NORETURN __attribute__((analyzer_noreturn)) +#endif +#endif +#ifndef CLANG_ANALYZER_NORETURN +#define CLANG_ANALYZER_NORETURN +#endif + void error_handler(int sig); typedef void (*terminate_callback_t)(int exit_code); @@ -31,7 +40,7 @@ void sway_log_init(sway_log_importance_t verbosity, terminate_callback_t termina void _sway_log(sway_log_importance_t verbosity, const char *format, ...) ATTRIB_PRINTF(2, 3); void _sway_vlog(sway_log_importance_t verbosity, const char *format, va_list args) ATTRIB_PRINTF(2, 0); void _sway_abort(const char *filename, ...) ATTRIB_PRINTF(1, 2); -bool _sway_assert(bool condition, const char* format, ...) ATTRIB_PRINTF(2, 3); +bool _sway_assert(bool condition, const char* format, ...) ATTRIB_PRINTF(2, 3) CLANG_ANALYZER_NORETURN; // TODO: get meson to precompute this, for better reproducibility/less overhead const char *_sway_strip_path(const char *filepath);