This is an archive of the discontinued LLVM Phabricator instance.

[libc] Fix line reporting in assertion failure
ClosedPublic

Authored by JonChesterfield on Jul 20 2023, 3:31 PM.

Details

Summary

Was passing zeros to the string print function.

Diff Detail

Event Timeline

Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJul 20 2023, 3:31 PM
JonChesterfield requested review of this revision.Jul 20 2023, 3:31 PM

IntegerToString returns a string view carefully sized to display only the digits from the number. Before this patch, we pass the whole line_str buffer. This prints as the empty string for integers that don't fill the buffer.

It's statically known that the value will fit in the buffer but the existing interface returns an optional. I haven't found an existing equivalent that returns a string view for statically sufficient buffer size, might be worth writing one.

jhuber6 accepted this revision.Jul 20 2023, 3:35 PM
This revision is now accepted and ready to land.Jul 20 2023, 3:35 PM

Unrelated to this, but I'm surprised assert lowers to eight calls to write_to_stderr and some runtime number conversion. I expected it to concatenate the strings and do the line number -> string conversion at preprocessor time, resolving to a single call to write_to_stderr with a compile time constant string literal.

This revision was automatically updated to reflect the committed changes.
libc/src/__support/libc_assert.h
36

this ^ is addressed by the wip D155902