Skip to content

Commit d67098c

Browse files
[clang][Driver][SYCL] Disable SYCL header search paths under -nostd[lib]inc (#20583)
That matches the intended behavior of those options.
1 parent 1a821de commit d67098c

File tree

3 files changed

+33
-19
lines changed

3 files changed

+33
-19
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5032,24 +5032,27 @@ void Clang::ConstructHostCompilerJob(Compilation &C, const JobAction &JA,
50325032
if (IsMSVCHostCompiler)
50335033
HostCompileArgs.push_back("/external:W0");
50345034

5035-
// Add default header search directories.
5036-
SmallString<128> BaseDir(C.getDriver().Dir);
5037-
llvm::sys::path::append(BaseDir, "..", "include");
5038-
SmallString<128> SYCLDir(BaseDir);
5039-
llvm::sys::path::append(SYCLDir, "sycl");
5040-
// This is used to provide our wrappers around STL headers that provide
5041-
// additional functions/template specializations when the user includes those
5042-
// STL headers in their programs (e.g., <complex>).
5043-
SmallString<128> STLWrappersDir(SYCLDir);
5044-
llvm::sys::path::append(STLWrappersDir, "stl_wrappers");
5045-
// Add the SYCL specific header directories as system directories for non
5046-
// MSVC compilers.
5047-
HostCompileArgs.push_back(IsMSVCHostCompiler ? "/external:I" : "-isystem");
5048-
HostCompileArgs.push_back(TCArgs.MakeArgString(SYCLDir));
5049-
HostCompileArgs.push_back(IsMSVCHostCompiler ? "/external:I" : "-isystem");
5050-
HostCompileArgs.push_back(TCArgs.MakeArgString(STLWrappersDir));
5051-
HostCompileArgs.push_back(IsMSVCHostCompiler ? "/external:I" : "-isystem");
5052-
HostCompileArgs.push_back(TCArgs.MakeArgString(BaseDir));
5035+
namespace options = clang::driver::options;
5036+
if (!TCArgs.hasArg(options::OPT_nostdlibinc, options::OPT_nostdinc)) {
5037+
// Add default header search directories.
5038+
SmallString<128> BaseDir(C.getDriver().Dir);
5039+
llvm::sys::path::append(BaseDir, "..", "include");
5040+
SmallString<128> SYCLDir(BaseDir);
5041+
llvm::sys::path::append(SYCLDir, "sycl");
5042+
// This is used to provide our wrappers around STL headers that provide
5043+
// additional functions/template specializations when the user includes
5044+
// those STL headers in their programs (e.g., <complex>).
5045+
SmallString<128> STLWrappersDir(SYCLDir);
5046+
llvm::sys::path::append(STLWrappersDir, "stl_wrappers");
5047+
// Add the SYCL specific header directories as system directories for non
5048+
// MSVC compilers.
5049+
HostCompileArgs.push_back(IsMSVCHostCompiler ? "/external:I" : "-isystem");
5050+
HostCompileArgs.push_back(TCArgs.MakeArgString(SYCLDir));
5051+
HostCompileArgs.push_back(IsMSVCHostCompiler ? "/external:I" : "-isystem");
5052+
HostCompileArgs.push_back(TCArgs.MakeArgString(STLWrappersDir));
5053+
HostCompileArgs.push_back(IsMSVCHostCompiler ? "/external:I" : "-isystem");
5054+
HostCompileArgs.push_back(TCArgs.MakeArgString(BaseDir));
5055+
}
50535056

50545057
if (!OutputAdded) {
50555058
// Add output file to the command line. This is assumed to be prefaced

clang/lib/Driver/ToolChains/SYCL.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,10 @@ void SYCLInstallationDetector::getSYCLDeviceLibPath(
123123

124124
void SYCLInstallationDetector::addSYCLIncludeArgs(
125125
const ArgList &DriverArgs, ArgStringList &CC1Args) const {
126-
if (DriverArgs.hasArg(clang::driver::options::OPT_nobuiltininc))
126+
namespace options = clang::driver::options;
127+
if (DriverArgs.hasArg(options::OPT_nostdlibinc, options::OPT_nostdinc)) {
127128
return;
129+
}
128130
// Add the SYCL header search locations in the specified order.
129131
// ../include/sycl/stl_wrappers
130132
// ../include
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: %clangxx -fsycl -fsycl-device-only -nostdlibinc -fsyntax-only %s
2+
// RUN: %clangxx -fsycl -fsycl-device-only -nostdinc -fsyntax-only %s
3+
4+
// RUN: %clangxx -fsycl -nostdlibinc -fsyntax-only %s
5+
// RUN: %clangxx -fsycl -nostdinc -fsyntax-only %s
6+
7+
#if __has_include(<sycl/sycl.hpp>)
8+
#error "expected to *not* be able to find SYCL headers"
9+
#endif

0 commit comments

Comments
 (0)