This is an archive of the discontinued LLVM Phabricator instance.

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

Authored by ayzhao on Apr 4 2022, 5:08 PM.

Details

Reviewers
None
Summary

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

Diff Detail

Event Timeline

ayzhao created this revision.Apr 4 2022, 5:08 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 4 2022, 5:08 PM
Herald added a subscriber: dexonsmith. · View Herald Transcript
ayzhao requested review of this revision.Apr 4 2022, 5:08 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 4 2022, 5:08 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
ayzhao abandoned this revision.Apr 4 2022, 5:10 PM

Accidental duplicate of D122766