diff --git a/libc/cmake/modules/LLVMLibCObjectRules.cmake b/libc/cmake/modules/LLVMLibCObjectRules.cmake --- a/libc/cmake/modules/LLVMLibCObjectRules.cmake +++ b/libc/cmake/modules/LLVMLibCObjectRules.cmake @@ -108,7 +108,7 @@ target_compile_options(${gpu_target_name} PRIVATE ${compile_options}) target_include_directories(${gpu_target_name} PRIVATE ${include_dirs}) add_dependencies(${gpu_target_name} ${ADD_GPU_ENTRYPOINT_OBJ_DEPENDS}) - target_compile_definitions(${gpu_target_name} PRIVATE LLVM_LIBC_PUBLIC_PACKAGING) + target_compile_definitions(${gpu_target_name} PRIVATE LIBC_COPT_PUBLIC_PACKAGING) # Append this target to a list of images to package into a single binary. set(input_file $) @@ -146,7 +146,7 @@ "${CMAKE_CURRENT_BINARY_DIR}/${stub_filename}" ) target_compile_options(${fq_target_name} BEFORE PRIVATE ${common_compile_options} - -DLLVM_LIBC_PUBLIC_PACKAGING + -DLIBC_COPT_PUBLIC_PACKAGING -nostdlib -Xclang -fembed-offload-object=${packaged_output_name}) target_include_directories(${fq_target_name} PRIVATE ${include_dirs}) add_dependencies(${fq_target_name} ${full_deps_list} ${packaged_target_name}) @@ -521,7 +521,7 @@ ${ADD_ENTRYPOINT_OBJ_SRCS} ${ADD_ENTRYPOINT_OBJ_HDRS} ) - target_compile_options(${fq_target_name} BEFORE PRIVATE ${common_compile_options} -DLLVM_LIBC_PUBLIC_PACKAGING) + target_compile_options(${fq_target_name} BEFORE PRIVATE ${common_compile_options} -DLIBC_COPT_PUBLIC_PACKAGING) target_include_directories(${fq_target_name} PRIVATE ${include_dirs}) add_dependencies(${fq_target_name} ${full_deps_list}) diff --git a/libc/common_libc_tuners.cmake b/libc/common_libc_tuners.cmake --- a/libc/common_libc_tuners.cmake +++ b/libc/common_libc_tuners.cmake @@ -4,11 +4,11 @@ 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) +option(LIBC_COPT_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_COPT_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.") + message(FATAL_ERROR "LIBC_COPT_UNSAFE_STRING_WIDE_READ is set at the same time as a sanitizer. LIBC_COPT_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") + list(APPEND LIBC_COMMON_TUNE_OPTIONS "-DLIBC_COPT_UNSAFE_STRING_WIDE_READ") endif() endif() diff --git a/libc/fuzzing/stdlib/CMakeLists.txt b/libc/fuzzing/stdlib/CMakeLists.txt --- a/libc/fuzzing/stdlib/CMakeLists.txt +++ b/libc/fuzzing/stdlib/CMakeLists.txt @@ -58,7 +58,7 @@ libc.src.stdlib.strtoul libc.src.stdlib.strtoull COMPILE_OPTIONS - -DLLVM_LIBC_FUZZ_ATOI_CLEANER_INPUT + -DLIBC_COPT_FUZZ_ATOI_CLEANER_INPUT ) add_libc_fuzzer( diff --git a/libc/fuzzing/stdlib/strtointeger_differential_fuzz.cpp b/libc/fuzzing/stdlib/strtointeger_differential_fuzz.cpp --- a/libc/fuzzing/stdlib/strtointeger_differential_fuzz.cpp +++ b/libc/fuzzing/stdlib/strtointeger_differential_fuzz.cpp @@ -50,7 +50,7 @@ size_t i; for (i = 0; i < size; ++i) { -#ifdef LLVM_LIBC_FUZZ_ATOI_CLEANER_INPUT +#ifdef LIBC_COPT_FUZZ_ATOI_CLEANER_INPUT container[i] = VALID_CHARS[data[i] % sizeof(VALID_CHARS)]; #else container[i] = data[i]; diff --git a/libc/src/__support/common.h b/libc/src/__support/common.h --- a/libc/src/__support/common.h +++ b/libc/src/__support/common.h @@ -17,13 +17,13 @@ #endif // GPU targets do not support aliasing. -#if defined(LLVM_LIBC_PUBLIC_PACKAGING) && defined(LIBC_TARGET_ARCH_IS_GPU) +#if defined(LIBC_COPT_PUBLIC_PACKAGING) && defined(LIBC_TARGET_ARCH_IS_GPU) #define LLVM_LIBC_FUNCTION(type, name, arglist) \ LLVM_LIBC_FUNCTION_ATTR decltype(__llvm_libc::name) \ __##name##_impl__ __asm__(#name); \ type __##name##_impl__ arglist // MacOS needs to be excluded because it does not support aliasing. -#elif defined(LLVM_LIBC_PUBLIC_PACKAGING) && (!defined(__APPLE__)) +#elif defined(LIBC_COPT_PUBLIC_PACKAGING) && (!defined(__APPLE__)) #define LLVM_LIBC_FUNCTION(type, name, arglist) \ LLVM_LIBC_FUNCTION_ATTR decltype(__llvm_libc::name) \ __##name##_impl__ __asm__(#name); \ diff --git a/libc/src/__support/str_to_float.h b/libc/src/__support/str_to_float.h --- a/libc/src/__support/str_to_float.h +++ b/libc/src/__support/str_to_float.h @@ -616,15 +616,15 @@ return; } -#ifndef LLVM_LIBC_DISABLE_CLINGER_FAST_PATH +#ifndef LIBC_COPT_DISABLE_CLINGER_FAST_PATH if (!truncated) { if (clinger_fast_path(mantissa, exp10, outputMantissa, outputExp2)) { return; } } -#endif // LLVM_LIBC_DISABLE_CLINGER_FAST_PATH +#endif // LIBC_COPT_DISABLE_CLINGER_FAST_PATH -#ifndef LLVM_LIBC_DISABLE_EISEL_LEMIRE +#ifndef LIBC_COPT_DISABLE_EISEL_LEMIRE // Try Eisel-Lemire if (eisel_lemire(mantissa, exp10, outputMantissa, outputExp2)) { if (!truncated) { @@ -641,11 +641,11 @@ } } } -#endif // LLVM_LIBC_DISABLE_EISEL_LEMIRE +#endif // LIBC_COPT_DISABLE_EISEL_LEMIRE -#ifndef LLVM_LIBC_DISABLE_SIMPLE_DECIMAL_CONVERSION +#ifndef LIBC_COPT_DISABLE_SIMPLE_DECIMAL_CONVERSION simple_decimal_conversion(numStart, outputMantissa, outputExp2); -#endif // LLVM_LIBC_DISABLE_SIMPLE_DECIMAL_CONVERSION +#endif // LIBC_COPT_DISABLE_SIMPLE_DECIMAL_CONVERSION return; } diff --git a/libc/src/stdio/printf_core/converter.cpp b/libc/src/stdio/printf_core/converter.cpp --- a/libc/src/stdio/printf_core/converter.cpp +++ b/libc/src/stdio/printf_core/converter.cpp @@ -13,10 +13,10 @@ // This option allows for replacing all of the conversion functions with custom // replacements. This allows conversions to be replaced at compile time. -#ifndef LLVM_LIBC_PRINTF_CONV_ATLAS +#ifndef LIBC_COPT_PRINTF_CONV_ATLAS #include "src/stdio/printf_core/converter_atlas.h" #else -#include LLVM_LIBC_PRINTF_CONV_ATLAS +#include LIBC_COPT_PRINTF_CONV_ATLAS #endif #include @@ -42,7 +42,7 @@ case 'x': case 'X': return convert_int(writer, to_conv); -#ifndef LLVM_LIBC_PRINTF_DISABLE_FLOAT +#ifndef LIBC_COPT_PRINTF_DISABLE_FLOAT case 'f': case 'F': return convert_float_decimal(writer, to_conv); @@ -55,11 +55,11 @@ case 'g': case 'G': return convert_float_dec_auto(writer, to_conv); -#endif // LLVM_LIBC_PRINTF_DISABLE_FLOAT -#ifndef LLVM_LIBC_PRINTF_DISABLE_WRITE_INT +#endif // LIBC_COPT_PRINTF_DISABLE_FLOAT +#ifndef LIBC_COPT_PRINTF_DISABLE_WRITE_INT case 'n': return convert_write_int(writer, to_conv); -#endif // LLVM_LIBC_PRINTF_DISABLE_WRITE_INT +#endif // LIBC_COPT_PRINTF_DISABLE_WRITE_INT case 'p': return convert_pointer(writer, to_conv); default: diff --git a/libc/src/stdio/printf_core/converter_atlas.h b/libc/src/stdio/printf_core/converter_atlas.h --- a/libc/src/stdio/printf_core/converter_atlas.h +++ b/libc/src/stdio/printf_core/converter_atlas.h @@ -22,18 +22,18 @@ // defines convert_int #include "src/stdio/printf_core/int_converter.h" -#ifndef LLVM_LIBC_PRINTF_DISABLE_FLOAT +#ifndef LIBC_COPT_PRINTF_DISABLE_FLOAT // defines convert_float_decimal // defines convert_float_dec_exp // defines convert_float_dec_auto #include "src/stdio/printf_core/float_dec_converter.h" // defines convert_float_hex_exp #include "src/stdio/printf_core/float_hex_converter.h" -#endif // LLVM_LIBC_PRINTF_DISABLE_FLOAT +#endif // LIBC_COPT_PRINTF_DISABLE_FLOAT -#ifndef LLVM_LIBC_PRINTF_DISABLE_WRITE_INT +#ifndef LIBC_COPT_PRINTF_DISABLE_WRITE_INT #include "src/stdio/printf_core/write_int_converter.h" -#endif // LLVM_LIBC_PRINTF_DISABLE_WRITE_INT +#endif // LIBC_COPT_PRINTF_DISABLE_WRITE_INT // defines convert_pointer #include "src/stdio/printf_core/ptr_converter.h" diff --git a/libc/src/stdio/printf_core/parser.h b/libc/src/stdio/printf_core/parser.h --- a/libc/src/stdio/printf_core/parser.h +++ b/libc/src/stdio/printf_core/parser.h @@ -26,7 +26,7 @@ size_t cur_pos = 0; internal::ArgList args_cur; -#ifndef LLVM_LIBC_PRINTF_DISABLE_INDEX_MODE +#ifndef LIBC_COPT_PRINTF_DISABLE_INDEX_MODE // args_start stores the start of the va_args, which is allows getting the // value of arguments that have already been passed. args_index is tracked so // that we know which argument args_cur is on. @@ -34,7 +34,7 @@ size_t args_index = 1; // Defined in printf_config.h - static constexpr size_t DESC_ARR_LEN = LLVM_LIBC_PRINTF_INDEX_ARR_LEN; + static constexpr size_t DESC_ARR_LEN = LIBC_COPT_PRINTF_INDEX_ARR_LEN; // desc_arr stores the sizes of the variables in the ArgList. This is used in // index mode to reduce repeated string parsing. The sizes are stored as @@ -45,16 +45,16 @@ // TODO: Look into object stores for optimization. -#endif // LLVM_LIBC_PRINTF_DISABLE_INDEX_MODE +#endif // LIBC_COPT_PRINTF_DISABLE_INDEX_MODE public: -#ifndef LLVM_LIBC_PRINTF_DISABLE_INDEX_MODE +#ifndef LIBC_COPT_PRINTF_DISABLE_INDEX_MODE LIBC_INLINE Parser(const char *__restrict new_str, internal::ArgList &args) : str(new_str), args_cur(args), args_start(args) {} #else LIBC_INLINE Parser(const char *__restrict new_str, internal::ArgList &args) : str(new_str), args_cur(args) {} -#endif // LLVM_LIBC_PRINTF_DISABLE_INDEX_MODE +#endif // LIBC_COPT_PRINTF_DISABLE_INDEX_MODE // get_next_section will parse the format string until it has a fully // specified format section. This can either be a raw format section with no @@ -84,7 +84,7 @@ // INDEX MODE ONLY FUNCTIONS AFTER HERE: //---------------------------------------------------- -#ifndef LLVM_LIBC_PRINTF_DISABLE_INDEX_MODE +#ifndef LIBC_COPT_PRINTF_DISABLE_INDEX_MODE // parse_index parses the index of a value inside a format string. It // assumes that str[*local_pos] points to character after a '%' or '*', and @@ -124,7 +124,7 @@ // modify cur_pos. TypeDesc get_type_desc(size_t index); -#endif // LLVM_LIBC_PRINTF_DISABLE_INDEX_MODE +#endif // LIBC_COPT_PRINTF_DISABLE_INDEX_MODE }; } // namespace printf_core diff --git a/libc/src/stdio/printf_core/parser.cpp b/libc/src/stdio/printf_core/parser.cpp --- a/libc/src/stdio/printf_core/parser.cpp +++ b/libc/src/stdio/printf_core/parser.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -// #define LLVM_LIBC_PRINTF_DISABLE_INDEX_MODE 1 // This will be a compile flag. +// #define LIBC_COPT_PRINTF_DISABLE_INDEX_MODE 1 // This will be a compile flag. #include "parser.h" @@ -22,11 +22,11 @@ namespace __llvm_libc { namespace printf_core { -#ifndef LLVM_LIBC_PRINTF_DISABLE_INDEX_MODE +#ifndef LIBC_COPT_PRINTF_DISABLE_INDEX_MODE #define GET_ARG_VAL_SIMPLEST(arg_type, index) get_arg_value(index) #else #define GET_ARG_VAL_SIMPLEST(arg_type, _) get_next_arg_value() -#endif // LLVM_LIBC_PRINTF_DISABLE_INDEX_MODE +#endif // LIBC_COPT_PRINTF_DISABLE_INDEX_MODE FormatSection Parser::get_next_section() { FormatSection section; @@ -38,9 +38,9 @@ ++cur_pos; [[maybe_unused]] size_t conv_index = 0; -#ifndef LLVM_LIBC_PRINTF_DISABLE_INDEX_MODE +#ifndef LIBC_COPT_PRINTF_DISABLE_INDEX_MODE conv_index = parse_index(&cur_pos); -#endif // LLVM_LIBC_PRINTF_DISABLE_INDEX_MODE +#endif // LIBC_COPT_PRINTF_DISABLE_INDEX_MODE section.flags = parse_flags(&cur_pos); @@ -120,7 +120,7 @@ break; } break; -#ifndef LLVM_LIBC_PRINTF_DISABLE_FLOAT +#ifndef LIBC_COPT_PRINTF_DISABLE_FLOAT case ('f'): case ('F'): case ('e'): @@ -137,10 +137,10 @@ cpp::bit_cast::UIntType>( GET_ARG_VAL_SIMPLEST(long double, conv_index)); break; -#endif // LLVM_LIBC_PRINTF_DISABLE_FLOAT -#ifndef LLVM_LIBC_PRINTF_DISABLE_WRITE_INT +#endif // LIBC_COPT_PRINTF_DISABLE_FLOAT +#ifndef LIBC_COPT_PRINTF_DISABLE_WRITE_INT case ('n'): -#endif // LLVM_LIBC_PRINTF_DISABLE_WRITE_INT +#endif // LIBC_COPT_PRINTF_DISABLE_WRITE_INT case ('p'): case ('s'): section.conv_val_ptr = GET_ARG_VAL_SIMPLEST(void *, conv_index); @@ -233,7 +233,7 @@ // INDEX MODE ONLY FUNCTIONS AFTER HERE: //---------------------------------------------------- -#ifndef LLVM_LIBC_PRINTF_DISABLE_INDEX_MODE +#ifndef LIBC_COPT_PRINTF_DISABLE_INDEX_MODE size_t Parser::parse_index(size_t *local_pos) { if (internal::isdigit(str[*local_pos])) { @@ -343,7 +343,7 @@ break; } break; -#ifndef LLVM_LIBC_PRINTF_DISABLE_FLOAT +#ifndef LIBC_COPT_PRINTF_DISABLE_FLOAT case ('f'): case ('F'): case ('e'): @@ -357,10 +357,10 @@ else conv_size = type_desc_from_type(); break; -#endif // LLVM_LIBC_PRINTF_DISABLE_FLOAT -#ifndef LLVM_LIBC_PRINTF_DISABLE_WRITE_INT +#endif // LIBC_COPT_PRINTF_DISABLE_FLOAT +#ifndef LIBC_COPT_PRINTF_DISABLE_WRITE_INT case ('n'): -#endif // LLVM_LIBC_PRINTF_DISABLE_WRITE_INT +#endif // LIBC_COPT_PRINTF_DISABLE_WRITE_INT case ('p'): case ('s'): conv_size = type_desc_from_type(); @@ -403,13 +403,13 @@ args_cur.next_var(); else if (cur_type_desc == type_desc_from_type()) args_cur.next_var(); -#ifndef LLVM_LIBC_PRINTF_DISABLE_FLOAT +#ifndef LIBC_COPT_PRINTF_DISABLE_FLOAT // Floating point numbers are stored separately from the other arguments. else if (cur_type_desc == type_desc_from_type()) args_cur.next_var(); else if (cur_type_desc == type_desc_from_type()) args_cur.next_var(); -#endif // LLVM_LIBC_PRINTF_DISABLE_FLOAT +#endif // LIBC_COPT_PRINTF_DISABLE_FLOAT // pointers may be stored separately from normal values. else if (cur_type_desc == type_desc_from_type()) args_cur.next_var(); @@ -420,7 +420,7 @@ } } -#endif // LLVM_LIBC_PRINTF_DISABLE_INDEX_MODE +#endif // LIBC_COPT_PRINTF_DISABLE_INDEX_MODE } // namespace printf_core } // namespace __llvm_libc diff --git a/libc/src/stdio/printf_core/printf_config.h b/libc/src/stdio/printf_core/printf_config.h --- a/libc/src/stdio/printf_core/printf_config.h +++ b/libc/src/stdio/printf_core/printf_config.h @@ -25,8 +25,8 @@ // the index array is 10, then when the 20th index is requested the first 10 // types can be found immediately, and then the format string must be parsed 10 // times to find the types of the next 10 arguments. -#ifndef LLVM_LIBC_PRINTF_INDEX_ARR_LEN -#define LLVM_LIBC_PRINTF_INDEX_ARR_LEN 128 +#ifndef LIBC_COPT_PRINTF_INDEX_ARR_LEN +#define LIBC_COPT_PRINTF_INDEX_ARR_LEN 128 #endif // TODO(michaelrj): Move the other printf configuration options into this file. diff --git a/libc/src/stdio/scanf_core/converter.cpp b/libc/src/stdio/scanf_core/converter.cpp --- a/libc/src/stdio/scanf_core/converter.cpp +++ b/libc/src/stdio/scanf_core/converter.cpp @@ -12,9 +12,9 @@ #include "src/stdio/scanf_core/core_structs.h" #include "src/stdio/scanf_core/reader.h" -#ifndef LLVM_LIBC_SCANF_DISABLE_FLOAT +#ifndef LIBC_COPT_SCANF_DISABLE_FLOAT #include "src/stdio/scanf_core/float_converter.h" -#endif // LLVM_LIBC_SCANF_DISABLE_FLOAT +#endif // LIBC_COPT_SCANF_DISABLE_FLOAT #include "src/stdio/scanf_core/current_pos_converter.h" #include "src/stdio/scanf_core/int_converter.h" #include "src/stdio/scanf_core/ptr_converter.h" @@ -48,7 +48,7 @@ if (ret_val != READ_OK) return ret_val; return convert_int(reader, to_conv); -#ifndef LLVM_LIBC_SCANF_DISABLE_FLOAT +#ifndef LIBC_COPT_SCANF_DISABLE_FLOAT case 'f': case 'F': case 'e': @@ -61,7 +61,7 @@ if (ret_val != READ_OK) return ret_val; return convert_float(reader, to_conv); -#endif // LLVM_LIBC_SCANF_DISABLE_FLOAT +#endif // LIBC_COPT_SCANF_DISABLE_FLOAT case 'n': return convert_current_pos(reader, to_conv); case 'p': diff --git a/libc/src/stdio/scanf_core/parser.h b/libc/src/stdio/scanf_core/parser.h --- a/libc/src/stdio/scanf_core/parser.h +++ b/libc/src/stdio/scanf_core/parser.h @@ -25,22 +25,22 @@ size_t cur_pos = 0; internal::ArgList args_cur; -#ifndef LLVM_LIBC_SCANF_DISABLE_INDEX_MODE +#ifndef LIBC_COPT_SCANF_DISABLE_INDEX_MODE // args_start stores the start of the va_args, which is used when a previous // argument is needed. In that case, we have to read the arguments from the // beginning since they don't support reading backwards. internal::ArgList args_start; size_t args_index = 1; -#endif // LLVM_LIBC_SCANF_DISABLE_INDEX_MODE +#endif // LIBC_COPT_SCANF_DISABLE_INDEX_MODE public: -#ifndef LLVM_LIBC_SCANF_DISABLE_INDEX_MODE +#ifndef LIBC_COPT_SCANF_DISABLE_INDEX_MODE LIBC_INLINE Parser(const char *__restrict new_str, internal::ArgList &args) : str(new_str), args_cur(args), args_start(args) {} #else LIBC_INLINE Parser(const char *__restrict new_str, internal::ArgList &args) : str(new_str), args_cur(args) {} -#endif // LLVM_LIBC_SCANF_DISABLE_INDEX_MODE +#endif // LIBC_COPT_SCANF_DISABLE_INDEX_MODE // get_next_section will parse the format string until it has a fully // specified format section. This can either be a raw format section with no @@ -64,7 +64,7 @@ // INDEX MODE ONLY FUNCTIONS AFTER HERE: //---------------------------------------------------- -#ifndef LLVM_LIBC_SCANF_DISABLE_INDEX_MODE +#ifndef LIBC_COPT_SCANF_DISABLE_INDEX_MODE // parse_index parses the index of a value inside a format string. It // assumes that str[*local_pos] points to character after a '%' or '*', and @@ -91,7 +91,7 @@ // case an O(n^2) operation. void args_to_index(size_t index); -#endif // LLVM_LIBC_SCANF_DISABLE_INDEX_MODE +#endif // LIBC_COPT_SCANF_DISABLE_INDEX_MODE }; } // namespace scanf_core diff --git a/libc/src/stdio/scanf_core/parser.cpp b/libc/src/stdio/scanf_core/parser.cpp --- a/libc/src/stdio/scanf_core/parser.cpp +++ b/libc/src/stdio/scanf_core/parser.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -// #define LLVM_LIBC_SCANF_DISABLE_INDEX_MODE 1 // This will be a compile flag. +// #define LIBC_COPT_SCANF_DISABLE_INDEX_MODE 1 // This will be a compile flag. #include "src/stdio/scanf_core/parser.h" @@ -22,11 +22,11 @@ namespace __llvm_libc { namespace scanf_core { -#ifndef LLVM_LIBC_SCANF_DISABLE_INDEX_MODE +#ifndef LIBC_COPT_SCANF_DISABLE_INDEX_MODE #define GET_ARG_VAL_SIMPLEST(arg_type, index) get_arg_value(index) #else #define GET_ARG_VAL_SIMPLEST(arg_type, _) get_next_arg_value() -#endif // LLVM_LIBC_SCANF_DISABLE_INDEX_MODE +#endif // LIBC_COPT_SCANF_DISABLE_INDEX_MODE FormatSection Parser::get_next_section() { FormatSection section; @@ -38,9 +38,9 @@ ++cur_pos; [[maybe_unused]] size_t conv_index = 0; -#ifndef LLVM_LIBC_SCANF_DISABLE_INDEX_MODE +#ifndef LIBC_COPT_SCANF_DISABLE_INDEX_MODE conv_index = parse_index(&cur_pos); -#endif // LLVM_LIBC_SCANF_DISABLE_INDEX_MODE +#endif // LIBC_COPT_SCANF_DISABLE_INDEX_MODE if (str[cur_pos] == '*') { ++cur_pos; @@ -191,7 +191,7 @@ // INDEX MODE ONLY FUNCTIONS AFTER HERE: //---------------------------------------------------- -#ifndef LLVM_LIBC_SCANF_DISABLE_INDEX_MODE +#ifndef LIBC_COPT_SCANF_DISABLE_INDEX_MODE size_t Parser::parse_index(size_t *local_pos) { if (internal::isdigit(str[*local_pos])) { @@ -219,7 +219,7 @@ } } -#endif // LLVM_LIBC_SCANF_DISABLE_INDEX_MODE +#endif // LIBC_COPT_SCANF_DISABLE_INDEX_MODE } // namespace scanf_core } // namespace __llvm_libc diff --git a/libc/src/stdio/scanf_core/scanf_config.h b/libc/src/stdio/scanf_core/scanf_config.h --- a/libc/src/stdio/scanf_core/scanf_config.h +++ b/libc/src/stdio/scanf_core/scanf_config.h @@ -14,11 +14,11 @@ // This flag disables all functionality relating to floating point numbers. This // can be useful for embedded systems or other situations where binary size is // important. -// #define LLVM_LIBC_SCANF_DISABLE_FLOAT +// #define LIBC_COPT_SCANF_DISABLE_FLOAT // This flag disables index mode, a posix extension often used for // internationalization of format strings. Supporting it takes up additional // memory and parsing time, so it can be disabled if it's not used. -// #define LLVM_LIBC_SCANF_DISABLE_INDEX_MODE +// #define LIBC_COPT_SCANF_DISABLE_INDEX_MODE #endif // LLVM_LIBC_SRC_STDIO_SCANF_CORE_SCANF_CONFIG_H diff --git a/libc/src/stdlib/atexit.cpp b/libc/src/stdlib/atexit.cpp --- a/libc/src/stdlib/atexit.cpp +++ b/libc/src/stdlib/atexit.cpp @@ -28,7 +28,7 @@ constexpr AtExitUnit(AtExitCallback *c, void *p) : callback(c), payload(p) {} }; -#ifdef LLVM_LIBC_PUBLIC_PACKAGING +#ifdef LIBC_COPT_PUBLIC_PACKAGING using ExitCallbackList = cpp::ReverseOrderBlockStore; #else // BlockStore uses dynamic memory allocation. To avoid dynamic memory @@ -40,7 +40,7 @@ // deps also (some of which are not yet available in LLVM libc) into the // integration tests. using ExitCallbackList = FixedVector; -#endif // LLVM_LIBC_PUBLIC_PACKAGING +#endif // LIBC_COPT_PUBLIC_PACKAGING constinit ExitCallbackList exit_callbacks; diff --git a/libc/src/string/memory_utils/memcpy_implementations.h b/libc/src/string/memory_utils/memcpy_implementations.h --- a/libc/src/string/memory_utils/memcpy_implementations.h +++ b/libc/src/string/memory_utils/memcpy_implementations.h @@ -66,16 +66,20 @@ CPtr __restrict src, size_t count) { // Whether to use rep;movsb exclusively, not at all, or only above a certain // threshold. -#ifndef LLVM_LIBC_MEMCPY_X86_USE_REPMOVSB_FROM_SIZE -#define LLVM_LIBC_MEMCPY_X86_USE_REPMOVSB_FROM_SIZE -1 +#ifndef LIBC_COPT_MEMCPY_X86_USE_REPMOVSB_FROM_SIZE +#define LIBC_COPT_MEMCPY_X86_USE_REPMOVSB_FROM_SIZE -1 #endif #ifdef LLVM_LIBC_MEMCPY_X86_USE_ONLY_REPMOVSB -#error LLVM_LIBC_MEMCPY_X86_USE_ONLY_REPMOVSB is deprecated use LLVM_LIBC_MEMCPY_X86_USE_REPMOVSB_FROM_SIZE=0 instead. +#error LLVM_LIBC_MEMCPY_X86_USE_ONLY_REPMOVSB is deprecated use LIBC_COPT_MEMCPY_X86_USE_REPMOVSB_FROM_SIZE=0 instead. #endif // LLVM_LIBC_MEMCPY_X86_USE_ONLY_REPMOVSB +#ifdef LLVM_LIBC_MEMCPY_X86_USE_REPMOVSB_FROM_SIZE +#error LLVM_LIBC_MEMCPY_X86_USE_REPMOVSB_FROM_SIZE is deprecated use LIBC_COPT_MEMCPY_X86_USE_REPMOVSB_FROM_SIZE=0 instead. +#endif // LLVM_LIBC_MEMCPY_X86_USE_REPMOVSB_FROM_SIZE + static constexpr size_t kRepMovsbThreshold = - LLVM_LIBC_MEMCPY_X86_USE_REPMOVSB_FROM_SIZE; + LIBC_COPT_MEMCPY_X86_USE_REPMOVSB_FROM_SIZE; if constexpr (kRepMovsbThreshold == 0) { return x86::Memcpy::repmovsb(dst, src, count); } else if constexpr (kRepMovsbThreshold == size_t(-1)) { diff --git a/libc/src/string/string_utils.h b/libc/src/string/string_utils.h --- a/libc/src/string/string_utils.h +++ b/libc/src/string/string_utils.h @@ -88,7 +88,7 @@ // Returns the length of a string, denoted by the first occurrence // of a null terminator. LIBC_INLINE size_t string_length(const char *src) { -#ifdef LIBC_UNSAFE_STRING_WIDE_READ +#ifdef LIBC_COPT_UNSAFE_STRING_WIDE_READ // Unsigned int is the default size for most processors, and on x86-64 it // performs better than larger sizes when the src pointer can't be assumed to // be aligned to a word boundary, so it's the size we use for reading the @@ -143,7 +143,7 @@ // 'src'. If 'ch' is not found, returns nullptr. LIBC_INLINE void *find_first_character(const unsigned char *src, unsigned char ch, size_t max_strlen) { -#ifdef LIBC_UNSAFE_STRING_WIDE_READ +#ifdef LIBC_COPT_UNSAFE_STRING_WIDE_READ // If the maximum size of the string is small, the overhead of aligning to a // word boundary and generating a bitmask of the appropriate size may be // greater than the gains from reading larger chunks. Based on some testing, diff --git a/libc/src/unistd/getopt.cpp b/libc/src/unistd/getopt.cpp --- a/libc/src/unistd/getopt.cpp +++ b/libc/src/unistd/getopt.cpp @@ -186,7 +186,7 @@ &impl::optopt, &optpos, impl::opterr, reinterpret_cast(__llvm_libc::stderr)}; -#ifndef LLVM_LIBC_PUBLIC_PACKAGING +#ifndef LIBC_COPT_PUBLIC_PACKAGING // This is used exclusively in tests. void set_getopt_state(char **optarg, int *optind, int *optopt, unsigned *optpos, int opterr, FILE *errstream) { diff --git a/libc/test/UnitTest/FPExceptMatcher.h b/libc/test/UnitTest/FPExceptMatcher.h --- a/libc/test/UnitTest/FPExceptMatcher.h +++ b/libc/test/UnitTest/FPExceptMatcher.h @@ -9,7 +9,7 @@ #ifndef LLVM_LIBC_UTILS_UNITTEST_FPEXCEPTMATCHER_H #define LLVM_LIBC_UTILS_UNITTEST_FPEXCEPTMATCHER_H -#ifndef LLVM_LIBC_TEST_USE_FUCHSIA +#ifndef LIBC_COPT_TEST_USE_FUCHSIA #include "test/UnitTest/Test.h" @@ -62,6 +62,6 @@ func))) #else #define ASSERT_RAISES_FP_EXCEPT(func) ASSERT_DEATH(func, WITH_SIGNAL(SIGFPE)) -#endif // LLVM_LIBC_TEST_USE_FUCHSIA +#endif // LIBC_COPT_TEST_USE_FUCHSIA #endif // LLVM_LIBC_UTILS_UNITTEST_FPEXCEPTMATCHER_H diff --git a/libc/test/UnitTest/Test.h b/libc/test/UnitTest/Test.h --- a/libc/test/UnitTest/Test.h +++ b/libc/test/UnitTest/Test.h @@ -9,7 +9,7 @@ #ifndef LLVM_LIBC_UTILS_UNITTEST_TEST_H #define LLVM_LIBC_UTILS_UNITTEST_TEST_H -#ifdef LLVM_LIBC_TEST_USE_FUCHSIA +#ifdef LIBC_COPT_TEST_USE_FUCHSIA #include "FuchsiaTest.h" #else #include "LibcTest.h" diff --git a/libc/test/src/math/RoundToIntegerTest.h b/libc/test/src/math/RoundToIntegerTest.h --- a/libc/test/src/math/RoundToIntegerTest.h +++ b/libc/test/src/math/RoundToIntegerTest.h @@ -84,6 +84,8 @@ void do_infinity_and_na_n_test(RoundToIntegerFunc func) { test_one_input(func, inf, INTEGER_MAX, true); test_one_input(func, neg_inf, INTEGER_MIN, true); + // This is currently never enabled, the CMake option in libc/CMakeLists.txt + // is not forwarded to C++. #if LLVM_LIBC_IMPLEMENTATION_DEFINED_TEST_BEHAVIOR // Result is not well-defined, we always returns INTEGER_MAX test_one_input(func, nan, INTEGER_MAX, true); diff --git a/libc/test/src/stdio/printf_core/parser_test.cpp b/libc/test/src/stdio/printf_core/parser_test.cpp --- a/libc/test/src/stdio/printf_core/parser_test.cpp +++ b/libc/test/src/stdio/printf_core/parser_test.cpp @@ -279,7 +279,7 @@ ASSERT_PFORMAT_EQ(expected2, format_arr[2]); } -#ifndef LLVM_LIBC_PRINTF_DISABLE_INDEX_MODE +#ifndef LIBC_COPT_PRINTF_DISABLE_INDEX_MODE TEST(LlvmLibcPrintfParserTest, IndexModeOneArg) { __llvm_libc::printf_core::FormatSection format_arr[10]; @@ -474,4 +474,4 @@ EXPECT_PFORMAT_EQ(expected9, format_arr[9]); } -#endif // LLVM_LIBC_PRINTF_DISABLE_INDEX_MODE +#endif // LIBC_COPT_PRINTF_DISABLE_INDEX_MODE diff --git a/libc/test/src/stdio/scanf_core/parser_test.cpp b/libc/test/src/stdio/scanf_core/parser_test.cpp --- a/libc/test/src/stdio/scanf_core/parser_test.cpp +++ b/libc/test/src/stdio/scanf_core/parser_test.cpp @@ -549,7 +549,7 @@ ASSERT_SFORMAT_EQ(expected2, format_arr[2]); } -#ifndef LLVM_LIBC_SCANF_DISABLE_INDEX_MODE +#ifndef LIBC_COPT_SCANF_DISABLE_INDEX_MODE TEST(LlvmLibcScanfParserTest, IndexModeOneArg) { __llvm_libc::scanf_core::FormatSection format_arr[10]; @@ -756,4 +756,4 @@ EXPECT_SFORMAT_EQ(expected10, format_arr[10]); } -#endif // LLVM_LIBC_SCANF_DISABLE_INDEX_MODE +#endif // LIBC_COPT_SCANF_DISABLE_INDEX_MODE diff --git a/libc/test/src/stdio/sprintf_test.cpp b/libc/test/src/stdio/sprintf_test.cpp --- a/libc/test/src/stdio/sprintf_test.cpp +++ b/libc/test/src/stdio/sprintf_test.cpp @@ -502,7 +502,7 @@ ASSERT_STREQ(buff, "0077 01000000000000 002 "); } -#ifndef LLVM_LIBC_PRINTF_DISABLE_FLOAT +#ifndef LIBC_COPT_PRINTF_DISABLE_FLOAT TEST_F(LlvmLibcSPrintfTest, FloatHexExpConv) { __llvm_libc::testutils::ForceRoundingMode r( @@ -2662,9 +2662,9 @@ ASSERT_STREQ_LEN(written, buff, "+0.126 0001.26e+03"); } -#endif // LLVM_LIBC_PRINTF_DISABLE_FLOAT +#endif // LIBC_COPT_PRINTF_DISABLE_FLOAT -#ifndef LLVM_LIBC_PRINTF_DISABLE_WRITE_INT +#ifndef LIBC_COPT_PRINTF_DISABLE_WRITE_INT TEST(LlvmLibcSPrintfTest, WriteIntConv) { char buff[64]; int written; @@ -2697,9 +2697,9 @@ written = __llvm_libc::sprintf(buff, "abc123%n", nullptr); EXPECT_LT(written, 0); } -#endif // LLVM_LIBC_PRINTF_DISABLE_WRITE_INT +#endif // LIBC_COPT_PRINTF_DISABLE_WRITE_INT -#ifndef LLVM_LIBC_PRINTF_DISABLE_INDEX_MODE +#ifndef LIBC_COPT_PRINTF_DISABLE_INDEX_MODE TEST(LlvmLibcSPrintfTest, IndexModeParsing) { char buff[64]; int written; @@ -2724,4 +2724,4 @@ EXPECT_EQ(written, 45); ASSERT_STREQ(buff, "why would u do this, this is such a pain. %"); } -#endif // LLVM_LIBC_PRINTF_DISABLE_INDEX_MODE +#endif // LIBC_COPT_PRINTF_DISABLE_INDEX_MODE diff --git a/utils/bazel/llvm-project-overlay/libc/libc_build_rules.bzl b/utils/bazel/llvm-project-overlay/libc/libc_build_rules.bzl --- a/utils/bazel/llvm-project-overlay/libc/libc_build_rules.bzl +++ b/utils/bazel/llvm-project-overlay/libc/libc_build_rules.bzl @@ -88,7 +88,7 @@ func_attrs = ["__attribute__((visibility(\"default\")))"] if weak: func_attrs.append("__attribute__((weak))") - local_defines = local_defines or ["LLVM_LIBC_PUBLIC_PACKAGING"] + local_defines = local_defines or ["LIBC_COPT_PUBLIC_PACKAGING"] local_defines.append("LLVM_LIBC_FUNCTION_ATTR='%s'" % " ".join(func_attrs)) _libc_library( name = name,