Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[clang] Fix test for case-insensitive absolute includes #76985

Conversation

jansvoboda11
Copy link
Contributor

@jansvoboda11 jansvoboda11 commented Jan 4, 2024

When CMake on Windows is told to generate the build into a directory whose real path has a different drive letter (e.g. due to a symlink), the "clang/test/Lexer/case-insensitive-include-absolute.c" test fails. That happens because because trySimplifyPath() in PPDirectives.cpp finds out there's more than a case difference between the #include path (containing %/t) and the real path, which prevents the diagnostic to fire.

I thought this is only an issue on Windows due to the fact that LIT does not drag the path to the build directory through os.path.realpath() like it does on other systems (see abs_path_preserve_drive() in "llvm/utils/lit/lit/util.py"). However, even after only using os.path.abspath() on a Unix system, build generated into a symlinked directory tests correctly. I assume there must be something else at play, but I don't have the time to dig deeper.

The fix is is fairly straightforward: use the real path in the #include (with %{/t:real}), which removes the non-case difference and unblocks the diagnostic.

When the test was ran via a symlink path (e.g. `ninja -C /symlink/llvm-project/build check-clang`), the diagnostic would not fire, since `%t` path in the include directive would differ in more than just a case from the real path of the header file.
@jansvoboda11 jansvoboda11 marked this pull request as ready for review January 5, 2024 21:41
@llvmbot llvmbot added the clang Clang issues not falling into any other category label Jan 5, 2024
@jansvoboda11 jansvoboda11 merged commit 853b133 into llvm:main Jan 5, 2024
7 checks passed
@llvmbot
Copy link
Collaborator

llvmbot commented Jan 5, 2024

@llvm/pr-subscribers-clang

Author: Jan Svoboda (jansvoboda11)

Changes

When CMake on Windows is told to generate the build into a directory whose real path has a different drive letter (e.g. due to a symlink), the "clang/test/Lexer/case-insensitive-include-absolute.c" test fails. That happens because because trySimplifyPath() in PPDirectives.cpp finds out there's more than a case difference between the #include path (containing %/t) and the real path, which prevents the diagnostic to fire.

I thought this is only an issue on Windows due to the fact that LIT does not drag the path to the build directory through os.path.realpath() like it does on other systems (see abs_path_preserve_drive() in "llvm/utils/lit/lit/util.py"). However, even after only using os.path.abspath() on a Unix system, build generated into a symlinked directory tests correctly. I assume there must be something else at play, but I don't have the time to dig deeper.

The fix is is fairly straightforward: use the real path in the #include (with %{/t:real}), which removes the non-case difference and unblocks the diagnostic.


Full diff: https://github.com/llvm/llvm-project/pull/76985.diff

1 Files Affected:

  • (modified) clang/test/Lexer/case-insensitive-include-absolute.c (+2-2)
diff --git a/clang/test/Lexer/case-insensitive-include-absolute.c b/clang/test/Lexer/case-insensitive-include-absolute.c
index 6247e4808c7fa2..ef9e131c45df59 100644
--- a/clang/test/Lexer/case-insensitive-include-absolute.c
+++ b/clang/test/Lexer/case-insensitive-include-absolute.c
@@ -1,8 +1,8 @@
 // REQUIRES: case-insensitive-filesystem
 
 // RUN: rm -rf %t && split-file %s %t
-// RUN: sed "s|DIR|%/t|g" %t/tu.c.in > %t/tu.c
-// RUN: %clang_cc1 -fsyntax-only %t/tu.c 2>&1 | FileCheck %s --DDIR=%/t
+// RUN: sed "s|DIR|%{/t:real}|g" %t/tu.c.in > %t/tu.c
+// RUN: %clang_cc1 -fsyntax-only %t/tu.c 2>&1 | FileCheck %s -DDIR=%{/t:real}
 
 //--- header.h
 //--- tu.c.in

@jansvoboda11 jansvoboda11 deleted the fix-case-insensitive-include-absolute-test branch January 5, 2024 21:41
justinfargnoli pushed a commit to justinfargnoli/llvm-project that referenced this pull request Jan 28, 2024
When CMake on Windows is told to generate the build into a directory
whose real path has a different drive letter (e.g. due to a symlink),
the "clang/test/Lexer/case-insensitive-include-absolute.c" test fails.
That happens because because `trySimplifyPath()` in `PPDirectives.cpp`
finds out there's more than a case difference between the `#include`
path (containing `%/t`) and the real path, which prevents the diagnostic
to fire.

I thought this is only an issue on Windows due to the fact that LIT does
not drag the path to the build directory through `os.path.realpath()`
like it does on other systems (see `abs_path_preserve_drive()` in
"llvm/utils/lit/lit/util.py"). However, even after only using
`os.path.abspath()` on a Unix system, build generated into a symlinked
directory tests correctly. I assume there must be something else at
play, but I don't have the time to dig deeper.

The fix is is fairly straightforward: use the real path in the
`#include` (with `%{/t:real}`), which removes the non-case difference
and unblocks the diagnostic.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants