From 2474f04f67a34476c16316ba0299237c3e6df6b0 Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Thu, 26 May 2016 00:22:26 +0000 Subject: [PATCH] PR11740: Disable assembly debug info when assembly already contains line directives If there is already debug info in the assembly file, and user hope to use -g option for compiling, we think we should not directly report an error. According to what GNU assembler did, it just reused the debug info in the assembly file, and turned off the DEBUG_TYPE option so that there will be no new debug info emitted by assembler. This fix is just as what GNU assembler did. The concern is the situation that there are two .text sections in the assembly file, one with debug info and the other one without. Currently with this fix, the assembler will no longer generate any debug info for the second .text section. And this is what GNU assembler exactly did for this situation. So I think this still make some sense. Patch by Zhizhou Yang! Differential Revision: http://reviews.llvm.org/D20002 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@270806 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/MCParser/AsmParser.cpp | 9 ++++----- test/MC/AsmParser/directive_file-2.s | 11 +++++++++++ test/MC/AsmParser/directive_file-errors.s | 9 --------- 3 files changed, 15 insertions(+), 14 deletions(-) create mode 100644 test/MC/AsmParser/directive_file-2.s delete mode 100644 test/MC/AsmParser/directive_file-errors.s diff --git a/lib/MC/MCParser/AsmParser.cpp b/lib/MC/MCParser/AsmParser.cpp index 7da00e89d78..5de8c7d603a 100644 --- a/lib/MC/MCParser/AsmParser.cpp +++ b/lib/MC/MCParser/AsmParser.cpp @@ -3001,12 +3001,11 @@ bool AsmParser::parseDirectiveFile(SMLoc DirectiveLoc) { if (FileNumber == -1) getStreamer().EmitFileDirective(Filename); else { + // If there is -g option as well as debug info from directive file, + // we turn off -g option, directly use the existing debug info instead. if (getContext().getGenDwarfForAssembly()) - Error(DirectiveLoc, - "input can't have .file dwarf directives when -g is " - "used to generate dwarf debug info for assembly code"); - - if (getStreamer().EmitDwarfFileDirective(FileNumber, Directory, Filename) == + getContext().setGenDwarfForAssembly(false); + else if (getStreamer().EmitDwarfFileDirective(FileNumber, Directory, Filename) == 0) Error(FileNumberLoc, "file number already allocated"); } diff --git a/test/MC/AsmParser/directive_file-2.s b/test/MC/AsmParser/directive_file-2.s new file mode 100644 index 00000000000..ff6df5116ad --- /dev/null +++ b/test/MC/AsmParser/directive_file-2.s @@ -0,0 +1,11 @@ +// RUN: llvm-mc -triple i386-unknown-unknown %s | FileCheck %s +// Test for Bug 11740 +// This testcase has two directive files, +// when compiled with -g, this testcase will not report error, +// but keep the debug info existing in the assembly file. + + .file "hello" + .file 1 "world" + +// CHECK: .file "hello" +// CHECK: .file 1 "world" diff --git a/test/MC/AsmParser/directive_file-errors.s b/test/MC/AsmParser/directive_file-errors.s deleted file mode 100644 index 5ae2bbe8005..00000000000 --- a/test/MC/AsmParser/directive_file-errors.s +++ /dev/null @@ -1,9 +0,0 @@ -// RUN: not llvm-mc -g -triple i386-unknown-unknown %s 2> %t.err | FileCheck %s -// RUN: FileCheck --check-prefix=CHECK-ERRORS %s < %t.err -// Test for Bug 11740 - - .file "hello" - .file 1 "world" - -// CHECK: .file "hello" -// CHECK-ERRORS:6:9: error: input can't have .file dwarf directives when -g is used to generate dwarf debug info for assembly code -- 2.11.0