Skip to content

Conversation

@dwblaikie
Copy link
Collaborator

Reverts #119229

Causes debug info to be unconditionally emitted, regardless of whether it's requested.

@llvmbot llvmbot added the llvm:mc Machine (object) code label Dec 11, 2024
@dwblaikie dwblaikie added skip-precommit-approval PR for CI feedback, not intended for review and removed llvm:mc Machine (object) code labels Dec 11, 2024
@dwblaikie dwblaikie merged commit 0d59fc2 into main Dec 11, 2024
8 of 10 checks passed
@dwblaikie dwblaikie deleted the revert-119229-asm-empty-dwarf branch December 11, 2024 02:14
@llvmbot
Copy link
Member

llvmbot commented Dec 11, 2024

@llvm/pr-subscribers-mc

Author: David Blaikie (dwblaikie)

Changes

Reverts llvm/llvm-project#119229

Causes debug info to be unconditionally emitted, regardless of whether it's requested.


Full diff: https://github.com/llvm/llvm-project/pull/119486.diff

2 Files Affected:

  • (modified) llvm/lib/MC/MCParser/AsmParser.cpp (+10-15)
  • (removed) llvm/test/MC/ELF/debug-hash-file-empty-dwarf.s (-26)
diff --git a/llvm/lib/MC/MCParser/AsmParser.cpp b/llvm/lib/MC/MCParser/AsmParser.cpp
index 3637d09e00fa14..d15a9a8a36c5a3 100644
--- a/llvm/lib/MC/MCParser/AsmParser.cpp
+++ b/llvm/lib/MC/MCParser/AsmParser.cpp
@@ -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;
@@ -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(
@@ -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;
 }
 
diff --git a/llvm/test/MC/ELF/debug-hash-file-empty-dwarf.s b/llvm/test/MC/ELF/debug-hash-file-empty-dwarf.s
deleted file mode 100644
index cc1c3d1796b6e2..00000000000000
--- a/llvm/test/MC/ELF/debug-hash-file-empty-dwarf.s
+++ /dev/null
@@ -1,26 +0,0 @@
-// RUN: llvm-mc -triple x86_64-unknown-linux-gnu -filetype obj -g -dwarf-version 5 -o %t %s
-// RUN: llvm-dwarfdump -debug-info -debug-line %t | FileCheck %s
-
-// CHECK-NOT: DW_TAG_
-
-// CHECK:      include_directories[ 0] =
-// CHECK-NOT:  include_directories[ 1] =
-// CHECK:      file_names[ 0]:
-// CHECK-NEXT:           name: "/MyTest/Inputs/other.S"
-// CHECK-NEXT:      dir_index: 0
-// CHECK-NOT:  file_names[ 1]:
-
-// RUN: llvm-mc -triple=x86_64 -filetype=obj -g -dwarf-version=5 -fdebug-prefix-map=/MyTest=/src_root %s -o %t.5.o
-// RUN: llvm-dwarfdump -debug-info -debug-line %t.5.o | FileCheck %s --check-prefixes=MAP
-
-// MAP-NOT: DW_TAG_
-
-// MAP:      include_directories[  0] = "{{.*}}"
-// MAP-NEXT: file_names[  0]:
-// MAP-NEXT:            name: "/src_root/Inputs/other.S"
-// MAP-NEXT:       dir_index: 0
-
-# 1 "/MyTest/Inputs/other.S"
-
-.section .data
-.asciz "data"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-precommit-approval PR for CI feedback, not intended for review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants