Skip to content

Commit 7599381

Browse files
committed
Use windows baskslash on anonymous tag locations if using MSVCFormatting and it's not absolute path.
This fixes a nondeterminism on debug info when building on windows natively vs cross building to windows. [1] https://github.com/llvm/llvm-project/blob/llvmorg-17-init/clang/lib/Lex/HeaderSearch.cpp#L465 Differential Revision: https://reviews.llvm.org/D150817
1 parent cb16b33 commit 7599381

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed

clang/lib/AST/TypePrinter.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,11 +1385,18 @@ void TypePrinter::printTag(TagDecl *D, raw_ostream &OS) {
13851385
if (PLoc.isValid()) {
13861386
OS << " at ";
13871387
StringRef File = PLoc.getFilename();
1388+
llvm::SmallString<1024> WrittenFile(File);
13881389
if (auto *Callbacks = Policy.Callbacks)
1389-
OS << Callbacks->remapPath(File);
1390-
else
1391-
OS << File;
1392-
OS << ':' << PLoc.getLine() << ':' << PLoc.getColumn();
1390+
WrittenFile = Callbacks->remapPath(File);
1391+
// Fix inconsistent path separator created by
1392+
// clang::DirectoryLookup::LookupFile when the file path is relative
1393+
// path.
1394+
llvm::sys::path::Style Style =
1395+
!llvm::sys::path::is_absolute(WrittenFile) && Policy.MSVCFormatting
1396+
? llvm::sys::path::Style::windows_backslash
1397+
: llvm::sys::path::Style::native;
1398+
llvm::sys::path::native(WrittenFile, Style);
1399+
OS << WrittenFile << ':' << PLoc.getLine() << ':' << PLoc.getColumn();
13931400
}
13941401
}
13951402

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#include "Inputs/debug-info-slash.h"
2+
int main() { a(); return 0; }
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
template <typename... T>
2+
void f1() {}
3+
void a() {
4+
auto Lambda = [] {};
5+
f1<decltype(Lambda)>();
6+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
RUN: rm -rf %t-dir
2+
RUN: mkdir -p %t-dir/header/Inputs
3+
RUN: cp %S/Inputs/debug-info-slash.cpp %t-dir/
4+
RUN: cp %S/Inputs/debug-info-slash.h %t-dir/header/Inputs
5+
RUN: cd %t-dir
6+
RUN: %clang -target x86_64-pc-win32 -emit-llvm -S -g %t-dir/debug-info-slash.cpp -Iheader -o - | FileCheck --check-prefix=WIN %s
7+
RUN: %clang -target x86_64-linux-gnu -emit-llvm -S -g %t-dir/debug-info-slash.cpp -Iheader -o - | FileCheck --check-prefix=LINUX %s
8+
9+
WIN: lambda at header\\Inputs\\debug-info-slash.h
10+
LINUX: lambda at header/Inputs/debug-info-slash.h

0 commit comments

Comments
 (0)