]> granicus.if.org Git - clang/commitdiff
[DWARF] Make -g with empty assembler source work better.
authorPaul Robinson <paul.robinson@sony.com>
Fri, 1 Mar 2019 20:58:04 +0000 (20:58 +0000)
committerPaul Robinson <paul.robinson@sony.com>
Fri, 1 Mar 2019 20:58:04 +0000 (20:58 +0000)
This was sometimes causing clang or llvm-mc to crash, and in other
cases could emit a bogus DWARF line-table header. I did an interim
patch in r352541; this patch should be a cleaner and more complete
fix, and retains the test.

Addresses PR40538.

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

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

test/Misc/cc1as-asm-debug.s
tools/driver/cc1as_main.cpp

index cd36cad6206d1c73597c170b6747a0db1d5d5fdf..a613fbfaeb4889955aae988978ce88031e04f163 100644 (file)
@@ -8,4 +8,5 @@
 // CHECK: {{\.}}section .debug_info
 // CHECK: {{\.}}section .debug_info
 // CHECK-NOT: {{\.}}section
-// CHECK: .ascii "comment.s"
+// Look for this as a relative path.
+// CHECK: .ascii "{{[^\\/].*}}comment.s"
index 0a38e355c7ae4bbc7ad13e322da3fea69e732989..a234ba3fc1bd38c581111d789ff3949b7fad95b3 100644 (file)
@@ -336,7 +336,7 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts,
   SourceMgr SrcMgr;
 
   // Tell SrcMgr about this buffer, which is what the parser will pick up.
-  SrcMgr.AddNewSourceBuffer(std::move(*Buffer), SMLoc());
+  unsigned BufferIndex = SrcMgr.AddNewSourceBuffer(std::move(*Buffer), SMLoc());
 
   // Record the location of the include directories so that the lexer can find
   // it later.
@@ -393,12 +393,21 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts,
     Ctx.setDwarfDebugProducer(StringRef(Opts.DwarfDebugProducer));
   if (!Opts.DebugCompilationDir.empty())
     Ctx.setCompilationDir(Opts.DebugCompilationDir);
+  else {
+    // If no compilation dir is set, try to use the current directory.
+    SmallString<128> CWD;
+    if (!sys::fs::current_path(CWD))
+      Ctx.setCompilationDir(CWD);
+  }
   if (!Opts.DebugPrefixMap.empty())
     for (const auto &KV : Opts.DebugPrefixMap)
       Ctx.addDebugPrefixMapEntry(KV.first, KV.second);
   if (!Opts.MainFileName.empty())
     Ctx.setMainFileName(StringRef(Opts.MainFileName));
   Ctx.setDwarfVersion(Opts.DwarfVersion);
+  if (Opts.GenDwarfForAssembly)
+    Ctx.setGenDwarfRootFile(Opts.InputFile,
+                            SrcMgr.getMemoryBuffer(BufferIndex)->getBuffer());
 
   // Build up the feature string from the target feature list.
   std::string FS;