[PATCH] D54348: Permit multiple .file directives with -g

Brian Cain via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 9 13:08:00 PST 2018


bcain created this revision.
bcain added reviewers: probinson, dyung.
Herald added subscribers: JDevlieghere, hiraditya, aprantl.

PR38994 caught a defect introduced by 340839: multiple .file directives
along with -g would result in an assertion.  This change no longer resets
the implicit '.file 0' and doesn't disable the generation of debug info.


Repository:
  rL LLVM

https://reviews.llvm.org/D54348

Files:
  llvm/lib/MC/MCDwarf.cpp
  llvm/lib/MC/MCParser/AsmParser.cpp
  llvm/test/MC/AsmParser/directive_file-4.s
  llvm/test/MC/AsmParser/directive_file-5.s


Index: llvm/test/MC/AsmParser/directive_file-5.s
===================================================================
--- /dev/null
+++ llvm/test/MC/AsmParser/directive_file-5.s
@@ -0,0 +1,16 @@
+// RUN: not llvm-mc -g -triple i386-unknown-unknown  %s | FileCheck -check-prefix=CHECK-DEBUG %s
+// RUN: llvm-mc  -triple i386-unknown-unknown %s -filetype=obj | obj2yaml | FileCheck -check-prefix=CHECK-DEFAULT %s
+
+// Test for Bug 38994
+// This testcase .... TBD
+
+        .file "xyz.c"
+.text
+
+f1:
+        nop
+        .file 1 "abc.c"
+
+// CHECK-DEBUG: error
+
+// CHECK-DEFAULT-NOT:  - Name:            .debug_info
Index: llvm/test/MC/AsmParser/directive_file-4.s
===================================================================
--- /dev/null
+++ llvm/test/MC/AsmParser/directive_file-4.s
@@ -0,0 +1,31 @@
+// RUN: llvm-mc -g -triple i386-unknown-unknown  %s | FileCheck -check-prefix=CHECK-DEBUG-ASM %s
+// RUN: llvm-mc -triple i386-unknown-unknown  %s | FileCheck -check-prefix=CHECK-DEFAULT %s
+// RUN: llvm-mc -g -triple i386-unknown-unknown %s -filetype=obj | obj2yaml | FileCheck -check-prefix=CHECK-DEBUG-OBJ %s
+
+// Test for Bug 38994
+// This testcase has a single function and two .file directives:
+// one with the [file-num] argument and one without.
+// When compiled with -g, this testcase will not report an error,
+// and generate new debug info.  The '.file 1' directive will be
+// replaced by the assembler-generated '.file 1' directive.
+
+        .file "xyz.c"
+f1:
+        .file 1 "abc.c"
+        nop
+.size f1, .-f1
+
+// CHECK-DEFAULT: .file "xyz.c"
+// CHECK-DEFAULT-NEXT: f1:
+// CHECK-DEFAULT-NEXT: .file 1 "abc.c"
+
+// CHECK-DEBUG-ASM: .file "xyz.c"
+// CHECK-DEBUG-ASM-NEXT: f1:
+// CHECK-DEBUG-ASM-NEXT: .file 1 {{.*}} "directive_file-4.s"
+
+// CHECK-DEBUG-OBJ:  Sections:
+// CHECK-DEBUG-OBJ:  - Name:            .text
+// CHECK-DEBUG-OBJ:  - Name:            .debug_info
+// CHECK-DEBUG-OBJ:  - Name:            .rel.debug_info
+// CHECK-DEBUG-OBJ:    Info:            .debug_info
+// CHECK-DEBUG-OBJ:  Symbols:
Index: llvm/lib/MC/MCParser/AsmParser.cpp
===================================================================
--- llvm/lib/MC/MCParser/AsmParser.cpp
+++ llvm/lib/MC/MCParser/AsmParser.cpp
@@ -3364,14 +3364,6 @@
   if (FileNumber == -1)
     getStreamer().EmitFileDirective(Filename);
   else {
-    // In case there is a -g option as well as debug info from directive .file,
-    // we turn off the -g option, directly use the existing debug info instead.
-    // Also reset any implicit ".file 0" for the assembler source.
-    if (Ctx.getGenDwarfForAssembly()) {
-      Ctx.getMCDwarfLineTable(0).resetRootFile();
-      Ctx.setGenDwarfForAssembly(false);
-    }
-
     MD5::MD5Result *CKMem = nullptr;
     if (HasMD5) {
       CKMem = (MD5::MD5Result *)Ctx.allocate(sizeof(MD5::MD5Result), 1);
Index: llvm/lib/MC/MCDwarf.cpp
===================================================================
--- llvm/lib/MC/MCDwarf.cpp
+++ llvm/lib/MC/MCDwarf.cpp
@@ -576,11 +576,6 @@
   // Get the new MCDwarfFile slot for this FileNumber.
   MCDwarfFile &File = MCDwarfFiles[FileNumber];
 
-  // It is an error to see the same number more than once.
-  if (!File.Name.empty())
-    return make_error<StringError>("file number already allocated",
-                                   inconvertibleErrorCode());
-
   // If any files have embedded source, they all must.
   if (HasSource != (Source != None))
     return make_error<StringError>("inconsistent use of embedded source",


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54348.173429.patch
Type: text/x-patch
Size: 3529 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181109/cd49fc19/attachment.bin>


More information about the llvm-commits mailing list