diff options
author | Zequan Wu <zequanwu@google.com> | 2023-03-30 15:01:21 -0400 |
---|---|---|
committer | Zequan Wu <zequanwu@google.com> | 2023-04-17 13:07:42 -0400 |
commit | ab8f622c79b27bc606da043e8dcbd417b8ade725 (patch) | |
tree | 3bedfa0ddf71791be883538825e865d5f3e78a70 /clang/lib/CodeGen/CGDebugInfo.cpp | |
parent | 676a96f768e1101ed5187c7751e56e1e11ebe593 (diff) | |
download | llvm-ab8f622c79b27bc606da043e8dcbd417b8ade725.zip llvm-ab8f622c79b27bc606da043e8dcbd417b8ade725.tar.gz llvm-ab8f622c79b27bc606da043e8dcbd417b8ade725.tar.bz2 |
[DebugInfo] Fix file path separator when targeting windows.
This fixes two problems:
1. When crossing compiling for windows on linux, source file path in debug info is concatenated with directory by host native separator ('/'). For windows local build, they are concatenated by '\'. This causes non-determinism bug.
The solution here is to let `LangOptions.UseTargetPathSeparator` to control if we should use host native separator or not.
2. Objectfile path in CodeView also uses host native separator when generated.
It's fixed by changing the path separator in `/Fo` to '\' if the path is not an absolute path when adding the `-object-file-name=` flag.
Reviewed By: hans
Differential Revision: https://reviews.llvm.org/D147256
Diffstat (limited to 'clang/lib/CodeGen/CGDebugInfo.cpp')
-rw-r--r-- | clang/lib/CodeGen/CGDebugInfo.cpp | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index cd0fece..5100d6c 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -528,6 +528,7 @@ void CGDebugInfo::CreateCompileUnit() { // Get absolute path name. SourceManager &SM = CGM.getContext().getSourceManager(); auto &CGO = CGM.getCodeGenOpts(); + const LangOptions &LO = CGM.getLangOpts(); std::string MainFileName = CGO.MainFileName; if (MainFileName.empty()) MainFileName = "<stdin>"; @@ -542,9 +543,15 @@ void CGDebugInfo::CreateCompileUnit() { MainFileDir = std::string(MainFile->getDir().getName()); if (!llvm::sys::path::is_absolute(MainFileName)) { llvm::SmallString<1024> MainFileDirSS(MainFileDir); - llvm::sys::path::append(MainFileDirSS, MainFileName); - MainFileName = - std::string(llvm::sys::path::remove_leading_dotslash(MainFileDirSS)); + llvm::sys::path::Style Style = + LO.UseTargetPathSeparator + ? (CGM.getTarget().getTriple().isOSWindows() + ? llvm::sys::path::Style::windows_backslash + : llvm::sys::path::Style::posix) + : llvm::sys::path::Style::native; + llvm::sys::path::append(MainFileDirSS, Style, MainFileName); + MainFileName = std::string( + llvm::sys::path::remove_leading_dotslash(MainFileDirSS, Style)); } // If the main file name provided is identical to the input file name, and // if the input file is a preprocessed source, use the module name for @@ -560,7 +567,6 @@ void CGDebugInfo::CreateCompileUnit() { } llvm::dwarf::SourceLanguage LangTag; - const LangOptions &LO = CGM.getLangOpts(); if (LO.CPlusPlus) { if (LO.ObjC) LangTag = llvm::dwarf::DW_LANG_ObjC_plus_plus; |