summaryrefslogtreecommitdiff
path: root/libc/test/src/stdio/printf_core
AgeCommit message (Collapse)Author
2025-11-05[libc] Add printf error handling (with fixes #2) (#166517)Marcell Leleszi
https://github.com/llvm/llvm-project/issues/159474 Another try of trying to land https://github.com/llvm/llvm-project/pull/166382 - Fix some leftover tests checking for specific errnos - Guard errno checking tests to not run on the GPU @michaelrj-google
2025-11-04Revert commit d8e5698 and 15b19c7 (#166498)Kewen Meng
2025-11-04[libc] Add printf error handling (with fixes) (#166382)Marcell Leleszi
https://github.com/llvm/llvm-project/issues/159474 Resubmitting https://github.com/llvm/llvm-project/pull/162876 with fixes as it broke some buildbots: - Fix comparisons of integer expressions of different signedness - Not check for specific errnos in tests, as they might not be available on all platforms
2025-11-03Revert "[libc] Add printf error handling" (#166232)Kewen Meng
2025-11-03[libc] Add printf error handling (#162876)Marcell Leleszi
[#159474](https://github.com/llvm/llvm-project/issues/159474) - All printf variants set errno and consistently return -1 on error, instead of returning various predefined error codes - Return value overflow handling is added
2025-09-05[libc] Use anonymous namespace for test helper code (#157203)Roland McGrath
Tests can be at top-level or inside an anonymous namespace, doesn't matter. But putting their helper code inside anonymous namespaces both makes the code compatible with compiling using -Wmissing-declarations and might let the compiler optimize the test good a bit better.
2025-06-13[libc] Fix bugs found when testing with all headers (#144049)William Huynh
Fixes a couple of bugs found when building. The PR to enable the headers can be found here: #144114. - math.yaml: float128 guard - wchar.yaml: __restrict keyword order
2025-03-12[libc] Template the writing mode for the writer class (#111559)Joseph Huber
Summary: Currently we dispatch the writing mode off of a runtime enum passed in by the constructor. This causes very unfortunate codegen for the GPU targets where we get worst-case codegen because of the unused function pointer for `sprintf`. Instead, this patch moves all of this to a template so it can be masked out. This results in no dynamic stack and uses 60 VGPRs instead of 117. It also compiles about 5x as fast.
2025-03-10[libc] Add `-Wno-sign-conversion` & re-attempt `-Wconversion` (#129811)Vinay Deshmukh
Relates to https://github.com/llvm/llvm-project/issues/119281#issuecomment-2699470459
2025-03-05Revert "[libc] Enable -Wconversion for tests. (#127523)"Augie Fackler
This reverts commit 1e6e845d49a336e9da7ca6c576ec45c0b419b5f6 because it changed the 1st parameter of adjust() to be unsigned, but libc itself calls adjust() with a negative argument in align_backward() in op_generic.h.
2025-03-04[libc] Enable -Wconversion for tests. (#127523)Vinay Deshmukh
Relates to: #119281
2024-08-02[libc] Fix printf handling of INT_MIN width (#101729)Michael Jones
Prevously, if INT_MIN was passed as a wildcard width to a printf conversion the parser would attempt to negate it to get the positive width (and set the left justify flag), but it would underflow and the width would be treated as 0. This patch corrects the issue by instead treating a width of INT_MIN as identical to -INT_MAX. Also includes docs changes to explain this behavior and adding b to the list of int conversions.
2024-03-29Add bit width length modifier to printf (#82461)Om Prakaash
Resolves #81685. This adds support for wN and wfN length modifiers in fprintf.
2024-02-07[libc] Support C23 'b' (binary) modifier in printf (#80851)Artem Tyurin
Reference: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2612.pdf. Fixes https://github.com/llvm/llvm-project/issues/80727.
2023-09-26[libc] Mass replace enclosing namespace (#67032)Guillaume Chatelet
This is step 4 of https://discourse.llvm.org/t/rfc-customizable-namespace-to-allow-testing-the-libc-when-the-system-libc-is-also-llvms-libc/73079
2023-09-21[libc] Template the printf / scanf parser class (#66277)Joseph Huber
Summary: The parser class for stdio currently accepts different argument providers. In-tree this is only used for a fuzzer test, however, the proposed implementation of the GPU handling of printf / scanf will require custom argument handlers. This makes the current approach of using a preprocessor macro messier. This path proposed folding this logic into a template instantiation. The downside to this is that because the implementation of the parser class is placed into an implementation file we need to manually instantiate the needed templates which will slightly bloat binary size. Alternatively we could remove the implementation file, or key off of the `libc` external packaging macro so it is not present in the installed version.
2023-07-20[libc] Move printf writer to new designMichael Jones
The new printf writer design focuses on optimizing the fast path. It inlines any write to a buffer or string, and by handling buffering itself can more effectively work with both internal and external file implementations. The overflow hook should allow for expansion to asprintf with minimal extra code. Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D153999
2023-02-24[libc] Clarify printf percent conversion behavior.Michael Jones
Almost all printf conversions ending in '%' are undefined, but they're traditionally treated as if the complete conversion specifier is "%%". This patch modifies the parser to more closely match that behavior. Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D144679
2023-02-22[libc] Prevent printf index mode crashesMichael Jones
The posix standard defines an alternate mode for printf where the conversions also have an index that describes which argument to select. Due to how variadic arguments work in C, to reach the nth argument all n-1 previous arguments must be read with their correct types. If the format string does not specify the types for a continuous set of arguments, then the arguments after the discontinuity cannot be safely read. This patch causes all conversions requesting an argument that comes after a gap be treated as raw (i.e. the conversion string is printed literally). Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D143782
2023-02-15[libc][NFC] Make tuning macros start with LIBC_COPT_Guillaume Chatelet
Rename preprocessor definitions that control tuning of llvm libc. Differential Revision: https://reviews.llvm.org/D143913
2023-02-07[libc][NFC] Move UnitTest and IntegrationTest to the 'test' directory.Siva Chandra Reddy
This part of the effort to make all test related pieces into the `test` directory. This helps is excluding test related pieces in a straight forward manner if LLVM_INCLUDE_TESTS is OFF. Future patches will also move the MPFR wrapper and testutils into the 'test' directory.
2022-11-07[libc][obvious] fix printf failing to stop on %\0Michael Jones
Previously, the printf parser would treat "%\0" as a conversion with the name "\0", and advance past the null byte causing a buffer overflow. This patch corrects that in both printf and scanf. Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D137367
2022-10-28[libc] add scanf parser and core utilitiesMichael Jones
This is the first piece of scanf. It's very similar in design to printf, and so much of the code is copied from that. There were potential issues with conflicting macros so I've also renamed the "ASSERT_FORMAT_EQ" macro for printf to "ASSERT_PFORMAT_EQ". Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D136288
2022-08-25[NFC][libc] Fix unused variable in string_writer_test testGuillaume Chatelet
2022-08-24[libc] move printf to use StringViewsMichael Jones
The FormatSection and the writer functions both previously took a char* and a length to represent a string. Now they use the StringView class to represent that more succinctly. This change also required fixing everywhere these were used, so it touches a lot of files. Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D131994
2022-08-19[reland][libc][NFC] Use STL case for bitGuillaume Chatelet
2022-08-19Revert "[libc][NFC] Use STL case for bit"Guillaume Chatelet
This reverts commit 7ba14b8611df1172d92d60bf19870e98a92e7a3a.
2022-08-19[libc][NFC] Use STL case for bitGuillaume Chatelet
2022-08-15[libc] add guard for file pieces of printfMichael Jones
In the printf_core CMake, the file pieces are defined as object libraries that depend on the File data structure. If these are added unconditionally they'll try to evaluate that dependancy even when there is no File available. This patch adds a guard to prevent that error. Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D131921
2022-06-27[libc] add printf oct conversionMichael Jones
The oct converter handles the %o conversion. Reviewed By: lntue Differential Revision: https://reviews.llvm.org/D127985
2022-06-17[libc] add printf pointer convMichael Jones
The pointer converter handles the %p conversion. It uses the hex converter for most of the conversion. Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D127995
2022-06-16[libc] add printf hex conversionMichael Jones
The hex converter handles the %x and %X conversions. Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D126082
2022-06-15[libc] refactor printf file writingMichael Jones
Add return values to converter functions to allow for better error handling when writing files. Also move the file writing code around to be easier to read. Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D127773
2022-06-09[libc] add printf base 10 integer conversionMichael Jones
This patch adds support for d, i, and u conversions in printf, as well as comprehensive unit tests. Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D125929
2022-06-09[libc] simplify printf converter testsMichael Jones
previously the printf converter tests reused the same string_writer, which meant that each test depended on the tests before it to succeed. This makes a new string_writer for each test to simplify and clarify the tests. Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D127341
2022-06-01[libc] Implement FLAGS option for generating all combinations for targets.Tue Ly
Add FLAGS option for add_header_library, add_object_library, add_entrypoint_object, and add_libc_unittest. In general, a flag is a string provided for supported functions under the multi-valued option `FLAGS`. It should be one of the following forms: FLAG_NAME FLAG_NAME__NO FLAG_NAME__ONLY A target will inherit all the flags of its upstream dependency. When we create a target `TARGET_NAME` with a flag using (add_header_library, add_object_library, ...), its behavior will depend on the flag form as follow: - FLAG_NAME: The following 2 targets will be generated: `TARGET_NAME` that has `FLAG_NAME` in its `FLAGS` property. `TARGET_NAME.__NO_FLAG_NAME` that depends on `DEP.__NO_FLAG_NAME` if `TARGET_NAME` depends on `DEP` and `DEP` has `FLAG_NAME` in its `FLAGS` property. - FLAG_NAME__ONLY: Only generate 1 target `TARGET_NAME` that has `FLAG_NAME` in its `FLAGS` property. - FLAG_NAME__NO: Only generate 1 target `TARGET_NAME.__NO_FLAG_NAME` that depends on `DEP.__NO_FLAG_NAME` if `DEP` is in its DEPENDS list and `DEP` has `FLAG_NAME` in its `FLAGS` property. To show all the targets generated, pass SHOW_INTERMEDIATE_OBJECTS=ON to cmake. To show all the targets' dependency and flags, pass `SHOW_INTERMEDIATE_OBJECTS=DEPS` to cmake. To completely disable a flag FLAG_NAME expansion, set the variable `SKIP_FLAG_EXPANSION_FLAG_NAME=TRUE`. Reviewed By: michaelrj, sivachandra Differential Revision: https://reviews.llvm.org/D125174
2022-05-17[libc] add sprintfMichael Jones
This adds the sprintf entrypoint, as well as unit tests. Currently sprintf only supports %%, %s, and %c, but the other conversions are on the way. Reviewed By: sivachandra, lntue Differential Revision: https://reviews.llvm.org/D125573
2022-05-12[libc] add printf converterMichael Jones
This adds the main pieces of the last piece of printf, the converter. This takes the completed format section from the parser and then converts it to a string for the writer, which is why it was the last piece to be written. So far it supports chars and strings, but more pieces are coming. Additionally, it supports replacing all of the conversion functions with user supplied versions at compile time to allow for additional functionality. Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D125327
2022-05-08[libc] Add LINK_LIBRARIES option to add_fp_unittest and add_libc_unittest.Tue Ly
This is needed to prepare for adding FLAGS option. Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D125055
2022-05-06[libc][NFC] add index mode to printf parserMichael Jones
This patch is a followup to the previous patch which implemented the main printf parsing logic as well as sequential mode. This patch adds index mode. Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D123424
2022-05-03[libc] add printf writerMichael Jones
The printf implmentation is made up of three main pieces, the parser, the converter, and the writer. This patch adds the implementation for the writer, as well as the function for writing to a string, along with tests. Reviewed By: sivachandra, lntue Differential Revision: https://reviews.llvm.org/D124421
2022-04-22[libc] Add Printf FormatSection MatcherMichael Jones
This patch changes the printf parser tests to use a more robust matcher. This allows for better debugging of parsing issues. This does not affect the actual printf code at all, only the tests. Reviewed By: sivachandra, lntue Differential Revision: https://reviews.llvm.org/D124130
2022-04-08[libc][NFC] implement printf parserMichael Jones
This patch adds the sequential mode implementation of the printf parser, as well as unit tests for it. In addition it adjusts the surrounding files to accomodate changes in the design found in the implementation process. Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D123339