[clang] [clang][lex] Fix non-portability diagnostics with absolute path (PR #74782)

Jan Svoboda via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 8 13:34:41 PST 2023


jansvoboda11 wrote:

My first version of the test put backslashes into the source file (i.e. `#include "C:\foo\bar"`) which doesn't really work, because Clang treats those as string escape sequences. Instead of trying to replace `\` with `\\` in the test, I chose to use forward slashes, which should be fine.

Interestingly, that prevented Clang to diagnose the case mismatch. That's because in `trySimplifyPath()`, any path component that differs from the "real path" component in anything else that case prevents the diagnostic. Importantly, this also applies to mismatching separators (e.g. 'C:/' in source, 'C:\' in real path). I don't think that's intended or reasonable, so I pushed a fix that allows the diagnostic to be emitted regardless of separator differences.

Note that the diagnostic won't suggest fixing up the separators themselves, since those get inherited from the in-source spelling, not from the real path.

https://github.com/llvm/llvm-project/pull/74782


More information about the cfe-commits mailing list