[PATCH] D123101: [clang] Use forward slash as the path separator for Windows in __FILE__, __builtin_FILE(), and std::source_location

Alan Zhao via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 4 17:08:52 PDT 2022


ayzhao created this revision.
Herald added a subscriber: dexonsmith.
Herald added a project: All.
ayzhao requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

When targeting Windows, the path separator used when targeting Windows
depends on the build environment when Clang _itself_ is built. This
leads to inconsistencies in Chrome builds where Clang running on
non-Windows environments uses the forward slash (/) path separator
while Clang running on Windows builds uses the backslash (\) path
separator. To fix this, we make Clang use forward slashes whenever it is
targeting Windows.

We chose to use forward slashes instead of backslashes in builds
targeting Windows because according to the C standard, backslashes in
\#include directives result in undefined behavior[1]. We may change this
decision though depending on the review.

[0]: https://crbug.com/1310767
[1]: https://stackoverflow.com/a/5790259


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123101

Files:
  clang/include/clang/Basic/LangOptions.h
  clang/include/clang/Lex/Preprocessor.h
  clang/lib/AST/Expr.cpp
  clang/lib/Basic/LangOptions.cpp
  clang/lib/Lex/PPMacroExpansion.cpp
  clang/test/Preprocessor/file_test_windows.c

STAMPS
actor(@ayzhao) application(Differential) author(@ayzhao) herald(H223) herald(H337) herald(H423) herald(H576) herald(H688) herald(H864) monogram(D123101) object-type(DREV) phid(PHID-DREV-zhl7ek66tkkebw7mewsb) revision-repository(rG) revision-status(needs-review) subscriber(@cfe-commits) subscriber(@dexonsmith) tag(#all) tag(#clang) via(conduit)

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D123101.420349.patch
Type: text/x-patch
Size: 6135 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220405/3cd58acd/attachment.bin>


More information about the cfe-commits mailing list