From: Paul Robinson Date: Fri, 1 Mar 2019 20:58:04 +0000 (+0000) Subject: [DWARF] Make -g with empty assembler source work better. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8302be4db4e454f45deae6fa8a470db7bc3495d0;p=clang [DWARF] Make -g with empty assembler source work better. 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 --- diff --git a/test/Misc/cc1as-asm-debug.s b/test/Misc/cc1as-asm-debug.s index cd36cad620..a613fbfaeb 100644 --- a/test/Misc/cc1as-asm-debug.s +++ b/test/Misc/cc1as-asm-debug.s @@ -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" diff --git a/tools/driver/cc1as_main.cpp b/tools/driver/cc1as_main.cpp index 0a38e355c7..a234ba3fc1 100644 --- a/tools/driver/cc1as_main.cpp +++ b/tools/driver/cc1as_main.cpp @@ -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;