yaxunl updated this revision to Diff 58471. yaxunl added a comment. Revised as Richard suggested.
http://reviews.llvm.org/D20630 Files: lib/Frontend/CompilerInvocation.cpp test/Driver/opencl.cl test/Frontend/stdlang.c Index: test/Frontend/stdlang.c =================================================================== --- test/Frontend/stdlang.c +++ test/Frontend/stdlang.c @@ -1,6 +1,6 @@ // 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=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 Index: test/Driver/opencl.cl =================================================================== --- /dev/null +++ test/Driver/opencl.cl @@ -0,0 +1,11 @@ +// RUN: %clang -S %s +// RUN: %clang -S -std=cl %s +// RUN: %clang -S -std=CL1.1 %s +// RUN: %clang -S -std=CL1.2 %s +// RUN: %clang -S -std=CL2.0 %s +// RUN: not %clang -S -std=c99 -DOPENCL %s 2>&1 | FileCheck --check-prefix=CHECK-C99 %s +// RUN: not %clang -S -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: lib/Frontend/CompilerInvocation.cpp =================================================================== --- lib/Frontend/CompilerInvocation.cpp +++ lib/Frontend/CompilerInvocation.cpp @@ -1398,6 +1398,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) { @@ -1462,7 +1469,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) @@ -1555,8 +1562,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: @@ -1575,7 +1583,7 @@ 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("cl", LangStandard::lang_opencl) .Case("CL1.1", LangStandard::lang_opencl11) .Case("CL1.2", LangStandard::lang_opencl12) .Case("CL2.0", LangStandard::lang_opencl20)
Index: test/Frontend/stdlang.c =================================================================== --- test/Frontend/stdlang.c +++ test/Frontend/stdlang.c @@ -1,6 +1,6 @@ // 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=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 Index: test/Driver/opencl.cl =================================================================== --- /dev/null +++ test/Driver/opencl.cl @@ -0,0 +1,11 @@ +// RUN: %clang -S %s +// RUN: %clang -S -std=cl %s +// RUN: %clang -S -std=CL1.1 %s +// RUN: %clang -S -std=CL1.2 %s +// RUN: %clang -S -std=CL2.0 %s +// RUN: not %clang -S -std=c99 -DOPENCL %s 2>&1 | FileCheck --check-prefix=CHECK-C99 %s +// RUN: not %clang -S -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: lib/Frontend/CompilerInvocation.cpp =================================================================== --- lib/Frontend/CompilerInvocation.cpp +++ lib/Frontend/CompilerInvocation.cpp @@ -1398,6 +1398,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) { @@ -1462,7 +1469,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) @@ -1555,8 +1562,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: @@ -1575,7 +1583,7 @@ 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("cl", LangStandard::lang_opencl) .Case("CL1.1", LangStandard::lang_opencl11) .Case("CL1.2", LangStandard::lang_opencl12) .Case("CL2.0", LangStandard::lang_opencl20)
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits