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
PCH not detected using Clang and CMake 3.16 #539
Comments
I tried to overcome the --- src/ccache.cpp
+++ src/ccache.cpp
@@ -2521,6 +2521,13 @@ cc_process_args(ArgsInfo& args_info,
continue;
}
+ // Allow parameters to compiler passed via -Xclang to be analyzed by
+ // ccache's logic like -Xclang -emit-pch
+ if (str_eq(argv[i], "-Xclang") && i + 2 < argc) {
+ args_add(common_args, argv[i]);
+ ++i;
+ }
+
if (str_eq(argv[i], "-fpch-preprocess") || str_eq(argv[i], "-emit-pch")
|| str_eq(argv[i], "-emit-pth")) {
found_fpch_preprocess = true;
@@ -2971,11 +2978,17 @@ cc_process_args(ArgsInfo& args_info,
return false;
}
- if (!detect_pch(argv[i], argv[i + 1], &found_pch)) {
+ // Skip the -Xclang -include -Xclang path/to/file cases
+ int next = 1;
+ if (str_eq(argv[i + 1], "-Xclang") && i + 3 < argc) {
+ next = 2;
+ }
+
+ if (!detect_pch(argv[i], argv[i + next], &found_pch)) {
return false;
}
- std::string relpath = make_relative_path(argv[i + 1]);
+ std::string relpath = make_relative_path(argv[i + next]);
if (compopt_affects_cpp(argv[i])) {
args_add(cpp_args, argv[i]);
args_add(cpp_args, relpath.c_str()); Unfortunately, as seen in ccache.log I've hit
In the first case when the pch file is created, the header In the second case, I'll have to dig further in oder to make ccache happy. This bug affects all Clang compilers (default on macOS) when used with CMake. |
Thanks for the bug report. This would be good to have fixed. For my own understanding: Do you happen to know why CMake uses |
Clang doesn't seem to have
Produces a 396 bytes file with Clang9 on Windows, whilst:
Produces a 7.138.760 bytes file, and it works no matter how many times you run the command. The
will generate the second time a 13.228 bytes file, and the 3rd time will issue an error:
This is due to Clang doing chained pchs. ccache would have to deal with |
Why not just use normal way of pch generation, namely
? |
Clang has a bug with the GCC mode, see https://gitlab.kitware.com/cmake/cmake/issues/19786 |
Thanks. Was that bug reported to bugs.llvm.org? |
I don't think we reported to llvm, since we found a workaround quickly, which works with all existing Clang versions. |
IMHO it would be better to get Clang bug fixed instead of introducing unnecessary complexity in every project around it. More so as that bug affect only one platform. |
Seems like you've used the same |
This is not a Windows specific bug. Clang has the same behavior on all platforms. https://gitlab.kitware.com/cmake/cmake/issues/19786 was mostly tested with AppleClang on macOS. |
Sorry, I didn't read issue carefully. |
I recently hit an error of reusing PCH with different arg in Halide. Wondering if it's related to this issue. |
Hi,
PS: I don't know what the distinction in |
Another problem will then be that with CMake 3.17.3, the command line looks like |
@ahasselbring thank you for the work on this issue! I took the latest master, build it with MinGW 8.1 ( I used CMake 3.18.0. And to my surprise...:
I expected 100% hit rate. For sloppiness I tried ccache-master-clang9.log and ccache-master-clang9-include_mtime.log. The weird part is that the same happend with MinGW GCC 8.1. I suspect there is a problem with how precompiled headers are handled in master. If I disable the precompiled headers in CMake, I get 100% hit rate for both compilers. |
|
Add |
By the way, I just saw in the original bug report that with gcc there is also only a preprocessed hit and not a direct hit. You can get preprocessed PCH hits with clang now if you add |
How to reproduce
CMake 3.16 has gotten support for PCHs. I've build a "Hello World" application and build it with MinGW-GCC 8.1 (gcc) and LLVM-MinGW 9.0 (clang).
CMakeLists.txt
main.cpp
test.cmake
I've build the application running
cmake -P test.cmake
.Actual behavior
For gcc at the end I've got in the statistics:
In the ccache.log file I could see entries like:
For clang I've got:
In the ccache.log I couldn't see any pch log entries.
Expected behavior
I expected ccache to detect and handle pch file for Clang.
Environment
ccache version 3.7.7
CMake PCH options
For Clang CMake uses the following format for pch file creation and usage:
The text was updated successfully, but these errors were encountered: