[PATCH] D138546: Clangd: Preserve target flags in system includes extractor
Christopher Sauer via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Dec 7 19:19:29 PST 2022
cpsauer updated this revision to Diff 481141.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D138546/new/
https://reviews.llvm.org/D138546
Files:
clang-tools-extra/clangd/SystemIncludeExtractor.cpp
clang-tools-extra/clangd/test/system-include-extractor.test
Index: clang-tools-extra/clangd/test/system-include-extractor.test
===================================================================
--- clang-tools-extra/clangd/test/system-include-extractor.test
+++ clang-tools-extra/clangd/test/system-include-extractor.test
@@ -16,6 +16,8 @@
# RUN: echo '[ -z "${args##*"-nostdinc"*}" ] || exit' >> %t.dir/bin/my_driver.sh
# RUN: echo '[ -z "${args##*"-isysroot=/isysroot"*}" ] || exit' >> %t.dir/bin/my_driver.sh
# RUN: echo '[ -z "${args##*"--sysroot /my/sysroot/path"*}" ] || exit' >> %t.dir/bin/my_driver.sh
+# RUN: echo '[ -z "${args##*"-target arm-linux-gnueabi"*}" ] || exit' >> %t.dir/bin/my_driver.sh
+# RUN: echo '[ -z "${args##*"--target=arm-linux-gnueabi"*}" ] || exit' >> %t.dir/bin/my_driver.sh
# RUN: echo 'echo line to ignore >&2' >> %t.dir/bin/my_driver.sh
# RUN: echo 'printf "Target: arm-linux-gnueabihf\r\n" >&2' >> %t.dir/bin/my_driver.sh
# RUN: echo 'printf "#include <...> search starts here:\r\n" >&2' >> %t.dir/bin/my_driver.sh
@@ -32,7 +34,7 @@
# Generate a compile_commands.json that will query the mock driver we've
# created. Which should add a.h and b.h into include search path.
-# RUN: echo '[{"directory": "%/t.dir", "command": "my_driver.sh the-file.cpp -nostdinc --sysroot /my/sysroot/path -isysroot=/isysroot", "file": "the-file.cpp"}]' > %t.dir/compile_commands.json
+# RUN: echo '[{"directory": "%/t.dir", "command": "my_driver.sh the-file.cpp -nostdinc --sysroot /my/sysroot/path -isysroot=/isysroot -target arm-linux-gnueabi --target=arm-linux-gnueabi", "file": "the-file.cpp"}]' > %t.dir/compile_commands.json
# RUN: sed -e "s|INPUT_DIR|%/t.dir|g" %s > %t.test.1
# On Windows, we need the URI in didOpen to look like "uri":"file:///C:/..."
@@ -70,7 +72,7 @@
{"jsonrpc":"2.0","method":"exit"}
# Generate a different compile_commands.json which does not point to the mock driver
-# RUN: echo '[{"directory": "%/t.dir", "command": "gcc the-file.cpp -nostdinc --sysroot /my/sysroot/path -isysroot=/isysroot", "file": "the-file.cpp"}]' > %t.dir/compile_commands.json
+# RUN: echo '[{"directory": "%/t.dir", "command": "gcc the-file.cpp -nostdinc --sysroot /my/sysroot/path -isysroot=/isysroot -target arm-linux-gnueabi --target=arm-linux-gnueabi", "file": "the-file.cpp"}]' > %t.dir/compile_commands.json
# Generate a clangd config file which points to the mock driver instead
# RUN: echo 'CompileFlags:' > %t.dir/.clangd
Index: clang-tools-extra/clangd/SystemIncludeExtractor.cpp
===================================================================
--- clang-tools-extra/clangd/SystemIncludeExtractor.cpp
+++ clang-tools-extra/clangd/SystemIncludeExtractor.cpp
@@ -184,13 +184,18 @@
const llvm::StringRef FlagsToPreserve[] = {
"-nostdinc", "--no-standard-includes", "-nostdinc++", "-nobuiltininc"};
// Preserves these flags and their values, either as separate args or with an
- // equalsbetween them
+ // equals between them
const llvm::StringRef ArgsToPreserve[] = {"--sysroot", "-isysroot"};
for (size_t I = 0, E = CommandLine.size(); I < E; ++I) {
llvm::StringRef Arg = CommandLine[I];
if (llvm::is_contained(FlagsToPreserve, Arg)) {
Args.push_back(Arg);
+ } else if (Arg.startswith("--target=")) {
+ Args.push_back(Arg);
+ } else if (I + 1 < E && Arg.equals("-target")) {
+ Args.push_back(CommandLine[I]);
+ Args.push_back(CommandLine[++I]);
} else {
const auto *Found =
llvm::find_if(ArgsToPreserve, [&Arg](llvm::StringRef S) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D138546.481141.patch
Type: text/x-patch
Size: 3515 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221208/b4a69bce/attachment-0001.bin>
More information about the cfe-commits
mailing list