Skip to content

Revert "[MC] Fix DWARF file table for files with empty DWARF (#119020)" #119486

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 10 additions & 15 deletions llvm/lib/MC/MCParser/AsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ class AsmParser : public MCAsmParser {
};
CppHashInfoTy CppHashInfo;

/// Have we seen any file line comment.
bool HadCppHashFilename = false;
/// The filename from the first cpp hash file line comment, if any.
StringRef FirstCppHashFilename;

/// List of forward directional labels for diagnosis at the end.
SmallVector<std::tuple<SMLoc, CppHashInfoTy, MCSymbol *>, 4> DirLabels;
Expand Down Expand Up @@ -952,6 +952,12 @@ bool AsmParser::enabledGenDwarfForAssembly() {
// the assembler source was produced with debug info already) then emit one
// describing the assembler source file itself.
if (getContext().getGenDwarfFileNumber() == 0) {
// Use the first #line directive for this, if any. It's preprocessed, so
// there is no checksum, and of course no source directive.
if (!FirstCppHashFilename.empty())
getContext().setMCLineTableRootFile(
/*CUID=*/0, getContext().getCompilationDir(), FirstCppHashFilename,
/*Cksum=*/std::nullopt, /*Source=*/std::nullopt);
const MCDwarfFile &RootFile =
getContext().getMCDwarfLineTable(/*CUID=*/0).getRootFile();
getContext().setGenDwarfFileNumber(getStreamer().emitDwarfFileDirective(
Expand Down Expand Up @@ -2434,19 +2440,8 @@ bool AsmParser::parseCppHashLineFilenameComment(SMLoc L, bool SaveLocInfo) {
CppHashInfo.Filename = Filename;
CppHashInfo.LineNumber = LineNumber;
CppHashInfo.Buf = CurBuffer;
if (!HadCppHashFilename) {
HadCppHashFilename = true;
// If we haven't encountered any .file directives, then the first #line
// directive describes the "root" file and directory of the compilation
// unit.
if (getContext().getGenDwarfFileNumber() == 0) {
// It's preprocessed, so there is no checksum, and of course no source
// directive.
getContext().setMCLineTableRootFile(
/*CUID=*/0, getContext().getCompilationDir(), Filename,
/*Cksum=*/std::nullopt, /*Source=*/std::nullopt);
}
}
if (FirstCppHashFilename.empty())
FirstCppHashFilename = Filename;
return false;
}

Expand Down
26 changes: 0 additions & 26 deletions llvm/test/MC/ELF/debug-hash-file-empty-dwarf.s

This file was deleted.

Loading