This revision was automatically updated to reflect the committed changes. Closed by commit rL273015: [OpenCL] Allow -std={cl|CL}{|1.1|1.2|2.0} in driver (authored by yaxunl).
Changed prior to commit: http://reviews.llvm.org/D20630?vs=58978&id=61109#toc Repository: rL LLVM http://reviews.llvm.org/D20630 Files: cfe/trunk/include/clang/Frontend/LangStandards.def cfe/trunk/lib/Frontend/CompilerInvocation.cpp cfe/trunk/test/Driver/opencl.cl cfe/trunk/test/Frontend/stdlang.c
Index: cfe/trunk/include/clang/Frontend/LangStandards.def =================================================================== --- cfe/trunk/include/clang/Frontend/LangStandards.def +++ cfe/trunk/include/clang/Frontend/LangStandards.def @@ -19,6 +19,14 @@ /// \param FEATURES - The standard features as flags, these are enums from the /// clang::frontend namespace, which is assumed to be be available. +/// LANGSTANDARD_ALIAS(IDENT, ALIAS) +/// \param IDENT - The name of the standard as a C++ identifier. +/// \param ALIAS - The alias of the standard. + +#ifndef LANGSTANDARD_ALIAS +#define LANGSTANDARD_ALIAS(IDENT, ALIAS) +#endif + // C89-ish modes. LANGSTANDARD(c89, "c89", "ISO C 1990", @@ -135,19 +143,26 @@ LANGSTANDARD(opencl, "cl", "OpenCL 1.0", LineComment | C99 | Digraphs | HexFloat) -LANGSTANDARD(opencl11, "CL1.1", +LANGSTANDARD(opencl11, "cl1.1", "OpenCL 1.1", LineComment | C99 | Digraphs | HexFloat) -LANGSTANDARD(opencl12, "CL1.2", +LANGSTANDARD(opencl12, "cl1.2", "OpenCL 1.2", LineComment | C99 | Digraphs | HexFloat) -LANGSTANDARD(opencl20, "CL2.0", +LANGSTANDARD(opencl20, "cl2.0", "OpenCL 2.0", LineComment | C99 | Digraphs | HexFloat) +LANGSTANDARD_ALIAS(opencl, "CL") +LANGSTANDARD_ALIAS(opencl11, "CL1.1") +LANGSTANDARD_ALIAS(opencl12, "CL1.2") +LANGSTANDARD_ALIAS(opencl20, "CL2.0") + // CUDA LANGSTANDARD(cuda, "cuda", "NVIDIA CUDA(tm)", LineComment | CPlusPlus | Digraphs) #undef LANGSTANDARD +#undef LANGSTANDARD_ALIAS + Index: cfe/trunk/test/Frontend/stdlang.c =================================================================== --- cfe/trunk/test/Frontend/stdlang.c +++ cfe/trunk/test/Frontend/stdlang.c @@ -1,5 +1,9 @@ // RUN: %clang_cc1 -x cuda -std=c++11 -DCUDA %s // RUN: %clang_cc1 -x cl -DOPENCL %s +// RUN: %clang_cc1 -x cl -cl-std=cl -DOPENCL %s +// RUN: %clang_cc1 -x cl -cl-std=cl1.1 -DOPENCL %s +// RUN: %clang_cc1 -x cl -cl-std=cl1.2 -DOPENCL %s +// RUN: %clang_cc1 -x cl -cl-std=cl2.0 -DOPENCL %s // RUN: %clang_cc1 -x cl -cl-std=CL -DOPENCL %s // RUN: %clang_cc1 -x cl -cl-std=CL1.1 -DOPENCL %s // RUN: %clang_cc1 -x cl -cl-std=CL1.2 -DOPENCL %s Index: cfe/trunk/test/Driver/opencl.cl =================================================================== --- cfe/trunk/test/Driver/opencl.cl +++ cfe/trunk/test/Driver/opencl.cl @@ -0,0 +1,15 @@ +// RUN: %clang %s +// RUN: %clang -std=cl %s +// RUN: %clang -std=cl1.1 %s +// RUN: %clang -std=cl1.2 %s +// RUN: %clang -std=cl2.0 %s +// RUN: %clang -std=CL %s +// RUN: %clang -std=CL1.1 %s +// RUN: %clang -std=CL1.2 %s +// RUN: %clang -std=CL2.0 %s +// RUN: not %clang_cc1 -std=c99 -DOPENCL %s 2>&1 | FileCheck --check-prefix=CHECK-C99 %s +// RUN: not %clang_cc1 -std=invalid -DOPENCL %s 2>&1 | FileCheck --check-prefix=CHECK-INVALID %s +// CHECK-C99: error: invalid argument '-std=c99' not allowed with 'OpenCL' +// CHECK-INVALID: error: invalid value 'invalid' in '-std=invalid' + +kernel void func(void); Index: cfe/trunk/lib/Frontend/CompilerInvocation.cpp =================================================================== --- cfe/trunk/lib/Frontend/CompilerInvocation.cpp +++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp @@ -1450,6 +1450,13 @@ Opts.AddVFSOverlayFile(A->getValue()); } +bool isOpenCL(LangStandard::Kind LangStd) { + return LangStd == LangStandard::lang_opencl + || LangStd == LangStandard::lang_opencl11 + || LangStd == LangStandard::lang_opencl12 + || LangStd == LangStandard::lang_opencl20; +} + void CompilerInvocation::setLangDefaults(LangOptions &Opts, InputKind IK, const llvm::Triple &T, LangStandard::Kind LangStd) { @@ -1517,7 +1524,7 @@ Opts.ImplicitInt = Std.hasImplicitInt(); // Set OpenCL Version. - Opts.OpenCL = LangStd == LangStandard::lang_opencl || IK == IK_OpenCL; + Opts.OpenCL = isOpenCL(LangStd) || IK == IK_OpenCL; if (LangStd == LangStandard::lang_opencl) Opts.OpenCLVersion = 100; else if (LangStd == LangStandard::lang_opencl11) @@ -1589,6 +1596,8 @@ LangStd = llvm::StringSwitch<LangStandard::Kind>(A->getValue()) #define LANGSTANDARD(id, name, desc, features) \ .Case(name, LangStandard::lang_##id) +#define LANGSTANDARD_ALIAS(id, alias) \ + .Case(alias, LangStandard::lang_##id) #include "clang/Frontend/LangStandards.def" .Default(LangStandard::lang_unspecified); if (LangStd == LangStandard::lang_unspecified) @@ -1616,8 +1625,9 @@ << A->getAsString(Args) << "C++/ObjC++"; break; case IK_OpenCL: - Diags.Report(diag::err_drv_argument_not_allowed_with) - << A->getAsString(Args) << "OpenCL"; + if (!isOpenCL(LangStd)) + Diags.Report(diag::err_drv_argument_not_allowed_with) + << A->getAsString(Args) << "OpenCL"; break; case IK_CUDA: case IK_PreprocessedCuda: @@ -1636,10 +1646,10 @@ if (const Arg *A = Args.getLastArg(OPT_cl_std_EQ)) { LangStandard::Kind OpenCLLangStd = llvm::StringSwitch<LangStandard::Kind>(A->getValue()) - .Case("CL", LangStandard::lang_opencl) - .Case("CL1.1", LangStandard::lang_opencl11) - .Case("CL1.2", LangStandard::lang_opencl12) - .Case("CL2.0", LangStandard::lang_opencl20) + .Cases("cl", "CL", LangStandard::lang_opencl) + .Cases("cl1.1", "CL1.1", LangStandard::lang_opencl11) + .Cases("cl1.2", "CL1.2", LangStandard::lang_opencl12) + .Cases("cl2.0", "CL2.0", LangStandard::lang_opencl20) .Default(LangStandard::lang_unspecified); if (OpenCLLangStd == LangStandard::lang_unspecified) {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits