[libc-commits] [libc] [libc] Export configs for `scanf` support (PR #98066)
Joseph Huber via libc-commits
libc-commits at lists.llvm.org
Mon Jul 8 12:09:47 PDT 2024
https://github.com/jhuber6 created https://github.com/llvm/llvm-project/pull/98066
Summary:
This patch adds the options for configuring floating point and index
mode for scanf just like `printf`. Not enabling it on the GPU yet, need
to fix something else first.
>From cb3f9655f793a5c203be8a87eef67a5521f888ff Mon Sep 17 00:00:00 2001
From: Joseph Huber <huberjn at outlook.com>
Date: Mon, 8 Jul 2024 14:04:46 -0500
Subject: [PATCH] [libc] Export configs for `scanf` support
Summary:
This patch adds the options for configuring floating point and index
mode for scanf just like `printf`. Not enabling it on the GPU yet, need
to fix something else first.
---
libc/config/config.json | 10 ++++++++++
libc/config/gpu/config.json | 8 ++++++++
libc/docs/configure.rst | 3 +++
libc/src/stdio/scanf_core/CMakeLists.txt | 18 ++++++++++++++++++
4 files changed, 39 insertions(+)
diff --git a/libc/config/config.json b/libc/config/config.json
index cf80f9993e595..e8feab20175f4 100644
--- a/libc/config/config.json
+++ b/libc/config/config.json
@@ -21,6 +21,16 @@
"doc": "Disable printing fixed point values in printf and friends."
}
},
+ "scanf": {
+ "LIBC_CONF_SCANF_DISABLE_FLOAT": {
+ "value": false,
+ "doc": "Disable parsing floating point values in scanf and friends."
+ },
+ "LIBC_CONF_SCANF_DISABLE_INDEX_MODE": {
+ "value": false,
+ "doc": "Disable index mode in the scanf format string."
+ }
+ },
"string": {
"LIBC_CONF_STRING_UNSAFE_WIDE_READ": {
"value": false,
diff --git a/libc/config/gpu/config.json b/libc/config/gpu/config.json
index 73bf810efbac6..71107d26ea7ab 100644
--- a/libc/config/gpu/config.json
+++ b/libc/config/gpu/config.json
@@ -13,6 +13,14 @@
"value": false
}
},
+ "scanf": {
+ "LIBC_CONF_SCANF_DISABLE_FLOAT": {
+ "value": true
+ },
+ "LIBC_CONF_SCANF_DISABLE_INDEX_MODE": {
+ "value": true
+ }
+ },
"math": {
"LIBC_CONF_MATH_OPTIMIZATIONS": {
"value": "(LIBC_MATH_SKIP_ACCURATE_PASS | LIBC_MATH_SMALL_TABLES | LIBC_MATH_NO_ERRNO | LIBC_MATH_NO_EXCEPT)"
diff --git a/libc/docs/configure.rst b/libc/docs/configure.rst
index d309d5b772038..9c641ef94570f 100644
--- a/libc/docs/configure.rst
+++ b/libc/docs/configure.rst
@@ -42,6 +42,9 @@ to learn about the defaults for your platform and target.
- ``LIBC_CONF_RAW_MUTEX_DEFAULT_SPIN_COUNT``: Default number of spins before blocking if a mutex is in contention (default to 100).
- ``LIBC_CONF_RWLOCK_DEFAULT_SPIN_COUNT``: Default number of spins before blocking if a rwlock is in contention (default to 100).
- ``LIBC_CONF_TIMEOUT_ENSURE_MONOTONICITY``: Automatically adjust timeout to CLOCK_MONOTONIC (default to true). POSIX API may require CLOCK_REALTIME, which can be unstable and leading to unexpected behavior. This option will convert the real-time timestamp to monotonic timestamp relative to the time of call.
+* **"scanf" options**
+ - ``LIBC_CONF_SCANF_DISABLE_FLOAT``: Disable parsing floating point values in scanf and friends.
+ - ``LIBC_CONF_SCANF_DISABLE_INDEX_MODE``: Disable index mode in the scanf format string.
* **"string" options**
- ``LIBC_CONF_MEMSET_X86_USE_SOFTWARE_PREFETCHING``: Inserts prefetch for write instructions (PREFETCHW) for memset on x86 to recover performance when hardware prefetcher is disabled.
- ``LIBC_CONF_STRING_UNSAFE_WIDE_READ``: Read more than a byte at a time to perform byte-string operations like strlen.
diff --git a/libc/src/stdio/scanf_core/CMakeLists.txt b/libc/src/stdio/scanf_core/CMakeLists.txt
index b3445300059fa..e2b49e0c91528 100644
--- a/libc/src/stdio/scanf_core/CMakeLists.txt
+++ b/libc/src/stdio/scanf_core/CMakeLists.txt
@@ -1,8 +1,26 @@
+if(LIBC_CONF_SCANF_DISABLE_FLOAT)
+ list(APPEND scanf_config_copts "-DLIBC_COPT_SCANF_DISABLE_FLOAT")
+endif()
+if(LIBC_CONF_SCANF_DISABLE_INDEX_MODE)
+ list(APPEND scanf_config_copts "-DLIBC_COPT_SCANF_DISABLE_INDEX_MODE")
+endif()
+if(scanf_config_copts)
+ list(PREPEND scanf_config_copts "COMPILE_OPTIONS")
+endif()
+
+add_header_library(
+ scanf_config
+ HDRS
+ scanf_config.h
+ ${scanf_config_copts}
+)
+
add_header_library(
core_structs
HDRS
core_structs.h
DEPENDS
+ .scanf_config
libc.src.__support.CPP.string_view
libc.src.__support.CPP.bitset
libc.src.__support.FPUtil.fp_bits
More information about the libc-commits
mailing list