This is an archive of the discontinued LLVM Phabricator instance.

[libc] add core printf parsing
AbandonedPublic

Authored by michaelrj on Jan 28 2022, 3:00 PM.

Details

Reviewers
sivachandra
lntue
Summary

This patch adds the core parsing for printf in the PrintfParser class.
It does not, however, include the conversion or string construction
parts that are necessary for a complete printf. Those will be added in a
later patch.

Diff Detail

Event Timeline

michaelrj created this revision.Jan 28 2022, 3:00 PM
michaelrj requested review of this revision.Jan 28 2022, 3:00 PM

Few highlevel comments for now. Once they are addressed, I will comment on the details.

libc/src/stdio/printf_parser.h
1

Most of this class should move to a .cpp file.

33–34

We should do it now as a prerequisite. Also, instead of a vector, it an "object-store" might be useful in general.

317

While holding onto a va_list pointer while on the same stack should be OK, saving it as another object's state can lead to surprising results. Also, it is not clear as to who is responsible for calling va_start and va_end. Can we perhaps create a RAII class around va_list so that we don't have to worry about things like this? Also, it is better to have an API which does not require storing the varargs.

libc/test/src/stdio/printf_parser_test.cpp
1

Couple of general comments:

  1. The tests are testing much less functionality than what is implemented.
  2. The va_list arg is always empty.
lntue added inline comments.Feb 2 2022, 7:23 AM
libc/src/stdio/printf_format_struct.h
17

Shall none be all CAPS?

michaelrj abandoned this revision.Feb 11 2022, 11:41 AM

This version of printf has issues that are not easily fixed. It is being redesigned, and a new patch will be made.