From ad4aa2a6f947967df883c18620517c53e67e19fc Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Mon, 31 Jan 2022 08:42:07 -0800 Subject: [PATCH 01/43] expr: lint cleanup, and introducing main_exit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This introduces a new macro main_exit, which is useful for pacifying gcc -fsanitizer=lint and in some cases means we can remove some ‘IF_LINT’ and ‘ifdef lint’ code. * src/expr.c (main): Use main_exit, not return. (docolon): Omit an IF_LINT that GCC no longer needs. * src/system.h (main_exit): New macro. --- src/expr.c | 4 ++-- src/system.h | 14 +++++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/expr.c b/src/expr.c index b8f216243..d0cffe3f7 100644 --- a/src/expr.c +++ b/src/expr.c @@ -357,7 +357,7 @@ main (int argc, char **argv) printv (v); - return null (v); + main_exit (null (v)); } /* Return a VALUE for I. */ @@ -585,7 +585,7 @@ trace (fxn) static VALUE * docolon (VALUE *sv, VALUE *pv) { - VALUE *v IF_LINT ( = NULL); + VALUE *v; char const *errmsg; struct re_pattern_buffer re_buffer; char fastmap[UCHAR_MAX + 1]; diff --git a/src/system.h b/src/system.h index 9f10579dc..16fcc38e7 100644 --- a/src/system.h +++ b/src/system.h @@ -465,13 +465,25 @@ enum # define PID_T_MAX TYPE_MAXIMUM (pid_t) #endif -/* Use this to suppress gcc's '...may be used before initialized' warnings. */ +/* Use this to suppress gcc warnings. */ #ifdef lint # define IF_LINT(Code) Code #else # define IF_LINT(Code) /* empty */ #endif +/* main_exit should be called only from the main function. It is + equivalent to 'exit'. When checking for lint it calls 'exit', to + pacify gcc -fsanitize=lint which would otherwise have false alarms + for pointers in the main function's activation record. Otherwise + it simply returns from 'main'; this used to be what gcc's static + checking preferred and may yet be again. */ +#ifdef lint +# define main_exit(status) exit (status) +#else +# define main_exit(status) return status +#endif + #ifdef __GNUC__ # define LIKELY(cond) __builtin_expect ((cond), 1) # define UNLIKELY(cond) __builtin_expect ((cond), 0) -- 2.32.0