This is an archive of the discontinued LLVM Phabricator instance.

[DebugInfo] Fix handling '# line "file"' for DWARFv5
ClosedPublic

Authored by ikudrin on Jan 20 2022, 7:13 AM.

Details

Summary

CppHashInfo.Filename is a StringRef that references a part of the source file and it is not null-terminated at the end of the file name. AsmParser::parseAndMatchAndEmitTargetInstruction() passes it to getStreamer().emitDwarfFileDirective(), and it eventually comes to isRootFile(). The comparison fails because FileName.data() is not properly terminated.

In addition, the old code might cause a significant speed degradation for long source files. The operator!=() for std::string and const char * can be implemented in a way that it finds the length of the second argument first, which slows the comparison for long data. parseAndMatchAndEmitTargetInstruction() calls emitDwarfFileDirective() every time if CppHashInfo.Filename is not empty. As a result, the longer the source file is, the slower compilation wend, and for a very long file, it might take hours instead of a couple of seconds normally.

Diff Detail

Event Timeline

ikudrin created this revision.Jan 20 2022, 7:13 AM
ikudrin requested review of this revision.Jan 20 2022, 7:13 AM
ikudrin retitled this revision from [DebugInfo] Fix handling '# line "file"' for DWARF5 to [DebugInfo] Fix handling '# line "file"' for DWARFv5.Jan 20 2022, 7:13 AM
probinson accepted this revision.Jan 20 2022, 9:36 AM

LGTM, thanks for finding this!

Really DWARF v5 shouldn't emit the fully qualified name in the file_names list, but I remember there being an issue filed for this a while back, and the fix will surely be somewhere else in the v5 path.

This revision is now accepted and ready to land.Jan 20 2022, 9:36 AM
This revision was landed with ongoing or failed builds.Jan 20 2022, 10:52 PM
This revision was automatically updated to reflect the committed changes.