diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp --- a/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp @@ -1230,6 +1230,17 @@ IncludeDir = IncludeDirectories[Entry.DirIdx - 1].getAsCString().getValue(); } + + // An include directory may be relative to the compilation directory, or may + // be an absolute path itself, similar to the compilation directory. Handle an + // absolute-path include direcctory the same as an absolute-path compilation + // directory. + if (Kind == FileLineInfoKind::RelativeFilePath && !IncludeDir.empty() && + isPathAbsoluteOnWindowsOrPosix(IncludeDir)) { + Result = std::string(llvm::sys::path::filename(FileName)); + return true; + } + // For absolute paths only, include the compilation directory of compile unit. // We know that FileName is not absolute, the only way to have an absolute // path at this point would be if IncludeDir is absolute. diff --git a/llvm/test/tools/llvm-symbolizer/relativenames.s b/llvm/test/tools/llvm-symbolizer/relativenames.s --- a/llvm/test/tools/llvm-symbolizer/relativenames.s +++ b/llvm/test/tools/llvm-symbolizer/relativenames.s @@ -8,11 +8,16 @@ # RUN: llvm-symbolizer 0 --relativenames --obj=%t.o \ # RUN: | FileCheck %s -DDIR=%p --check-prefix=RELATIVENAMES +## Sanity check for default. +# RUN: llvm-symbolizer 0 --obj=%t.o \ +# RUN: | FileCheck %s -DDIR=%p --check-prefix=ABSOLUTENAMES + ## Ensure last option wins. # RUN: llvm-symbolizer 0 --basenames --relativenames --obj=%t.o \ # RUN: | FileCheck %s -DDIR=%p --check-prefix=RELATIVENAMES # RUN: llvm-symbolizer 0 --relativenames --basenames --obj=%t.o \ # RUN: | FileCheck %s --check-prefix=BASENAMES -# RELATIVENAMES: [[DIR]]{{\\|/}}relativenames.s:4 +# ABSOLUTENAMES: [[DIR]]{{\\|/}}relativenames.s:4 +# RELATIVENAMES: {{^}}relativenames.s:4 # BASENAMES: {{^}}relativenames.s:4