Skip to content

Commit e5f74b0

Browse files
committed
[clangd] Forward --target to system include extraction
Some clang multilib configurations (such as the one currently used in the beta ARM LLVM toolchain) wind up only reporting the C++ include paths properly if they get passed the correct target.
1 parent 9dc5d8d commit e5f74b0

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

clang-tools-extra/clangd/SystemIncludeExtractor.cpp

+10-2
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,13 @@ struct DriverArgs {
8787
std::string Lang;
8888
std::string Sysroot;
8989
std::string ISysroot;
90+
std::string Target;
9091

9192
bool operator==(const DriverArgs &RHS) const {
9293
return std::tie(Driver, StandardIncludes, StandardCXXIncludes, Lang,
93-
Sysroot, ISysroot) ==
94+
Sysroot, ISysroot, Target) ==
9495
std::tie(RHS.Driver, RHS.StandardIncludes, RHS.StandardCXXIncludes,
95-
RHS.Lang, RHS.Sysroot, ISysroot);
96+
RHS.Lang, RHS.Sysroot, RHS.ISysroot, RHS.Target);
9697
}
9798

9899
DriverArgs(const tooling::CompileCommand &Cmd, llvm::StringRef File) {
@@ -130,6 +131,11 @@ struct DriverArgs {
130131
ISysroot = Cmd.CommandLine[I + 1];
131132
else
132133
ISysroot = Arg.str();
134+
} else if (Arg.consume_front("--target=")) {
135+
Target = Arg.str();
136+
} else if (Arg.consume_front("-target")) {
137+
if (Arg.empty() && I + 1 < E)
138+
Target = Cmd.CommandLine[I + 1];
133139
}
134140
}
135141

@@ -167,6 +173,8 @@ struct DriverArgs {
167173
Args.append({"--sysroot", Sysroot});
168174
if (!ISysroot.empty())
169175
Args.append({"-isysroot", ISysroot});
176+
if (!Target.empty())
177+
Args.append({"-target", Target});
170178
return Args;
171179
}
172180

clang-tools-extra/clangd/test/system-include-extractor.test

+3-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
# RUN: echo '[ -z "${args##*"-nostdinc"*}" ] || exit' >> %t.dir/bin/my_driver.sh
1818
# RUN: echo '[ -z "${args##*"--sysroot /my/sysroot/path"*}" ] || exit' >> %t.dir/bin/my_driver.sh
1919
# RUN: echo '[ -z "${args##*"-isysroot /isysroot"*}" ] || exit' >> %t.dir/bin/my_driver.sh
20+
# RUN: echo '[ -z "${args##*"-target arm-linux-gnueabihf"*}" ] || exit' >> %t.dir/bin/my_driver.sh
2021
# RUN: echo 'echo line to ignore >&2' >> %t.dir/bin/my_driver.sh
2122
# RUN: echo 'printf "Target: arm-linux-gnueabihf\r\n" >&2' >> %t.dir/bin/my_driver.sh
2223
# RUN: echo 'printf "#include <...> search starts here:\r\n" >&2' >> %t.dir/bin/my_driver.sh
@@ -36,7 +37,7 @@
3637

3738
# Generate a compile_commands.json that will query the mock driver we've
3839
# created. Which should add a.h and b.h into include search path.
39-
# 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
40+
# RUN: echo '[{"directory": "%/t.dir", "command": "my_driver.sh the-file.cpp --target=arm-linux-gnueabihf -nostdinc --sysroot /my/sysroot/path -isysroot/isysroot", "file": "the-file.cpp"}]' > %t.dir/compile_commands.json
4041

4142
# RUN: sed -e "s|INPUT_DIR|%/t.dir|g" %s > %t.test.1
4243
# On Windows, we need the URI in didOpen to look like "uri":"file:///C:/..."
@@ -74,7 +75,7 @@
7475
{"jsonrpc":"2.0","method":"exit"}
7576

7677
# Generate a different compile_commands.json which does not point to the mock driver
77-
# 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
78+
# RUN: echo '[{"directory": "%/t.dir", "command": "gcc the-file.cpp --target=arm-linux-gnueabihf -nostdinc --sysroot /my/sysroot/path -isysroot/isysroot", "file": "the-file.cpp"}]' > %t.dir/compile_commands.json
7879

7980
# Generate a clangd config file which points to the mock driver instead
8081
# RUN: echo 'CompileFlags:' > %t.dir/.clangd

0 commit comments

Comments
 (0)