llvm-project/libc/common_libc_tuners.cmake
Michael Jones a3b745818d [libc] add unsafe mode to strlen
The only safe way to implement strlen involves reading the string one
char at a time. It is faster to read in larger blocks, but this leads to
reading beyond the string boundary, which is undefined behavior. This
patch adds an implementation and flag to use this fast but unsafe
version of strlen.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D129808
2022-11-30 16:48:35 -08:00

15 lines
922 B
CMake

# ------------------------------------------------------------------------------
# Common tuning option definitions.
# ------------------------------------------------------------------------------
set(LIBC_COMMON_TUNE_OPTIONS "")
option(LIBC_UNSAFE_STRING_WIDE_READ "Functions searching for the first character in a string such as strlen will read the string as int sized blocks instead of bytes. This relies on undefined behavior and may fail on some systems, but improves performance on long strings." OFF)
if(LIBC_UNSAFE_STRING_WIDE_READ)
if(LLVM_USE_SANITIZER)
message(FATAL_ERROR "LIBC_UNSAFE_STRING_WIDE_READ is set at the same time as a sanitizer. LIBC_UNSAFE_STRING_WIDE_READ causes strlen and memchr to read beyond the end of their target strings, which is undefined behavior caught by sanitizers.")
else()
list(APPEND LIBC_COMMON_TUNE_OPTIONS "-DLIBC_UNSAFE_STRING_WIDE_READ")
endif()
endif()