summaryrefslogtreecommitdiff
path: root/llvm/lib/Support/FormatVariadic.cpp
AgeCommit message (Collapse)Author
2024-10-16[formatv] Leave format parameters unstripped (#112625)David Blaikie
This is consistent with std::formatv and allows formatters to support a wider variety of use cases (like having a bare string in their formatter if that's useful, etc). Came up in the context of some Carbon diagnostic work here: https://github.com/carbon-language/carbon-lang/pull/4411#discussion_r1803688859
2024-09-16[Support] Fix bugs in formatv automatic index assignment (#108384)Rahul Joshi
Fix bugs found when actually trying to use formatv() automatic index assignment in IntrinsicEmitter.cpp: - Assign automatic index only for `ReplacementType::Format`. - Make the check for all replacement indices being either automatic orexplicit more accurate. The existing check fails for formatv("{}{0}{}", 0, 1) (added as a unit test). Explicitly track if we have seen any explicit and any automatic index instead.
2024-09-12[Support] Add automatic index assignment in formatv (#107459)Rahul Joshi
Make index in replacement field optional. It will be automatically assigned in incremental order by formatv. Make mixed use of automatic and explicit indices an error that will fail validation. Adopt uses of formatv() within FormatVariadic to use automatic index.
2024-09-05[NFC][Support] Refactor FormatVariadic code. (#106610)Rahul Joshi
- Rename `Align` field in ReplacementItem/FmtAlign to `Width` to accurately reflect its use. - Change both `Width` and `Index` in ReplacementItem to 32-bit int instead of size_t (as 64-bits seems excessive in this context). - Eliminate the use of `Empty` ReplacementType, and use the existing std::optional<> instead to indicate that. - Eliminate some boilerplate type code in formatv(). - Eliminate the loop in `splitLiteralAndReplacement`. The existing code will never loop back. - Directly use constructor instead of std::make_pair.
2024-08-29Revert "Revert "[Support] Validate number of arguments passed to formatv()"" ↵Rahul Joshi
(#106592) Reverts llvm/llvm-project#106589 The fix for bot failures caused by the reverted commit was committed already, so this revert is not needed.
2024-08-29Revert "[Support] Validate number of arguments passed to formatv()" (#106589)Mehdi Amini
Reverts llvm/llvm-project#105745 Some bots are broken apparently.
2024-08-29[Support] Validate number of arguments passed to formatv() (#105745)Rahul Joshi
Change formatv() to validate that the number of arguments passed matches number of replacement fields in the format string, and that the replacement indices do not contain holes. To support cases where this cannot be guaranteed, introduce a formatv() overload that allows disabling validation with a bool flag as its first argument.
2024-08-19[Support] Do not ignore unterminated open { in formatv (#104688)Rahul Joshi
- When an unterminated open { is detected in the format string, instead of asserting and ignoring the error, replace that string with another to indicate the error, and remove the assert as well. - This will make the error evident in both assert and release builds and make observing the error more convenient (as several uses of this function are in TableGen and it is often built in release mode even in debug builds)
2024-04-02Move format internal code from llvm::detail to llvm::support::detail. (#87288)Chenguang Wang
Some support code, e.g. llvm/Support/Endian.h, uses llvm::support::detail, but the format-related code uses llvm::detail. On VS2019, when a C++ file includes both headers, a `detail::` from `namespace llvm { ... }` becomes ambiguous. 44253a9c breaks TensorFlow and [JAX](https://github.com/google/jax/actions/runs/8507773013/job/23300219405) build because of this. Since llvm::X::detail seems like a cleaner solution and is used in other places as well (e.g. llvm::yaml::detail), we should probably migrate all llvm::detail usages to llvm::X::detail.
2024-02-04[llvm] Use StringRef::consume_front (NFC)Kazu Hirata
2024-01-13[Support] Use StringRef::consume_front (NFC)Kazu Hirata
2022-12-16[Support] llvm::Optional => std::optionalFangrui Song
https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-02[llvm] Use std::nullopt instead of None (NFC)Kazu Hirata
This patch mechanically replaces None with std::nullopt where the compiler would warn if None were deprecated. The intent is to reduce the amount of manual work required in migrating from Optional to std::optional. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-11-25[Support] Use std::optional in FormatVariadic.cpp (NFC)Kazu Hirata
This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-06-20[llvm] Don't use Optional::hasValue (NFC)Kazu Hirata
2022-02-06Revert rG7275de7fb2f087871611d037d1b529b226dd0521 "[AArch64] ↵Simon Pilgrim
translateLocChar - silence dead code warning" Seems to cause some buildbot misbehaviour (+ there's a dumb copy+paste typo in the commit message....)
2022-02-06[AArch64] translateLocChar - silence dead code warningSimon Pilgrim
Remove default case from switch and return None after the switch()
2020-07-22[NFC] Simplify `splitLiteralAndReplacement` functionRahul Joshi
- Eliminate `From` which is 0 most of the times. - Replace 'find_first_of('{') != 0' with 'front() != '{' - Simplify the loop body given the it executes only when front() == '}' Differential Revision: https://reviews.llvm.org/D84178
2020-04-11[FormatVariadic] Reduce allocationsBenjamin Kramer
- Move Adapters array to the stack, we know the size precisely - Parse format string on demand into a SmallVector. In theory this could lead to parsing it multiple times, but I couldn't find a single instance of that in LLVM. - Make more of the implementation details private.
2020-03-02Explicitly include <cassert> when using assertJoerg Sonnenberger
Depending on the OS used, a module-enabled build can fail due to the special handling <cassert> gets as textual header.
2019-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth
to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
2018-12-29Add vtable anchor to classes.Richard Trieu
llvm-svn: 350142
2017-10-08Remove unused variables. No functionality change.Benjamin Kramer
llvm-svn: 315185
2016-11-11[Support] Introduce llvm::formatv() function.Zachary Turner
This introduces a new type-safe general purpose formatting library. It provides compile-time type safety, does not require a format specifier (since the type is deduced), and provides mechanisms for extending the format capability to user defined types, and overriding the formatting behavior for existing types. This patch additionally adds documentation for the API to the LLVM programmer's manual. Mailing List Thread: http://lists.llvm.org/pipermail/llvm-dev/2016-October/105836.html Differential Revision: https://reviews.llvm.org/D25587 llvm-svn: 286682