This is an archive of the discontinued LLVM Phabricator instance.

Fix pr31836 on Windows too, and correctly handle repeated separators.
ClosedPublic

Authored by thakis on Apr 30 2020, 5:48 PM.

Details

Summary

The approach in D30000 assumes that the '/' returned by path::begin()
is the first element for absolute paths, but that's not true on
Windows.

Also, on Windows backslashes in include lines often end up escaped
so that there are two of them. Having backslashes in include lines
is undefined behavior in most cases and implementation-defined
behavior in C++20, but since clang treats it as normal repeated
path separators, the diagnostic should too.

Unbreaks -Wnonportable-include-path for absolute paths on Windows,
and unbreaks it on non-Windows in the case of absolute paths with
repeated directory separators.

This affects e.g. the #include __FILE__ technique if the file
passed to clang has the wrong case for the drive letter. Before:

C:\src\llvm-project>bin\clang-cl.exe c:\src\llvm-project\test.cc
c:\\src\\llvm-project\\test.cc(4,10): warning: non-portable path to file
    '"c\\srccllvm-projectctest.cc.'; specified path differs in case from
    file name on disk [-Wnonportable-include-path]
     ^

Now:

C:\src\llvm-project> out\gn\bin\clang-cl c:\src\llvm-project\test.cc
c:\\src\\llvm-project\\test.cc(4,10): warning: non-portable path to file
    '"C:\\src\\llvm-project\\test.cc"'; specified path differs in case from
    file name on disk [-Wnonportable-include-path]
     ^

Diff Detail

Event Timeline

thakis created this revision.Apr 30 2020, 5:48 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 30 2020, 5:48 PM
thakis updated this revision to Diff 261481.May 1 2020, 9:52 AM
thakis edited the summary of this revision. (Show Details)
thakis edited the summary of this revision. (Show Details)
amccarth accepted this revision.May 1 2020, 10:33 AM
amccarth added a subscriber: amccarth.

OK as is, but please consider re-using llvm::sys::path to distinguish separators.

Please also check that there are no regressions in the clang VFS tests.

clang/lib/Lex/PPDirectives.cpp
2118

Can you re-use llvm::sys::path::is_separator instead of inventing a new thing? You can explicitly pass llvm::path::Style::windows if the Microsoft extensions are enabled. Otherwise let it default to llvm::path::Style::native.

This revision is now accepted and ready to land.May 1 2020, 10:33 AM
thakis closed this revision.May 1 2020, 11:17 AM
thakis marked an inline comment as done.

Thanks!