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
clangd 17 regression: response files are not expanded when using command inference #69690
Comments
@llvm/issue-subscribers-clangd Author: None (drcxd)
Hello,
I have upgraded to 17.0.X, but I found that clangd reports that some of the header files cannot be found. However, downgrade back to 16.0.6, the error disappears. All the other settings of the project are the same. I only replaced the clangd binary from 16.0.6 to 17.0.2 or 17.0.3, then the server reports that the header files are missing, which actually, of course, are not. I have read 17.0.1 release notes but found nothing helpful. Any help would be appreciated. Otherwise, I can only stay in clangd 16.0.6 forever. That would be really sad for me. |
hi @drcxd can you provide some more details so that we can investigate the issue? https://clangd.llvm.org/troubleshooting#gathering-logs explains how to gather some bare minimum. It'd be great if you can also mention which header is not found, and its location on your system. |
Hello @kadircet Here is the log:
The first missing header file is
The compile instruction for the file I opened is:
In
Notice that the last line is the including path which contains the |
I noticed that the problem is gone in release 17.0.4, so I'll just close this issue. |
I was wrong. The issue persists in 17.0.4. Sorry. |
A new update: with clangd and clang 16.0.6, when I try to complete at a certain point, the completion failed, I have the following error messages:
However, in my editor, clangd does not report such a file not found error. |
New update: I find that if I open X.h first, then the server reports that a header file included in X.h is missing. If I open X.h after I have opened X.cpp, then the header file missing error is gone. Is that when only the header file is opened, the server does not know which .cpp file includes it and thus does not know the corresponding compile instruction, which contains the including directory? But how does this problem not manifest in previous versions? I have used clangd on the same project for about 2 years and have only experienced such issue after upgrade to 17.0.X. |
Yes, that seems likely to be the explanation. When a header is opened, clangd first checks to see if it's included by an open file, if so the open file's compile command is used to process the header. If not, clangd will pick some other compile command from |
Hello, @HighCommander4 , I have posted the log in a previous reply. I excerpt part of the log I assume that is related to this problem here:
In the log file, I can not see clangd picked any compile command from |
This line:
is saying that clangd is using the command of |
It would be interesting to compare the logs from the two scenarios, to see what is different. |
This is the log when I only open
This is the log when I open
It looks like in 16.0.6, even if only the header file is opened, the flags can be correctly inferred from the compile instruction of the .cpp file. In 17.0.4, only after the .cpp file has opened, the flags can be correctly inferred. |
I wonder if this is somehow a regression from https://reviews.llvm.org/D143436, which was a change made between clangd 16 and clangd 17, and moved around the code for adding the contents of the response file (the cc @dmpolukhin if you have any ideas |
I was able to reproduce this regression on Linux with the following reproduction steps:
I confirmed via a local revert that https://reviews.llvm.org/D143436 is indeed what regressed this. @dmpolukhin, as the author of the regressing patch, could you take a look at this please? |
Since I'm seeing a number of users run into this issue, summarizing the workarounds I'm currently aware of:
|
Sorry for being late here, for some reason I didn't receive the notification. I'll take a look to this issue. |
@HighCommander4 Response files stop being expanded because inference process removes all unknown arguments and extra input files (response file is treated as extra input in this case). In the past the expansion was happening before inference and it is the right order because during inference we check for driver mode, source type, etc. they might be hidden inside the response file so all response files have to be expanded before the inference. Therefore we have following options:
Please let me know what do you think is the best option to resolve this issue. |
Summary: After https://reviews.llvm.org/D143436 response files stopped working with CDB interpolation. It has happened because interpolation removes all unknwn flags and extra input files. Response file is treated as an extra input because it is not a flag. Moreover inference needs full command line for driver mode and file type detection so all response files have to be expanded for correct inference. This patch implements the simplest approach that add extra response file expansion before inference. Response file expansion in CommandMangler keep working for CDB pushed via LSP and will do nothing if all response files are already expanded. Test Plan: TBD Reviewers: Subscribers: Tasks: llvm#69690 Tags:
Summary: After https://reviews.llvm.org/D143436 response files stopped working with CDB interpolation. It has happened because interpolation removes all unknwn flags and extra input files. Response file is treated as an extra input because it is not a flag. Moreover inference needs full command line for driver mode and file type detection so all response files have to be expanded for correct inference. This patch partially reverts D143436 and add additional response file expansion in OverlayCDB for CDBs pushed via LSP. Test Plan: unittests Reviewers: Subscribers: Tasks: llvm#69690 Tags:
Summary: After https://reviews.llvm.org/D143436 response files stopped working with CDB interpolation. It has happened because interpolation removes all unknwn flags and extra input files. Response file is treated as an extra input because it is not a flag. Moreover inference needs full command line for driver mode and file type detection so all response files have to be expanded for correct inference. This patch partially reverts D143436 and add additional response file expansion in OverlayCDB for CDBs pushed via LSP. Test Plan: unittests Tasks: llvm#69690
Summary: After https://reviews.llvm.org/D143436 response files stopped working with CDB interpolation. It has happened because interpolation removes all unknown flags and extra input files. Response file is treated as an extra input because it is not a flag. Moreover inference needs full command line for driver mode and file type detection so all response files have to be expanded for correct inference. This patch partially reverts D143436 and add additional response file expansion in OverlayCDB for CDBs pushed via LSP. Test Plan: check-clangd Tasks: #69690
Fixed by #75753. Thank you, @dmpolukhin! |
Will the next release include this fix? |
Yes, clangd 18. |
I'm trying to use the second workaround but it has no effect (compile_commands.json still contain Where did you get this variable name from? |
I saw it in places like this StackOverflow answer, and I see it referenced in the CMake source, but I don't have deeper familiarity with it, so I'm not sure why it might not be working (you might have more luck asking that in a CMake forum). |
Summary: After https://reviews.llvm.org/D143436 response files stopped working with CDB interpolation. It has happened because interpolation removes all unknown flags and extra input files. Response file is treated as an extra input because it is not a flag. Moreover inference needs full command line for driver mode and file type detection so all response files have to be expanded for correct inference. This patch partially reverts D143436 and add additional response file expansion in OverlayCDB for CDBs pushed via LSP. Test Plan: check-clangd Tasks: llvm/llvm-project#69690
I'm on clangd 17.0.6 and had same issue in vscode. My temporary workaround was: set(CMAKE_CXX_USE_RESPONSE_FILE_FOR_INCLUDES OFF) clangd was not expanding rsp file which contained include directories for cmake's FetchContent output (I imported C++ fmtlib) When these settings are turned off my compile commands goes from: to this: which fixes my issue. My clangd logs looked the same as OP. |
Hello,
I have upgraded to 17.0.X, but I found that clangd reports that some of the header files cannot be found. However, downgrade back to 16.0.6, the error disappears.
All the other settings of the project are the same. I only replaced the clangd binary from 16.0.6 to 17.0.2 or 17.0.3, then the server reports that the header files are missing, which actually, of course, are not.
I have read 17.0.1 release notes but found nothing helpful. Any help would be appreciated. Otherwise, I can only stay in clangd 16.0.6 forever. That would be really sad for me.
The text was updated successfully, but these errors were encountered: