]> granicus.if.org Git - llvm/commitdiff
[MC] Don't error on numberless .file directives on MachO
authorReid Kleckner <rnk@google.com>
Tue, 5 Feb 2019 21:14:09 +0000 (21:14 +0000)
committerReid Kleckner <rnk@google.com>
Tue, 5 Feb 2019 21:14:09 +0000 (21:14 +0000)
Summary:
Before r349976, MC ignored such directives when producing an object file
and asserted when re-producing textual assembly output. I turned this
assertion into a hard error in both cases in r349976, but this makes it
unnecessarily difficult to write a single assembly file that supports
both MachO and other object formats that support .file. A user reported
this as PR40578, and we decided to go back to ignoring the directive.

Fixes PR40578

Reviewers: mstorsjo

Subscribers: hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D57772

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@353218 91177308-0d34-0410-b5e6-96231b3b80d8

lib/MC/MCParser/AsmParser.cpp
test/MC/MachO/file-single.s [deleted file]
test/MC/MachO/file.s

index b2ff1e1dc472c057d67a242f063c33db1d9e457e..a66a4eb29afc6864f5e8167ec71905de86449c12 100644 (file)
@@ -3370,10 +3370,11 @@ bool AsmParser::parseDirectiveFile(SMLoc DirectiveLoc) {
   }
 
   if (FileNumber == -1) {
-    if (!getContext().getAsmInfo()->hasSingleParameterDotFile())
-      return Error(DirectiveLoc,
-                   "target does not support '.file' without a number");
-    getStreamer().EmitFileDirective(Filename);
+    // Ignore the directive if there is no number and the target doesn't support
+    // numberless .file directives. This allows some portability of assembler
+    // between different object file formats.
+    if (getContext().getAsmInfo()->hasSingleParameterDotFile())
+      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.
diff --git a/test/MC/MachO/file-single.s b/test/MC/MachO/file-single.s
deleted file mode 100644 (file)
index 747af22..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-// RUN: not llvm-mc -triple i386-apple-darwin9 %s -o /dev/null 2>&1 | FileCheck %s
-
-// Previously this crashed MC.
-
-// CHECK: error: target does not support '.file' without a number
-
-        .file "dir/foo"
-        nop
index 3ddfb2efe2246803e8a9a489ec5f31fccd3c5963..eddbb599d97a27ed9455d93073d73a4aab5767ae 100644 (file)
@@ -1,5 +1,8 @@
 // RUN: llvm-mc -triple i386-apple-darwin9 %s -filetype=obj -o - | llvm-readobj -s -section-data | FileCheck %s
 
+// This number-less file directive is ignored on MachO.
+        .file "bar/baz.s"
+
         .file  1 "dir/foo"
         nop