r355226 - [DWARF] Make -g with empty assembler source work better.
Paul Robinson via cfe-commits
cfe-commits at lists.llvm.org
Fri Mar 1 12:58:04 PST 2019
Author: probinson
Date: Fri Mar 1 12:58:04 2019
New Revision: 355226
URL: http://llvm.org/viewvc/llvm-project?rev=355226&view=rev
Log:
[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
Modified:
cfe/trunk/test/Misc/cc1as-asm-debug.s
cfe/trunk/tools/driver/cc1as_main.cpp
Modified: cfe/trunk/test/Misc/cc1as-asm-debug.s
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/cc1as-asm-debug.s?rev=355226&r1=355225&r2=355226&view=diff
==============================================================================
--- cfe/trunk/test/Misc/cc1as-asm-debug.s (original)
+++ cfe/trunk/test/Misc/cc1as-asm-debug.s Fri Mar 1 12:58:04 2019
@@ -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"
Modified: cfe/trunk/tools/driver/cc1as_main.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/driver/cc1as_main.cpp?rev=355226&r1=355225&r2=355226&view=diff
==============================================================================
--- cfe/trunk/tools/driver/cc1as_main.cpp (original)
+++ cfe/trunk/tools/driver/cc1as_main.cpp Fri Mar 1 12:58:04 2019
@@ -336,7 +336,7 @@ static bool ExecuteAssembler(AssemblerIn
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(AssemblerIn
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;
More information about the cfe-commits
mailing list