Skip to content

Commit 3192ee7

Browse files
authored
[Driver][SYCL] Make -std=c++17 the default for DPC++ (#1662)
This forces -std=c++17 for DPC++ when no -std* option is provided on the command line. Only enabled with -fsycl. Modify setting implementation to be more inline with existing flow. This also allows for MSVC /std option settings to override. Signed-off-by: Michael D Toguchi <[email protected]>
1 parent 94cb022 commit 3192ee7

File tree

5 files changed

+25
-4
lines changed

5 files changed

+25
-4
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5106,6 +5106,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
51065106
/*Joined=*/true);
51075107
else if (IsWindowsMSVC)
51085108
ImplyVCPPCXXVer = true;
5109+
else if (IsSYCL)
5110+
// For DPC++, we default to -std=c++17 for all compilations. Use of -std
5111+
// on the command line will override.
5112+
CmdArgs.push_back("-std=c++17");
51095113

51105114
Args.AddLastArg(CmdArgs, options::OPT_ftrigraphs,
51115115
options::OPT_fno_trigraphs);
@@ -5674,7 +5678,11 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
56745678

56755679
if (LanguageStandard.empty()) {
56765680
if (IsMSVC2015Compatible)
5677-
LanguageStandard = "-std=c++14";
5681+
if (IsSYCL)
5682+
// For DPC++, C++17 is the default.
5683+
LanguageStandard = "-std=c++17";
5684+
else
5685+
LanguageStandard = "-std=c++14";
56785686
else
56795687
LanguageStandard = "-std=c++11";
56805688
}

clang/test/Driver/sycl-offload.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,5 +814,18 @@
814814
// RUN: %clangxx -### -c -fsycl -xc-header %s 2>&1 | FileCheck -check-prefixes=CHECK_XC_FSYCL %s
815815
// CHECK_XC_FSYCL: The option -x c{{.*}} must not be used in conjunction with -fsycl{{.*}}
816816

817+
// -std=c++17 check (check all 3 compilations)
818+
// RUN: %clangxx -### -c -fsycl -xc++ %s 2>&1 | FileCheck -check-prefix=CHECK-STD %s
819+
// RUN: %clang_cl -### -c -fsycl -TP %s 2>&1 | FileCheck -check-prefix=CHECK-STD %s
820+
// CHECK-STD: clang{{.*}} "-emit-llvm-bc" {{.*}} "-std=c++17"
821+
// CHECK-STD: clang{{.*}} "-fsyntax-only" {{.*}} "-std=c++17"
822+
// CHECK-STD: clang{{.*}} "-emit-obj" {{.*}} "-std=c++17"
823+
824+
// -std=c++17 override check
825+
// RUN: %clangxx -### -c -fsycl -std=c++14 -xc++ %s 2>&1 | FileCheck -check-prefix=CHECK-STD-OVR %s
826+
// RUN: %clang_cl -### -c -fsycl /std:c++14 -TP %s 2>&1 | FileCheck -check-prefix=CHECK-STD-OVR %s
827+
// CHECK-STD-OVR: clang{{.*}} "-std=c++14"
828+
// CHECK-STD-OVR-NOT: clang{{.*}} "-std=c++17"
829+
817830
// TODO: SYCL specific fail - analyze and enable
818831
// XFAIL: windows-msvc

sycl/doc/FAQ.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ set up a proper environment. To learn more about using the DPC++ compiler,
1919
please refer to [Users Manual](UsersManual.md). If using a special compiler
2020
is not an option for you and/or you would like to experiment without offloading
2121
code to non-host devices, you can exploit SYCL's host device feature. This
22-
gives you the ability to use any C++14 compiler. You will need to link your
22+
gives you the ability to use any C++17 compiler. You will need to link your
2323
application with the DPC++ Runtime library and provide a path to the SYCL
2424
headers directory. Please, refer to your compiler manual to learn about
2525
specific build options.

sycl/doc/GetStartedGuide.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ class CUDASelector : public cl::sycl::device_selector {
516516
## C++ standard
517517

518518
- DPC++ runtime is built as C++14 library.
519-
- DPC++ compiler is building apps as C++14 apps by default.
519+
- DPC++ compiler is building apps as C++17 apps by default.
520520

521521
## Known Issues and Limitations
522522

sycl/test/abi/layout_handler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
// CHECK-NEXT: FieldDecl {{.*}} MAssociatedAccesors 'vector_class<detail::ArgDesc>':'std::vector<cl::sycl::detail::ArgDesc, std::allocator<cl::sycl::detail::ArgDesc>>'
1717
// CHECK-NEXT: FieldDecl {{.*}} MRequirements 'vector_class<detail::Requirement *>':'std::vector<cl::sycl::detail::AccessorImplHost *, std::allocator<cl::sycl::detail::AccessorImplHost *>>'
1818
// CHECK-NEXT: FieldDecl {{.*}} MNDRDesc 'detail::NDRDescT':'cl::sycl::detail::NDRDescT'
19-
// CHECK-NEXT: FieldDecl {{.*}} MKernelName 'cl::sycl::string_class':'std::__cxx11::basic_string<char>'
19+
// CHECK-NEXT: FieldDecl {{.*}} MKernelName 'cl::sycl::string_class':'std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>'
2020
// CHECK-NEXT: FieldDecl {{.*}} MKernel 'shared_ptr_class<detail::kernel_impl>':'std::shared_ptr<cl::sycl::detail::kernel_impl>'
2121
// CHECK-NEXT: FieldDecl {{.*}} MCGType 'detail::CG::CGTYPE':'cl::sycl::detail::CG::CGTYPE'
2222
// CHECK-NEXT: DeclRefExpr {{.*}} 'cl::sycl::detail::CG::CGTYPE' EnumConstant {{.*}} 'NONE' 'cl::sycl::detail::CG::CGTYPE'

0 commit comments

Comments
 (0)