Allow for mixing source/no-source DIFiles in one CU · llvm/llvm-project@87e22bd (original) (raw)
`@@ -386,7 +386,7 @@ void MCDwarfLineTableHeader::emitV2FileDirTables(MCStreamer *MCOS) const {
`
386
386
`}
`
387
387
``
388
388
`static void emitOneV5FileEntry(MCStreamer *MCOS, const MCDwarfFile &DwarfFile,
`
389
``
`-
bool EmitMD5, bool HasSource,
`
``
389
`+
bool EmitMD5, bool HasAnySource,
`
390
390
` std::optional &LineStr) {
`
391
391
`assert(!DwarfFile.Name.empty());
`
392
392
`if (LineStr)
`
`@@ -401,7 +401,7 @@ static void emitOneV5FileEntry(MCStreamer *MCOS, const MCDwarfFile &DwarfFile,
`
401
401
` MCOS->emitBinaryData(
`
402
402
`StringRef(reinterpret_cast<const char *>(Cksum.data()), Cksum.size()));
`
403
403
` }
`
404
``
`-
if (HasSource) {
`
``
404
`+
if (HasAnySource) {
`
405
405
`if (LineStr)
`
406
406
` LineStr->emitRef(MCOS, DwarfFile.Source.value_or(StringRef()));
`
407
407
`else {
`
`@@ -452,7 +452,7 @@ void MCDwarfLineTableHeader::emitV5FileDirTables(
`
452
452
`uint64_t Entries = 2;
`
453
453
`if (HasAllMD5)
`
454
454
` Entries += 1;
`
455
``
`-
if (HasSource)
`
``
455
`+
if (HasAnySource)
`
456
456
` Entries += 1;
`
457
457
` MCOS->emitInt8(Entries);
`
458
458
` MCOS->emitULEB128IntValue(dwarf::DW_LNCT_path);
`
`@@ -464,7 +464,7 @@ void MCDwarfLineTableHeader::emitV5FileDirTables(
`
464
464
` MCOS->emitULEB128IntValue(dwarf::DW_LNCT_MD5);
`
465
465
` MCOS->emitULEB128IntValue(dwarf::DW_FORM_data16);
`
466
466
` }
`
467
``
`-
if (HasSource) {
`
``
467
`+
if (HasAnySource) {
`
468
468
` MCOS->emitULEB128IntValue(dwarf::DW_LNCT_LLVM_source);
`
469
469
` MCOS->emitULEB128IntValue(LineStr ? dwarf::DW_FORM_line_strp
`
470
470
` : dwarf::DW_FORM_string);
`
`@@ -479,9 +479,9 @@ void MCDwarfLineTableHeader::emitV5FileDirTables(
`
479
479
`assert((!RootFile.Name.empty() || MCDwarfFiles.size() >= 1) &&
`
480
480
`"No root file and no .file directives");
`
481
481
`emitOneV5FileEntry(MCOS, RootFile.Name.empty() ? MCDwarfFiles[1] : RootFile,
`
482
``
`-
HasAllMD5, HasSource, LineStr);
`
``
482
`+
HasAllMD5, HasAnySource, LineStr);
`
483
483
`for (unsigned i = 1; i < MCDwarfFiles.size(); ++i)
`
484
``
`-
emitOneV5FileEntry(MCOS, MCDwarfFiles[i], HasAllMD5, HasSource, LineStr);
`
``
484
`+
emitOneV5FileEntry(MCOS, MCDwarfFiles[i], HasAllMD5, HasAnySource, LineStr);
`
485
485
`}
`
486
486
``
487
487
`std::pair<MCSymbol *, MCSymbol *>
`
`@@ -598,7 +598,7 @@ MCDwarfLineTableHeader::tryGetFile(StringRef &Directory, StringRef &FileName,
`
598
598
`// If any files have embedded source, they all must.
`
599
599
`if (MCDwarfFiles.empty()) {
`
600
600
`trackMD5Usage(Checksum.has_value());
`
601
``
`-
HasSource = (Source != std::nullopt);
`
``
601
`+
HasAnySource |= Source.has_value();
`
602
602
` }
`
603
603
`if (DwarfVersion >= 5 && isRootFile(RootFile, Directory, FileName, Checksum))
`
604
604
`return 0;
`
`@@ -625,11 +625,6 @@ MCDwarfLineTableHeader::tryGetFile(StringRef &Directory, StringRef &FileName,
`
625
625
`return make_error("file number already allocated",
`
626
626
`inconvertibleErrorCode());
`
627
627
``
628
``
`-
// If any files have embedded source, they all must.
`
629
``
`-
if (HasSource != (Source != std::nullopt))
`
630
``
`-
return make_error("inconsistent use of embedded source",
`
631
``
`-
inconvertibleErrorCode());
`
632
``
-
633
628
`if (Directory.empty()) {
`
634
629
`// Separate the directory part from the basename of the FileName.
`
635
630
` StringRef tFileName = sys::path::filename(FileName);
`
`@@ -662,8 +657,8 @@ MCDwarfLineTableHeader::tryGetFile(StringRef &Directory, StringRef &FileName,
`
662
657
` File.Checksum = Checksum;
`
663
658
`trackMD5Usage(Checksum.has_value());
`
664
659
` File.Source = Source;
`
665
``
`-
if (Source)
`
666
``
`-
HasSource = true;
`
``
660
`+
if (Source.has_value())
`
``
661
`+
HasAnySource = true;
`
667
662
``
668
663
`// return the allocated FileNumber.
`
669
664
`return FileNumber;
`