diff --git a/clang/include/clang/Basic/LangOptions.h b/clang/include/clang/Basic/LangOptions.h --- a/clang/include/clang/Basic/LangOptions.h +++ b/clang/include/clang/Basic/LangOptions.h @@ -125,6 +125,11 @@ MSVC2019 = 1920, }; + enum SYCLMajorVersion { + SYCL_None, + SYCL_2017, + }; + /// Clang versions with different platform ABI conformance. enum class ClangABI { /// Attempt to be ABI-compatible with code generated by Clang 3.8.x diff --git a/clang/include/clang/Basic/LangOptions.def b/clang/include/clang/Basic/LangOptions.def --- a/clang/include/clang/Basic/LangOptions.def +++ b/clang/include/clang/Basic/LangOptions.def @@ -246,7 +246,7 @@ LANGOPT(SYCL , 1, 0, "SYCL") LANGOPT(SYCLIsDevice , 1, 0, "Generate code for SYCL device") -LANGOPT(SYCLVersion , 32, 0, "Version of the SYCL standard used") +ENUM_LANGOPT(SYCLVersion , SYCLMajorVersion, 1, SYCL_None, "Version of the SYCL standard used") LANGOPT(HIPUseNewLaunchAPI, 1, 0, "Use new kernel launching API for HIP") diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -2277,11 +2277,13 @@ // -sycl-std applies to any SYCL source, not only those containing kernels, // but also those using the SYCL API if (const Arg *A = Args.getLastArg(OPT_sycl_std_EQ)) { - Opts.SYCLVersion = llvm::StringSwitch(A->getValue()) - .Cases("2017", "1.2.1", "121", "sycl-1.2.1", 2017) - .Default(0U); + Opts.setSYCLVersion( + llvm::StringSwitch(A->getValue()) + .Cases("2017", "1.2.1", "121", "sycl-1.2.1", + LangOptions::SYCL_2017) + .Default(LangOptions::SYCL_None)); - if (Opts.SYCLVersion == 0U) { + if (Opts.getSYCLVersion() == LangOptions::SYCL_None) { // User has passed an invalid value to the flag, this is an error Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << A->getValue(); diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp --- a/clang/lib/Frontend/InitPreprocessor.cpp +++ b/clang/lib/Frontend/InitPreprocessor.cpp @@ -476,7 +476,7 @@ if (LangOpts.SYCL) { // SYCL Version is set to a value when building SYCL applications - if (LangOpts.SYCLVersion == 2017) + if (LangOpts.getSYCLVersion() == LangOptions::SYCL_2017) Builder.defineMacro("CL_SYCL_LANGUAGE_VERSION", "121"); }