Index: include/clang/Basic/DiagnosticSemaKinds.td =================================================================== --- include/clang/Basic/DiagnosticSemaKinds.td +++ include/clang/Basic/DiagnosticSemaKinds.td @@ -7967,7 +7967,7 @@ // Blocks def err_blocks_disable : Error<"blocks support disabled - compile with -fblocks" - " or %select{pick a deployment target that supports them|for OpenCL 2.0 or above}0">; + " or %select{pick a deployment target that supports them|for OpenCL 2.0}0">; def err_block_returning_array_function : Error< "block cannot return %select{array|function}0 type %1">; Index: include/clang/Driver/Options.td =================================================================== --- include/clang/Driver/Options.td +++ include/clang/Driver/Options.td @@ -514,7 +514,7 @@ def cl_no_signed_zeros : Flag<["-"], "cl-no-signed-zeros">, Group, Flags<[CC1Option]>, HelpText<"OpenCL only. Allow use of less precise no signed zeros computations in the generated binary.">; def cl_std_EQ : Joined<["-"], "cl-std=">, Group, Flags<[CC1Option]>, - HelpText<"OpenCL language standard to compile for.">, Values<"cl,CL,cl1.1,CL1.1,cl1.2,CL1.2,cl2.0,CL2.0">; + HelpText<"OpenCL language standard to compile for.">, Values<"cl,CL,cl1.1,CL1.1,cl1.2,CL1.2,cl2.0,CL2.0,clc++,CLC++,cl2.2,CL2.2">; def cl_denorms_are_zero : Flag<["-"], "cl-denorms-are-zero">, Group, Flags<[CC1Option]>, HelpText<"OpenCL only. Allow denormals to be flushed to zero.">; def cl_fp32_correctly_rounded_divide_sqrt : Flag<["-"], "cl-fp32-correctly-rounded-divide-sqrt">, Group, Flags<[CC1Option]>, Index: include/clang/Frontend/LangStandards.def =================================================================== --- include/clang/Frontend/LangStandards.def +++ include/clang/Frontend/LangStandards.def @@ -155,11 +155,17 @@ LANGSTANDARD(opencl20, "cl2.0", OpenCL, "OpenCL 2.0", LineComment | C99 | Digraphs | HexFloat | OpenCL) +LANGSTANDARD(opencl22, "cl2.2", + OpenCL, "OpenCL 2.2 (aka OpenCL C++)", + LineComment | CPlusPlus | CPlusPlus11 | CPlusPlus14 | Digraphs | OpenCL) LANGSTANDARD_ALIAS_DEPR(opencl10, "CL") LANGSTANDARD_ALIAS_DEPR(opencl11, "CL1.1") LANGSTANDARD_ALIAS_DEPR(opencl12, "CL1.2") LANGSTANDARD_ALIAS_DEPR(opencl20, "CL2.0") +LANGSTANDARD_ALIAS_DEPR(opencl22, "CL2.2") +LANGSTANDARD_ALIAS_DEPR(opencl22, "clc++") +LANGSTANDARD_ALIAS_DEPR(opencl22, "CLC++") // CUDA LANGSTANDARD(cuda, "cuda", CUDA, "NVIDIA CUDA(tm)", Index: lib/Frontend/CompilerInvocation.cpp =================================================================== --- lib/Frontend/CompilerInvocation.cpp +++ lib/Frontend/CompilerInvocation.cpp @@ -1872,6 +1872,8 @@ Opts.OpenCLVersion = 120; else if (LangStd == LangStandard::lang_opencl20) Opts.OpenCLVersion = 200; + else if (LangStd == LangStandard::lang_opencl22) + Opts.OpenCLVersion = 220; // OpenCL has some additional defaults. if (Opts.OpenCL) { @@ -2063,6 +2065,7 @@ .Cases("cl1.1", "CL1.1", LangStandard::lang_opencl11) .Cases("cl1.2", "CL1.2", LangStandard::lang_opencl12) .Cases("cl2.0", "CL2.0", LangStandard::lang_opencl20) + .Cases("clc++", "CLC++", "cl2.2", "CL2.2", LangStandard::lang_opencl22) .Default(LangStandard::lang_unspecified); if (OpenCLLangStd == LangStandard::lang_unspecified) { @@ -2275,7 +2278,7 @@ Opts.RTTI = Opts.CPlusPlus && !Args.hasArg(OPT_fno_rtti); Opts.RTTIData = Opts.RTTI && !Args.hasArg(OPT_fno_rtti_data); Opts.Blocks = Args.hasArg(OPT_fblocks) || (Opts.OpenCL - && Opts.OpenCLVersion >= 200); + && Opts.OpenCLVersion == 200); Opts.BlocksRuntimeOptional = Args.hasArg(OPT_fblocks_runtime_optional); Opts.CoroutinesTS = Args.hasArg(OPT_fcoroutines_ts); Index: lib/Frontend/InitPreprocessor.cpp =================================================================== --- lib/Frontend/InitPreprocessor.cpp +++ lib/Frontend/InitPreprocessor.cpp @@ -425,7 +425,7 @@ Builder.defineMacro("__OBJC__"); // OpenCL v1.0/1.1 s6.9, v1.2/2.0 s6.10: Preprocessor Directives and Macros. - if (LangOpts.OpenCL) { + if (LangOpts.OpenCL && !LangOpts.CPlusPlus) { // OpenCL v1.0 and v1.1 do not have a predefined macro to indicate the // language standard with which the program is compiled. __OPENCL_VERSION__ // is for the OpenCL version supported by the OpenCL device, which is not Index: test/Driver/autocomplete.c =================================================================== --- test/Driver/autocomplete.c +++ test/Driver/autocomplete.c @@ -32,6 +32,7 @@ // MEABIALL-NEXT: gnu // RUN: %clang --autocomplete=-cl-std=,CL2 | FileCheck %s -check-prefix=CLSTD // CLSTD: CL2.0 +// CLSTD: CL2.2 // RUN: %clang --autocomplete=-cl-std= | FileCheck %s -check-prefix=CLSTDALL // CLSTDALL: cl // CLSTDALL-NEXT: CL @@ -41,6 +42,10 @@ // CLSTDALL-NEXT: CL1.2 // CLSTDALL-NEXT: cl2.0 // CLSTDALL-NEXT: CL2.0 +// CLSTDALL-NEXT: cl2.2 +// CLSTDALL-NEXT: CL2.2 +// CLSTDALL-NEXT: clc++ +// CLSTDALL-NEXT: CLC++ // RUN: %clang --autocomplete=-fno-sanitize-coverage=,f | FileCheck %s -check-prefix=FNOSANICOVER // FNOSANICOVER: func // RUN: %clang --autocomplete=-fno-sanitize-coverage= | FileCheck %s -check-prefix=FNOSANICOVERALL Index: test/Driver/opencl.cl =================================================================== --- test/Driver/opencl.cl +++ test/Driver/opencl.cl @@ -2,6 +2,7 @@ // RUN: %clang -S -### -cl-std=CL1.1 %s 2>&1 | FileCheck --check-prefix=CHECK-CL11 %s // RUN: %clang -S -### -cl-std=CL1.2 %s 2>&1 | FileCheck --check-prefix=CHECK-CL12 %s // RUN: %clang -S -### -cl-std=CL2.0 %s 2>&1 | FileCheck --check-prefix=CHECK-CL20 %s +// RUN: %clang -S -### -cl-std=CL2.2 %s 2>&1 | FileCheck --check-prefix=CHECK-CL22 %s // RUN: %clang -S -### -cl-opt-disable %s 2>&1 | FileCheck --check-prefix=CHECK-OPT-DISABLE %s // RUN: %clang -S -### -cl-strict-aliasing %s 2>&1 | FileCheck --check-prefix=CHECK-STRICT-ALIASING %s // RUN: %clang -S -### -cl-single-precision-constant %s 2>&1 | FileCheck --check-prefix=CHECK-SINGLE-PRECISION-CONST %s @@ -21,6 +22,7 @@ // CHECK-CL11: "-cc1" {{.*}} "-cl-std=CL1.1" // CHECK-CL12: "-cc1" {{.*}} "-cl-std=CL1.2" // CHECK-CL20: "-cc1" {{.*}} "-cl-std=CL2.0" +// CHECK-CL22: "-cc1" {{.*}} "-cl-std=CL2.2" // CHECK-OPT-DISABLE: "-cc1" {{.*}} "-cl-opt-disable" // CHECK-STRICT-ALIASING: "-cc1" {{.*}} "-cl-strict-aliasing" // CHECK-SINGLE-PRECISION-CONST: "-cc1" {{.*}} "-cl-single-precision-constant" Index: test/Driver/unknown-std.cl =================================================================== --- test/Driver/unknown-std.cl +++ test/Driver/unknown-std.cl @@ -10,6 +10,7 @@ // CHECK-NEXT: note: use 'cl1.1' for 'OpenCL 1.1' standard // CHECK-NEXT: note: use 'cl1.2' for 'OpenCL 1.2' standard // CHECK-NEXT: note: use 'cl2.0' for 'OpenCL 2.0' standard +// CHECK-NEXT: note: use 'cl2.2' for 'OpenCL 2.2 (aka OpenCL C++)' standard // Make sure that no other output is present. // CHECK-NOT: {{^.+$}} Index: test/Frontend/opencl.cl =================================================================== --- test/Frontend/opencl.cl +++ test/Frontend/opencl.cl @@ -1,24 +1,33 @@ -// RUN: %clang_cc1 %s -verify -fsyntax-only -// RUN: %clang_cc1 %s -verify -fsyntax-only -cl-std=CL1.1 -// RUN: %clang_cc1 %s -verify -fsyntax-only -cl-std=CL1.2 -// RUN: %clang_cc1 %s -verify -fsyntax-only -cl-std=CL2.0 -// RUN: %clang_cc1 %s -verify -fsyntax-only -fblocks -DBLOCKS -// RUN: %clang_cc1 %s -verify -fsyntax-only -cl-std=CL1.1 -fblocks -DBLOCKS -// RUN: %clang_cc1 %s -verify -fsyntax-only -cl-std=CL1.2 -fblocks -DBLOCKS -// RUN: %clang_cc1 %s -triple amdgcn--amdhsa -x c -std=c99 -verify -fsyntax-only +// RUN: %clang_cc1 %s -verify -fsyntax-only -DSYNTAX +// RUN: %clang_cc1 %s -verify -fsyntax-only -cl-std=CL1.1 -DSYNTAX +// RUN: %clang_cc1 %s -verify -fsyntax-only -cl-std=CL1.2 -DSYNTAX +// RUN: %clang_cc1 %s -verify -fsyntax-only -cl-std=CL2.0 -DSYNTAX +// RUN: %clang_cc1 %s -verify -fsyntax-only -cl-std=CL2.2 -DSYNTAX -DCXX +// RUN: %clang_cc1 %s -verify -fsyntax-only -fblocks -DBLOCKS -DSYNTAX +// RUN: %clang_cc1 %s -verify -fsyntax-only -cl-std=CL1.1 -fblocks -DBLOCKS -DSYNTAX +// RUN: %clang_cc1 %s -verify -fsyntax-only -cl-std=CL1.2 -fblocks -DBLOCKS -DSYNTAX +// RUN: %clang_cc1 %s -triple amdgcn--amdhsa -x c -std=c99 -verify -fsyntax-only -DSYNTAX // RUN: %clang_cc1 -cl-std=CL1.1 -cl-strict-aliasing -fblocks %s 2>&1 | FileCheck --check-prefix=CHECK-INVALID-OPENCL-VERSION11 %s // RUN: %clang_cc1 -cl-std=CL1.2 -cl-strict-aliasing -fblocks %s 2>&1 | FileCheck --check-prefix=CHECK-INVALID-OPENCL-VERSION12 %s // RUN: %clang_cc1 -cl-std=CL2.0 -cl-strict-aliasing %s 2>&1 | FileCheck --check-prefix=CHECK-INVALID-OPENCL-VERSION20 %s +#ifdef SYNTAX +class test{ +int member; +}; +#ifndef CXX +//expected-error@-4{{unknown type name 'class'}} +//expected-error@-5{{expected ';' after top level declarator}} +#endif +#endif + void f(void (^g)(void)) { -#ifdef __OPENCL_C_VERSION__ -#if __OPENCL_C_VERSION__ < CL_VERSION_2_0 && !defined(BLOCKS) - // expected-error@-3{{blocks support disabled - compile with -fblocks or for OpenCL 2.0 or above}} -#else - // expected-no-diagnostics +#if defined(__OPENCL_C_VERSION__) || defined(CXX) +#if !defined(BLOCKS) && (defined(CXX) || __OPENCL_C_VERSION__ != CL_VERSION_2_0) + // expected-error@-3{{blocks support disabled - compile with -fblocks or for OpenCL 2.0}} #endif #else - // expected-error@-8{{blocks support disabled - compile with -fblocks or pick a deployment target that supports them}} + // expected-error@-6{{blocks support disabled - compile with -fblocks or pick a deployment target that supports them}} #endif } Index: test/Frontend/stdlang.c =================================================================== --- test/Frontend/stdlang.c +++ test/Frontend/stdlang.c @@ -4,10 +4,14 @@ // 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=cl2.2 -DOPENCL %s +// RUN: %clang_cc1 -x cl -cl-std=clc++ -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=CL2.2 -DOPENCL %s +// RUN: %clang_cc1 -x cl -cl-std=CLC++ -DOPENCL %s // RUN: not %clang_cc1 -x cl -std=c99 -DOPENCL %s 2>&1 | FileCheck --check-prefix=CHECK-C99 %s // RUN: not %clang_cc1 -x cl -cl-std=invalid -DOPENCL %s 2>&1 | FileCheck --check-prefix=CHECK-INVALID %s // CHECK-C99: error: invalid argument '-std=c99' not allowed with 'OpenCL'