From ce3c1ea83e18e6b8a02013bbdae4b4c183e39997 Mon Sep 17 00:00:00 2001 From: Andrea Corallo Date: Sun, 31 May 2020 20:28:31 +0100 Subject: [PATCH] * Optimize 'emit_static_object' for load-time * src/comp.c (emit_static_object): Use a chunck size of 200 bytes on bugged GCCs and a longer one (1024) in sane ones. Rename str in buff to disambiguate and prefer xmalloc to a VLA given the buffer is not that small. --- src/comp.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/comp.c b/src/comp.c index c9d3fd04070..2d904c91548 100644 --- a/src/comp.c +++ b/src/comp.c @@ -2441,27 +2441,30 @@ emit_static_object (const char *name, Lisp_Object obj) gcc_jit_context_new_rvalue_from_int (comp.ctxt, comp.int_type, 0)), NULL)); + /* We can't use always string literals longer that 200 bytes because + they cause a crash in pre GCC 10 libgccjit. + . + + Adjust if possible to reduce the number of function calls. */ + size_t chunck_size = NILP (Fcomp_libgccjit_version ()) ? 200 : 1024; + char *buff = xmalloc (chunck_size); for (ptrdiff_t i = 0; i < len;) { - /* We can't use string literals longer that 200 bytes because - they cause a crash in older versions of gccjit. - https://gcc.gnu.org/ml/jit/2019-q3/msg00013.html. */ - char str[200]; - strncpy (str, p, 200); - str[199] = 0; - uintptr_t l = strlen (str); + strncpy (buff, p, chunck_size); + buff[chunck_size - 1] = 0; + uintptr_t l = strlen (buff); if (l != 0) { p += l; i += l; - gcc_jit_rvalue *args[3] - = {gcc_jit_lvalue_as_rvalue (ptrvar), - gcc_jit_context_new_string_literal (comp.ctxt, str), - gcc_jit_context_new_rvalue_from_int (comp.ctxt, - comp.size_t_type, - l)}; + gcc_jit_rvalue *args[] = + { gcc_jit_lvalue_as_rvalue (ptrvar), + gcc_jit_context_new_string_literal (comp.ctxt, buff), + gcc_jit_context_new_rvalue_from_int (comp.ctxt, + comp.size_t_type, + l) }; gcc_jit_block_add_eval (block, NULL, gcc_jit_context_new_call (comp.ctxt, NULL, @@ -2496,6 +2499,7 @@ emit_static_object (const char *name, Lisp_Object obj) NULL)); } } + xfree (buff); gcc_jit_block_add_assignment ( block, -- 2.39.5