This is an archive of the discontinued LLVM Phabricator instance.

[libc] Fix printf %p format
ClosedPublic

Authored by michaelrj on Sep 5 2023, 2:48 PM.

Details

Summary

The %p format wasn't correctly passing along flags and modifiers to the
integer conversion behind the scenes. This patch fixes that behavior, as
well as changing the nullptr behavior to be a string conversion behind
the scenes.

Diff Detail

Event Timeline

michaelrj created this revision.Sep 5 2023, 2:48 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptSep 5 2023, 2:48 PM
michaelrj requested review of this revision.Sep 5 2023, 2:48 PM
jhuber6 accepted this revision.Sep 5 2023, 2:50 PM

Thanks.

libc/src/stdio/printf_core/ptr_converter.h
23–24

Why do we need to cast nullptr here? Also do we have the raw value itself? We could just check that for zero.

This revision is now accepted and ready to land.Sep 5 2023, 2:50 PM
michaelrj marked an inline comment as done.Sep 5 2023, 2:59 PM
michaelrj added inline comments.
libc/src/stdio/printf_core/ptr_converter.h
23–24

I'm not sure why that cast is there. I've removed it.

The reason we check the pointer is because the value is a pointer, so it gets stored in the pointer member.

michaelrj updated this revision to Diff 555943.Sep 5 2023, 2:59 PM
michaelrj marked an inline comment as done.

clean up unnecessary cast.

lntue added inline comments.Sep 7 2023, 8:07 AM
libc/src/stdio/printf_core/ptr_converter.h
32–37

This is now unreachable. You can remove the else from the above and this return statement.

michaelrj updated this revision to Diff 556187.Sep 7 2023, 11:26 AM
michaelrj marked an inline comment as done.

remove unnecessary return and simplify conditionals

lntue accepted this revision.Sep 7 2023, 2:04 PM
This revision was automatically updated to reflect the committed changes.