Skip to content

Commit e7ed860

Browse files
authored
[Driver][SYCL] Set /Zc:__cplusplus default for MSVC host compilation (#7406)
By default, we pass the /Zc:__cplusplus to host compiler(cl) When user passes /Zc:__cplusplus- on the icx/icpx commandline, we override the option to the host compiler to disable the default. When user passes /Zc:_cplusplus- (OR) /Zc:_cplusplus through -fsycl-host-compiler-options, we pass such option as-is. This will have higher priority.
1 parent a782779 commit e7ed860

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4637,6 +4637,13 @@ void Clang::ConstructHostCompilerJob(Compilation &C, const JobAction &JA,
46374637
HostCompileArgs.push_back(TCArgs.MakeArgString(OutOpt));
46384638
OutputAdded = true;
46394639
};
4640+
// By default: pass /Zc:__cplusplus if we see a MSVC compiler.
4641+
// Users can disable this through
4642+
// -fsycl-host-compiler-options=/Zc:__cplusplus-
4643+
// It overrides the default option.
4644+
if (IsMSVCHostCompiler)
4645+
HostCompileArgs.push_back("/Zc:__cplusplus");
4646+
46404647
// FIXME: Reuse existing toolchains which are already supported to put
46414648
// together the options.
46424649
// FIXME: For any potential obscure host compilers that do not use the

clang/test/Driver/sycl-host-compiler.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,12 @@
6767
// RUN: %clangxx -fsycl -fsycl-host-compiler=g++ %t.o -### 2>&1 \
6868
// RUN: | FileCheck -check-prefix=WARNING_HOST_COMPILER %s
6969
// WARNING_HOST_COMPILER-NOT: warning: argument unused during compilation: '-fsycl-host-compiler=g++' [-Wunused-command-line-argument]
70+
71+
// Zc:__cplusplus, Zc:__cplusplus- check
72+
// RUN: %clang_cl -### -fsycl-host-compiler=cl -fsycl %s 2>&1 | FileCheck -check-prefix=CHECK-ZC-CPLUSPLUS %s
73+
// RUN: %clang_cl -### -fsycl-host-compiler=cl -fsycl -fsycl-host-compiler-options=/Zc:__cplusplus- %s 2>&1 | FileCheck -check-prefix=CHECK-ZC-CPLUSPLUS-MINUS %s
74+
// RUN: %clang_cl -### %s 2>&1 | FileCheck -check-prefix=CHECK-NO-ZC-CPLUSPLUS %s
75+
// RUN: %clang_cl -### -fsycl-host-compiler=g++ -fsycl %s 2>&1 | FileCheck -check-prefix=CHECK-NO-ZC-CPLUSPLUS %s
76+
// CHECK-ZC-CPLUSPLUS: "/Zc:__cplusplus"
77+
// CHECK-ZC-CPLUSPLUS-MINUS: "/Zc:__cplusplus-"
78+
// CHECK-NO-ZC-CPLUSPLUS-NOT: "/Zc:__cplusplus"

0 commit comments

Comments
 (0)