diff mbox series

libcpp: bump padding size in _cpp_convert_input [PR116458]

Message ID 20240822182508.621-1-amonakov@ispras.ru
State New
Headers show
Series libcpp: bump padding size in _cpp_convert_input [PR116458] | expand

Commit Message

Alexander Monakov Aug. 22, 2024, 6:25 p.m. UTC
The recently introduced search_line_fast_ssse3 raised padding
requirement from 16 to 64, which was adjusted in read_file_guts,
but the corresponding ' + 16' in _cpp_convert_input was overlooked.

libcpp/ChangeLog:

	PR preprocessor/116458
	* charset.cc (_cpp_convert_input): Bump padding to 64 if
	HAVE_SSSE3.
---
 libcpp/charset.cc | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

Comments

Richard Biener Aug. 23, 2024, 10:46 a.m. UTC | #1
On Thu, Aug 22, 2024 at 8:25 PM Alexander Monakov <amonakov@ispras.ru> wrote:
>
> The recently introduced search_line_fast_ssse3 raised padding
> requirement from 16 to 64, which was adjusted in read_file_guts,
> but the corresponding ' + 16' in _cpp_convert_input was overlooked.

OK

> libcpp/ChangeLog:
>
>         PR preprocessor/116458
>         * charset.cc (_cpp_convert_input): Bump padding to 64 if
>         HAVE_SSSE3.
> ---
>  libcpp/charset.cc | 21 ++++++++++++---------
>  1 file changed, 12 insertions(+), 9 deletions(-)
>
> diff --git a/libcpp/charset.cc b/libcpp/charset.cc
> index d58319a500..79072877cb 100644
> --- a/libcpp/charset.cc
> +++ b/libcpp/charset.cc
> @@ -3093,6 +3093,7 @@ _cpp_convert_input (cpp_reader *pfile, const char *input_charset,
>    struct cset_converter input_cset;
>    struct _cpp_strbuf to;
>    unsigned char *buffer;
> +  size_t pad;
>
>    input_cset = init_iconv_desc (pfile, SOURCE_CHARSET, input_charset);
>    if (input_cset.func == convert_no_conversion)
> @@ -3129,16 +3130,18 @@ _cpp_convert_input (cpp_reader *pfile, const char *input_charset,
>         }
>      }
>
> +#ifdef HAVE_SSSE3
> +  pad = 64;
> +#else
> +  pad = 16;
> +#endif
>    /* Resize buffer if we allocated substantially too much, or if we
> -     haven't enough space for the \n-terminator or following
> -     15 bytes of padding (used to quiet warnings from valgrind or
> -     Address Sanitizer, when the optimized lexer accesses aligned
> -     16-byte memory chunks, including the bytes after the malloced,
> -     area, and stops lexing on '\n').  */
> -  if (to.len + 4096 < to.asize || to.len + 16 > to.asize)
> -    to.text = XRESIZEVEC (uchar, to.text, to.len + 16);
> -
> -  memset (to.text + to.len, '\0', 16);
> +     don't have enough space for the following padding, which allows
> +     search_line_fast to use (possibly misaligned) vector loads.  */
> +  if (to.len + 4096 < to.asize || to.len + pad > to.asize)
> +    to.text = XRESIZEVEC (uchar, to.text, to.len + pad);
> +
> +  memset (to.text + to.len, '\0', pad);
>
>    /* If the file is using old-school Mac line endings (\r only),
>       terminate with another \r, not an \n, so that we do not mistake
> --
> 2.46.0
>
diff mbox series

Patch

diff --git a/libcpp/charset.cc b/libcpp/charset.cc
index d58319a500..79072877cb 100644
--- a/libcpp/charset.cc
+++ b/libcpp/charset.cc
@@ -3093,6 +3093,7 @@  _cpp_convert_input (cpp_reader *pfile, const char *input_charset,
   struct cset_converter input_cset;
   struct _cpp_strbuf to;
   unsigned char *buffer;
+  size_t pad;
 
   input_cset = init_iconv_desc (pfile, SOURCE_CHARSET, input_charset);
   if (input_cset.func == convert_no_conversion)
@@ -3129,16 +3130,18 @@  _cpp_convert_input (cpp_reader *pfile, const char *input_charset,
 	}
     }
 
+#ifdef HAVE_SSSE3
+  pad = 64;
+#else
+  pad = 16;
+#endif
   /* Resize buffer if we allocated substantially too much, or if we
-     haven't enough space for the \n-terminator or following
-     15 bytes of padding (used to quiet warnings from valgrind or
-     Address Sanitizer, when the optimized lexer accesses aligned
-     16-byte memory chunks, including the bytes after the malloced,
-     area, and stops lexing on '\n').  */
-  if (to.len + 4096 < to.asize || to.len + 16 > to.asize)
-    to.text = XRESIZEVEC (uchar, to.text, to.len + 16);
-
-  memset (to.text + to.len, '\0', 16);
+     don't have enough space for the following padding, which allows
+     search_line_fast to use (possibly misaligned) vector loads.  */
+  if (to.len + 4096 < to.asize || to.len + pad > to.asize)
+    to.text = XRESIZEVEC (uchar, to.text, to.len + pad);
+
+  memset (to.text + to.len, '\0', pad);
 
   /* If the file is using old-school Mac line endings (\r only),
      terminate with another \r, not an \n, so that we do not mistake