This is an archive of the discontinued LLVM Phabricator instance.

[libc] Clarify printf percent conversion behavior.
ClosedPublic

Authored by michaelrj on Feb 23 2023, 2:54 PM.

Details

Summary

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.

Diff Detail

Event Timeline

michaelrj created this revision.Feb 23 2023, 2:54 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptFeb 23 2023, 2:54 PM
michaelrj requested review of this revision.Feb 23 2023, 2:54 PM
lntue added inline comments.Feb 23 2023, 8:07 PM
libc/src/stdio/printf_core/parser.cpp
113

Probably we should have a section in the main doc page about implementation-defined behaviors and rationale, with links to the implementations and tests.

sivachandra accepted this revision.Feb 23 2023, 8:16 PM
sivachandra added inline comments.
libc/src/stdio/printf_core/parser.cpp
113

Address this before landing: Please use "we" instead of "I".

Can be done as a follow up step: +1 for adding a doc page titled "Implementation Defined Behavior".

This revision is now accepted and ready to land.Feb 23 2023, 8:16 PM
michaelrj marked 2 inline comments as done.Feb 24 2023, 10:20 AM
michaelrj added inline comments.
libc/src/stdio/printf_core/parser.cpp
113

I agree that we should have a page on implementation defined behavior and will do that in another patch.

michaelrj marked an inline comment as done.

fix comment phrasing before landing

Fix a minor bug found in final testing.

Setting the variable from the result of a failed index parsing was setting
unexpected pieces of the FormatSection struct. This wouldn't have affected
any actual conversions, since the only conversion that regains its has_conv
flag is %% which ignores all options, but it was causing the test to fail.

This revision was landed with ongoing or failed builds.Feb 24 2023, 1:29 PM
This revision was automatically updated to reflect the committed changes.