Pacify GCC 13 -Wanalyzer-out-of-bounds

* src/alloc.c (NEAR_STACK_TOP): Hoist from here ...
* src/thread.h: ... to here.
* src/print.c (print_object): Use NEAR_STACK_TOP instead of raw
buffer address.  This is more natural, and pacifies GCC 13.
This commit is contained in:
Paul Eggert 2023-05-14 18:51:23 -07:00
parent 4fedd5af4c
commit 0c11c2ae71
3 changed files with 10 additions and 10 deletions

View file

@ -5338,15 +5338,6 @@ typedef union
#endif
} stacktop_sentry;
/* Yield an address close enough to the top of the stack that the
garbage collector need not scan above it. Callers should be
declared NO_INLINE. */
#ifdef HAVE___BUILTIN_FRAME_ADDRESS
# define NEAR_STACK_TOP(addr) ((void) (addr), __builtin_frame_address (0))
#else
# define NEAR_STACK_TOP(addr) (addr)
#endif
/* Set *P to the address of the top of the stack. This must be a
macro, not a function, so that it is executed in the caller's
environment. It is not inside a do-while so that its storage

View file

@ -2204,7 +2204,7 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag)
max ((sizeof " with data 0x"
+ (sizeof (uintmax_t) * CHAR_BIT + 4 - 1) / 4),
40)))];
current_thread->stack_top = buf;
current_thread->stack_top = NEAR_STACK_TOP (buf);
print_obj:
maybe_quit ();

View file

@ -33,6 +33,15 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
#include "sysselect.h" /* FIXME */
#include "systhread.h"
/* Yield an address close enough to the top of the stack that the
garbage collector need not scan above it. Callers should be
declared NO_INLINE. */
#ifdef HAVE___BUILTIN_FRAME_ADDRESS
# define NEAR_STACK_TOP(addr) ((void) (addr), __builtin_frame_address (0))
#else
# define NEAR_STACK_TOP(addr) (addr)
#endif
INLINE_HEADER_BEGIN
/* Byte-code interpreter thread state. */