<div dir="ltr">Still breaking the same testcase:<div><br></div><div><div>echristo@athyra ~/t/debug> cat > foo.c</div><div>void g() {}</div><div>echristo@athyra ~/t/debug> ~/builds/build-llvm-release-asserts/bin/clang -g foo.c -S -o foo.s</div><div>echristo@athyra ~/t/debug> ~/builds/build-llvm-release-asserts/bin/clang -g foo.s -c</div><div>foo.s:8:2: error: file number already allocated</div><div>        .file   1 "foo.c"</div><div>        ^<br><br>Can you revert please?</div></div><div><br></div><div>-eric</div></div><br><div class="gmail_quote"><div dir="ltr">On Thu, Mar 8, 2018 at 2:42 PM Paul Robinson via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: probinson<br>
Date: Thu Mar  8 14:39:47 2018<br>
New Revision: 327073<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=327073&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=327073&view=rev</a><br>
Log:<br>
[DWARF] Fix mixing assembler -g with DWARF .file directives.<br>
<br>
We were effectively overriding an explicit '.file' directive with info<br>
for the assembler source.  That shouldn't happen.<br>
<br>
Fixes PR36636.<br>
<br>
Differential Revision: <a href="https://reviews.llvm.org/D44265" rel="noreferrer" target="_blank">https://reviews.llvm.org/D44265</a><br>
<br>
Modified:<br>
    llvm/trunk/lib/MC/MCParser/AsmParser.cpp<br>
    llvm/trunk/test/MC/AsmParser/directive_file-2.s<br>
<br>
Modified: llvm/trunk/lib/MC/MCParser/AsmParser.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/AsmParser.cpp?rev=327073&r1=327072&r2=327073&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/AsmParser.cpp?rev=327073&r1=327072&r2=327073&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/MC/MCParser/AsmParser.cpp (original)<br>
+++ llvm/trunk/lib/MC/MCParser/AsmParser.cpp Thu Mar  8 14:39:47 2018<br>
@@ -311,6 +311,11 @@ private:<br>
   }<br>
   static void DiagHandler(const SMDiagnostic &Diag, void *Context);<br>
<br>
+  /// Should we emit DWARF describing this assembler source?  (Returns false if<br>
+  /// the source has .file directives, which means we don't want to generate<br>
+  /// info describing the assembler source itself.)<br>
+  bool enabledGenDwarfForAssembly();<br>
+<br>
   /// \brief Enter the specified file. This returns true on failure.<br>
   bool enterIncludeFile(const std::string &Filename);<br>
<br>
@@ -824,6 +829,19 @@ const AsmToken &AsmParser::Lex() {<br>
   return *tok;<br>
 }<br>
<br>
+bool AsmParser::enabledGenDwarfForAssembly() {<br>
+  // Check whether the user specified -g.<br>
+  if (!getContext().getGenDwarfForAssembly())<br>
+    return false;<br>
+  // If we haven't encountered any .file directives (which would imply that<br>
+  // the assembler source was produced with debug info already) then emit one<br>
+  // describing the assembler source file itself.<br>
+  if (getContext().getGenDwarfFileNumber() == 0)<br>
+    getContext().setGenDwarfFileNumber(getStreamer().EmitDwarfFileDirective(<br>
+        0, StringRef(), getContext().getMainFileName()));<br>
+  return true;<br>
+}<br>
+<br>
 bool AsmParser::Run(bool NoInitialTextSection, bool NoFinalize) {<br>
   // Create the initial section, if requested.<br>
   if (!NoInitialTextSection)<br>
@@ -837,7 +855,9 @@ bool AsmParser::Run(bool NoInitialTextSe<br>
   SmallVector<AsmRewrite, 4> AsmStrRewrites;<br>
<br>
   // If we are generating dwarf for assembly source files save the initial text<br>
-  // section and generate a .file directive.<br>
+  // section.  (Don't use enabledGenDwarfForAssembly() here, as we aren't<br>
+  // emitting any actual debug info yet and haven't had a chance to parse any<br>
+  // embedded .file directives.)<br>
   if (getContext().getGenDwarfForAssembly()) {<br>
     MCSection *Sec = getStreamer().getCurrentSectionOnly();<br>
     if (!Sec->getBeginSymbol()) {<br>
@@ -848,8 +868,6 @@ bool AsmParser::Run(bool NoInitialTextSe<br>
     bool InsertResult = getContext().addGenDwarfSection(Sec);<br>
     assert(InsertResult && ".text section should not have debug info yet");<br>
     (void)InsertResult;<br>
-    getContext().setGenDwarfFileNumber(getStreamer().EmitDwarfFileDirective(<br>
-        0, StringRef(), getContext().getMainFileName()));<br>
   }<br>
<br>
   // While we have input, parse each statement.<br>
@@ -1784,7 +1802,7 @@ bool AsmParser::parseStatement(ParseStat<br>
<br>
     // If we are generating dwarf for assembly source files then gather the<br>
     // info to make a dwarf label entry for this label if needed.<br>
-    if (getContext().getGenDwarfForAssembly())<br>
+    if (enabledGenDwarfForAssembly())<br>
       MCGenDwarfLabelEntry::Make(Sym, &getStreamer(), getSourceManager(),<br>
                                  IDLoc);<br>
<br>
@@ -2153,7 +2171,7 @@ bool AsmParser::parseStatement(ParseStat<br>
<br>
   // If we are generating dwarf for the current section then generate a .loc<br>
   // directive for the instruction.<br>
-  if (!ParseHadError && getContext().getGenDwarfForAssembly() &&<br>
+  if (!ParseHadError && enabledGenDwarfForAssembly() &&<br>
       getContext().getGenDwarfSectionSyms().count(<br>
           getStreamer().getCurrentSectionOnly())) {<br>
     unsigned Line;<br>
@@ -3336,15 +3354,12 @@ bool AsmParser::parseDirectiveFile(SMLoc<br>
     }<br>
     // If there is -g option as well as debug info from directive file,<br>
     // we turn off -g option, directly use the existing debug info instead.<br>
-    if (getContext().getGenDwarfForAssembly())<br>
-      getContext().setGenDwarfForAssembly(false);<br>
-    else {<br>
-      Expected<unsigned> FileNumOrErr = getStreamer().tryEmitDwarfFileDirective(<br>
-          FileNumber, Directory, Filename, CKMem, Source);<br>
-      if (!FileNumOrErr)<br>
-        return Error(DirectiveLoc, toString(FileNumOrErr.takeError()));<br>
-      FileNumber = FileNumOrErr.get();<br>
-    }<br>
+    getContext().setGenDwarfForAssembly(false);<br>
+    Expected<unsigned> FileNumOrErr = getStreamer().tryEmitDwarfFileDirective(<br>
+        FileNumber, Directory, Filename, CKMem, Source);<br>
+    if (!FileNumOrErr)<br>
+      return Error(DirectiveLoc, toString(FileNumOrErr.takeError()));<br>
+    FileNumber = FileNumOrErr.get();<br>
   }<br>
<br>
   return false;<br>
<br>
Modified: llvm/trunk/test/MC/AsmParser/directive_file-2.s<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/AsmParser/directive_file-2.s?rev=327073&r1=327072&r2=327073&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/AsmParser/directive_file-2.s?rev=327073&r1=327072&r2=327073&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/test/MC/AsmParser/directive_file-2.s (original)<br>
+++ llvm/trunk/test/MC/AsmParser/directive_file-2.s Thu Mar  8 14:39:47 2018<br>
@@ -1,4 +1,4 @@<br>
-// RUN: llvm-mc -triple i386-unknown-unknown %s | FileCheck %s<br>
+// RUN: llvm-mc -g -triple i386-unknown-unknown %s | FileCheck %s<br>
 // Test for Bug 11740<br>
 // This testcase has two directive files,<br>
 // when compiled with -g, this testcase will not report error,<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div>