This is an archive of the discontinued LLVM Phabricator instance.

[DWARF] Fix undefined behaviour in dwarf type printer
ClosedPublic

Authored by momo5502 on Jul 12 2023, 8:23 AM.

Details

Summary

The value to be formatted here, Val, is an int64_t which can not be formatted using %x.
This commit adjusts all misuses I was able to find in the llvm-dwarfdump project.

Failing tests in https://reviews.llvm.org/D153800 lead to the discovery and analysis of this issue.

Diff Detail

Event Timeline

momo5502 created this revision.Jul 12 2023, 8:23 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 12 2023, 8:23 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
momo5502 requested review of this revision.Jul 12 2023, 8:23 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 12 2023, 8:23 AM
efriedma accepted this revision.Jul 12 2023, 12:04 PM

LGTM

Longer term, we should consider what we can do to mitigate this sort of issue showing up again (adding a "format" attribute to llvm::format and/or switching more code over to other formatting functions like llvm::formatv).

llvm/lib/DebugInfo/DWARF/DWARFTypePrinter.cpp
431

Not really related to this change, but while you're here, can you drop the to_string calls? OS << llvm::format() should just work.

This revision is now accepted and ready to land.Jul 12 2023, 12:04 PM

Thank you for reviewing, and yes, I totally aggree. Preventing such issues from happening in the first place is would be better.
Will update this change tomorrow to drop the to_string calls.

Btw, before I forget it, for future commits of mine, can you please use the following details from now on: Maurice Heumann <maurice.heumann@wibu.com>.

momo5502 updated this revision to Diff 539851.Jul 12 2023, 10:55 PM

Remove to_string usages

momo5502 marked an inline comment as done.Jul 12 2023, 10:56 PM

Thanks for the catch!