Re: [PATCH] D19071: [OpenCL] Add predefined macros.
This revision was automatically updated to reflect the committed changes. Closed by commit rL267590: [OpenCL] Add predefined macros. (authored by yaxunl). Changed prior to commit: http://reviews.llvm.org/D19071?vs=55016=55066#toc Repository: rL LLVM http://reviews.llvm.org/D19071 Files: cfe/trunk/lib/Frontend/CompilerInvocation.cpp cfe/trunk/lib/Frontend/InitPreprocessor.cpp cfe/trunk/test/Frontend/std.cl cfe/trunk/test/Frontend/stdlang.c cfe/trunk/test/Preprocessor/predefined-macros.c Index: cfe/trunk/test/Preprocessor/predefined-macros.c === --- cfe/trunk/test/Preprocessor/predefined-macros.c +++ cfe/trunk/test/Preprocessor/predefined-macros.c @@ -146,3 +146,40 @@ // CHECK-SYNC_CAS_MIPS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1 // CHECK-SYNC_CAS_MIPS32-NOT: __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 // CHECK-SYNC_CAS_MIPS64: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1 + +// RUN: %clang_cc1 %s -E -dM -o - -x cl \ +// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-CL10 +// RUN: %clang_cc1 %s -E -dM -o - -x cl -cl-std=CL1.1 \ +// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-CL11 +// RUN: %clang_cc1 %s -E -dM -o - -x cl -cl-std=CL1.2 \ +// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-CL12 +// RUN: %clang_cc1 %s -E -dM -o - -x cl -cl-std=CL2.0 \ +// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-CL20 +// RUN: %clang_cc1 %s -E -dM -o - -x cl -cl-fast-relaxed-math \ +// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-FRM +// CHECK-CL10: #define CL_VERSION_1_0 100 +// CHECK-CL10: #define CL_VERSION_1_1 110 +// CHECK-CL10: #define CL_VERSION_1_2 120 +// CHECK-CL10: #define CL_VERSION_2_0 200 +// CHECK-CL10: #define __OPENCL_C_VERSION__ 100 +// CHECK-CL10-NOT: #define __FAST_RELAXED_MATH__ 1 +// CHECK-CL11: #define CL_VERSION_1_0 100 +// CHECK-CL11: #define CL_VERSION_1_1 110 +// CHECK-CL11: #define CL_VERSION_1_2 120 +// CHECK-CL11: #define CL_VERSION_2_0 200 +// CHECK-CL11: #define __OPENCL_C_VERSION__ 110 +// CHECK-CL11-NOT: #define __FAST_RELAXED_MATH__ 1 +// CHECK-CL12: #define CL_VERSION_1_0 100 +// CHECK-CL12: #define CL_VERSION_1_1 110 +// CHECK-CL12: #define CL_VERSION_1_2 120 +// CHECK-CL12: #define CL_VERSION_2_0 200 +// CHECK-CL12: #define __OPENCL_C_VERSION__ 120 +// CHECK-CL12-NOT: #define __FAST_RELAXED_MATH__ 1 +// CHECK-CL20: #define CL_VERSION_1_0 100 +// CHECK-CL20: #define CL_VERSION_1_1 110 +// CHECK-CL20: #define CL_VERSION_1_2 120 +// CHECK-CL20: #define CL_VERSION_2_0 200 +// CHECK-CL20: #define __OPENCL_C_VERSION__ 200 +// CHECK-CL20-NOT: #define __FAST_RELAXED_MATH__ 1 +// CHECK-FRM: #define __FAST_RELAXED_MATH__ 1 + Index: cfe/trunk/test/Frontend/stdlang.c === --- cfe/trunk/test/Frontend/stdlang.c +++ cfe/trunk/test/Frontend/stdlang.c @@ -1,6 +1,13 @@ // RUN: %clang_cc1 -x cuda -std=c++11 -DCUDA %s -// RUN: %clang_cc1 -x cl -std=c99 -DOPENCL %s -// expected-no-diagnostics +// 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: 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' +// CHECK-INVALID: error: invalid value 'invalid' in '-cl-std=invalid' #if defined(CUDA) __attribute__((device)) void f_device(); Index: cfe/trunk/test/Frontend/std.cl === --- cfe/trunk/test/Frontend/std.cl +++ cfe/trunk/test/Frontend/std.cl @@ -1,9 +0,0 @@ -// RUN: %clang_cc1 %s -fsyntax-only -cl-std=CL -// RUN: %clang_cc1 %s -fsyntax-only -cl-std=CL1.1 -// RUN: %clang_cc1 %s -fsyntax-only -cl-std=CL1.2 -// RUN: %clang_cc1 %s -fsyntax-only -cl-std=CL2.0 -// RUN: not %clang_cc1 %s -fsyntax-only -cl-std=invalid -DINVALID 2>&1 | FileCheck %s - -#ifdef INVALID -// CHECK: invalid value 'invalid' in '-cl-std=invalid' -#endif Index: cfe/trunk/lib/Frontend/CompilerInvocation.cpp === --- cfe/trunk/lib/Frontend/CompilerInvocation.cpp +++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp @@ -1495,9 +1495,8 @@ << A->getAsString(Args) << "C++/ObjC++"; break; case IK_OpenCL: -if (!Std.isC99()) - Diags.Report(diag::err_drv_argument_not_allowed_with) -<< A->getAsString(Args) << "OpenCL"; +Diags.Report(diag::err_drv_argument_not_allowed_with) + << A->getAsString(Args) << "OpenCL"; break; case IK_CUDA: case IK_PreprocessedCuda: Index: cfe/trunk/lib/Frontend/InitPreprocessor.cpp
Re: [PATCH] D19071: [OpenCL] Add predefined macros.
Anastasia accepted this revision. Anastasia added a comment. This revision is now accepted and ready to land. LGTM! Thanks! http://reviews.llvm.org/D19071 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D19071: [OpenCL] Add predefined macros.
yaxunl updated this revision to Diff 55016. yaxunl marked 4 inline comments as done. yaxunl added a comment. Add CHECK-NOT for `__FAST_RELAXED_MATH__`. http://reviews.llvm.org/D19071 Files: lib/Frontend/CompilerInvocation.cpp lib/Frontend/InitPreprocessor.cpp test/Frontend/std.cl test/Frontend/stdlang.c test/Preprocessor/predefined-macros.c Index: test/Preprocessor/predefined-macros.c === --- test/Preprocessor/predefined-macros.c +++ test/Preprocessor/predefined-macros.c @@ -146,3 +146,40 @@ // CHECK-SYNC_CAS_MIPS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1 // CHECK-SYNC_CAS_MIPS32-NOT: __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 // CHECK-SYNC_CAS_MIPS64: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1 + +// RUN: %clang_cc1 %s -E -dM -o - -x cl \ +// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-CL10 +// RUN: %clang_cc1 %s -E -dM -o - -x cl -cl-std=CL1.1 \ +// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-CL11 +// RUN: %clang_cc1 %s -E -dM -o - -x cl -cl-std=CL1.2 \ +// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-CL12 +// RUN: %clang_cc1 %s -E -dM -o - -x cl -cl-std=CL2.0 \ +// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-CL20 +// RUN: %clang_cc1 %s -E -dM -o - -x cl -cl-fast-relaxed-math \ +// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-FRM +// CHECK-CL10: #define CL_VERSION_1_0 100 +// CHECK-CL10: #define CL_VERSION_1_1 110 +// CHECK-CL10: #define CL_VERSION_1_2 120 +// CHECK-CL10: #define CL_VERSION_2_0 200 +// CHECK-CL10: #define __OPENCL_C_VERSION__ 100 +// CHECK-CL10-NOT: #define __FAST_RELAXED_MATH__ 1 +// CHECK-CL11: #define CL_VERSION_1_0 100 +// CHECK-CL11: #define CL_VERSION_1_1 110 +// CHECK-CL11: #define CL_VERSION_1_2 120 +// CHECK-CL11: #define CL_VERSION_2_0 200 +// CHECK-CL11: #define __OPENCL_C_VERSION__ 110 +// CHECK-CL11-NOT: #define __FAST_RELAXED_MATH__ 1 +// CHECK-CL12: #define CL_VERSION_1_0 100 +// CHECK-CL12: #define CL_VERSION_1_1 110 +// CHECK-CL12: #define CL_VERSION_1_2 120 +// CHECK-CL12: #define CL_VERSION_2_0 200 +// CHECK-CL12: #define __OPENCL_C_VERSION__ 120 +// CHECK-CL12-NOT: #define __FAST_RELAXED_MATH__ 1 +// CHECK-CL20: #define CL_VERSION_1_0 100 +// CHECK-CL20: #define CL_VERSION_1_1 110 +// CHECK-CL20: #define CL_VERSION_1_2 120 +// CHECK-CL20: #define CL_VERSION_2_0 200 +// CHECK-CL20: #define __OPENCL_C_VERSION__ 200 +// CHECK-CL20-NOT: #define __FAST_RELAXED_MATH__ 1 +// CHECK-FRM: #define __FAST_RELAXED_MATH__ 1 + Index: test/Frontend/stdlang.c === --- test/Frontend/stdlang.c +++ test/Frontend/stdlang.c @@ -1,6 +1,13 @@ // RUN: %clang_cc1 -x cuda -std=c++11 -DCUDA %s -// RUN: %clang_cc1 -x cl -std=c99 -DOPENCL %s -// expected-no-diagnostics +// 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: 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' +// CHECK-INVALID: error: invalid value 'invalid' in '-cl-std=invalid' #if defined(CUDA) __attribute__((device)) void f_device(); Index: test/Frontend/std.cl === --- test/Frontend/std.cl +++ /dev/null @@ -1,9 +0,0 @@ -// RUN: %clang_cc1 %s -fsyntax-only -cl-std=CL -// RUN: %clang_cc1 %s -fsyntax-only -cl-std=CL1.1 -// RUN: %clang_cc1 %s -fsyntax-only -cl-std=CL1.2 -// RUN: %clang_cc1 %s -fsyntax-only -cl-std=CL2.0 -// RUN: not %clang_cc1 %s -fsyntax-only -cl-std=invalid -DINVALID 2>&1 | FileCheck %s - -#ifdef INVALID -// CHECK: invalid value 'invalid' in '-cl-std=invalid' -#endif Index: lib/Frontend/InitPreprocessor.cpp === --- lib/Frontend/InitPreprocessor.cpp +++ lib/Frontend/InitPreprocessor.cpp @@ -408,6 +408,39 @@ if (LangOpts.ObjC1) Builder.defineMacro("__OBJC__"); + // OpenCL v1.0/1.1 s6.9, v1.2/2.0 s6.10: Preprocessor Directives and Macros. + if (LangOpts.OpenCL) { +// 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 +// necessarily the language standard with which the program is compiled. +// A shared OpenCL header file requires a macro to indicate the language +// standard. As a workaround, __OPENCL_C_VERSION__ is defined for +// OpenCL v1.0 and v1.1. +switch (LangOpts.OpenCLVersion) { +case 100: +
Re: [PATCH] D19071: [OpenCL] Add predefined macros.
Anastasia added inline comments. Comment at: test/Preprocessor/predefined-macros.c:180 @@ +179,3 @@ +// CHECK-CL20: #define __OPENCL_C_VERSION__ 200 +// CHECK-FRM: #define __FAST_RELAXED_MATH__ 1 + Could we also add CHECK-NOT for all the above cases to make sure FAST_RELAXED_MATH doesn't appear there. http://reviews.llvm.org/D19071 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D19071: [OpenCL] Add predefined macros.
yaxunl updated this revision to Diff 54552. yaxunl added a comment. Revised as Anastasia suggested. http://reviews.llvm.org/D19071 Files: lib/Frontend/CompilerInvocation.cpp lib/Frontend/InitPreprocessor.cpp test/Frontend/std.cl test/Frontend/stdlang.c test/Preprocessor/predefined-macros.c Index: test/Preprocessor/predefined-macros.c === --- test/Preprocessor/predefined-macros.c +++ test/Preprocessor/predefined-macros.c @@ -146,3 +146,36 @@ // CHECK-SYNC_CAS_MIPS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1 // CHECK-SYNC_CAS_MIPS32-NOT: __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 // CHECK-SYNC_CAS_MIPS64: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1 + +// RUN: %clang_cc1 %s -E -dM -o - -x cl \ +// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-CL10 +// RUN: %clang_cc1 %s -E -dM -o - -x cl -cl-std=CL1.1 \ +// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-CL11 +// RUN: %clang_cc1 %s -E -dM -o - -x cl -cl-std=CL1.2 \ +// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-CL12 +// RUN: %clang_cc1 %s -E -dM -o - -x cl -cl-std=CL2.0 \ +// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-CL20 +// RUN: %clang_cc1 %s -E -dM -o - -x cl -cl-fast-relaxed-math \ +// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-FRM +// CHECK-CL10: #define CL_VERSION_1_0 100 +// CHECK-CL10: #define CL_VERSION_1_1 110 +// CHECK-CL10: #define CL_VERSION_1_2 120 +// CHECK-CL10: #define CL_VERSION_2_0 200 +// CHECK-CL10: #define __OPENCL_C_VERSION__ 100 +// CHECK-CL11: #define CL_VERSION_1_0 100 +// CHECK-CL11: #define CL_VERSION_1_1 110 +// CHECK-CL11: #define CL_VERSION_1_2 120 +// CHECK-CL11: #define CL_VERSION_2_0 200 +// CHECK-CL11: #define __OPENCL_C_VERSION__ 110 +// CHECK-CL12: #define CL_VERSION_1_0 100 +// CHECK-CL12: #define CL_VERSION_1_1 110 +// CHECK-CL12: #define CL_VERSION_1_2 120 +// CHECK-CL12: #define CL_VERSION_2_0 200 +// CHECK-CL12: #define __OPENCL_C_VERSION__ 120 +// CHECK-CL20: #define CL_VERSION_1_0 100 +// CHECK-CL20: #define CL_VERSION_1_1 110 +// CHECK-CL20: #define CL_VERSION_1_2 120 +// CHECK-CL20: #define CL_VERSION_2_0 200 +// CHECK-CL20: #define __OPENCL_C_VERSION__ 200 +// CHECK-FRM: #define __FAST_RELAXED_MATH__ 1 + Index: test/Frontend/stdlang.c === --- test/Frontend/stdlang.c +++ test/Frontend/stdlang.c @@ -1,6 +1,13 @@ // RUN: %clang_cc1 -x cuda -std=c++11 -DCUDA %s -// RUN: %clang_cc1 -x cl -std=c99 -DOPENCL %s -// expected-no-diagnostics +// 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: 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' +// CHECK-INVALID: error: invalid value 'invalid' in '-cl-std=invalid' #if defined(CUDA) __attribute__((device)) void f_device(); Index: test/Frontend/std.cl === --- test/Frontend/std.cl +++ /dev/null @@ -1,9 +0,0 @@ -// RUN: %clang_cc1 %s -fsyntax-only -cl-std=CL -// RUN: %clang_cc1 %s -fsyntax-only -cl-std=CL1.1 -// RUN: %clang_cc1 %s -fsyntax-only -cl-std=CL1.2 -// RUN: %clang_cc1 %s -fsyntax-only -cl-std=CL2.0 -// RUN: not %clang_cc1 %s -fsyntax-only -cl-std=invalid -DINVALID 2>&1 | FileCheck %s - -#ifdef INVALID -// CHECK: invalid value 'invalid' in '-cl-std=invalid' -#endif Index: lib/Frontend/InitPreprocessor.cpp === --- lib/Frontend/InitPreprocessor.cpp +++ lib/Frontend/InitPreprocessor.cpp @@ -408,6 +408,39 @@ if (LangOpts.ObjC1) Builder.defineMacro("__OBJC__"); + // OpenCL v1.0/1.1 s6.9, v1.2/2.0 s6.10: Preprocessor Directives and Macros. + if (LangOpts.OpenCL) { +// 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 +// necessarily the language standard with which the program is compiled. +// A shared OpenCL header file requires a macro to indicate the language +// standard. As a workaround, __OPENCL_C_VERSION__ is defined for +// OpenCL v1.0 and v1.1. +switch (LangOpts.OpenCLVersion) { +case 100: + Builder.defineMacro("__OPENCL_C_VERSION__", "100"); + break; +case 110: + Builder.defineMacro("__OPENCL_C_VERSION__", "110"); + break; +case 120: + Builder.defineMacro("__OPENCL_C_VERSION__", "120"); + break; +case 200: +
Re: [PATCH] D19071: [OpenCL] Add predefined macros.
yaxunl updated this revision to Diff 54404. yaxunl added a comment. Fix test/preprocessor/predefined_macros.c. Merge test/frontend/std.cl into langstd.c since they are similar. http://reviews.llvm.org/D19071 Files: lib/Frontend/CompilerInvocation.cpp lib/Frontend/InitPreprocessor.cpp test/Frontend/std.cl test/Frontend/stdlang.c test/Preprocessor/predefined-macros.c Index: test/Preprocessor/predefined-macros.c === --- test/Preprocessor/predefined-macros.c +++ test/Preprocessor/predefined-macros.c @@ -146,3 +146,36 @@ // CHECK-SYNC_CAS_MIPS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1 // CHECK-SYNC_CAS_MIPS32-NOT: __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 // CHECK-SYNC_CAS_MIPS64: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1 + +// RUN: %clang_cc1 %s -E -dM -o - -x cl \ +// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-CL10 +// RUN: %clang_cc1 %s -E -dM -o - -x cl -cl-std=CL1.1 \ +// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-CL11 +// RUN: %clang_cc1 %s -E -dM -o - -x cl -cl-std=CL1.2 \ +// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-CL12 +// RUN: %clang_cc1 %s -E -dM -o - -x cl -cl-std=CL2.0 \ +// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-CL20 +// RUN: %clang_cc1 %s -E -dM -o - -x cl -cl-fast-relaxed-math \ +// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-FRM +// CHECK-CL10: #define CL_VERSION_1_0 100 +// CHECK-CL10: #define CL_VERSION_1_1 110 +// CHECK-CL10: #define CL_VERSION_1_2 120 +// CHECK-CL10: #define CL_VERSION_2_0 200 +// CHECK-CL10: #define __OPENCL_C_VERSION__ 100 +// CHECK-CL11: #define CL_VERSION_1_0 100 +// CHECK-CL11: #define CL_VERSION_1_1 110 +// CHECK-CL11: #define CL_VERSION_1_2 120 +// CHECK-CL11: #define CL_VERSION_2_0 200 +// CHECK-CL11: #define __OPENCL_C_VERSION__ 110 +// CHECK-CL12: #define CL_VERSION_1_0 100 +// CHECK-CL12: #define CL_VERSION_1_1 110 +// CHECK-CL12: #define CL_VERSION_1_2 120 +// CHECK-CL12: #define CL_VERSION_2_0 200 +// CHECK-CL12: #define __OPENCL_C_VERSION__ 120 +// CHECK-CL20: #define CL_VERSION_1_0 100 +// CHECK-CL20: #define CL_VERSION_1_1 110 +// CHECK-CL20: #define CL_VERSION_1_2 120 +// CHECK-CL20: #define CL_VERSION_2_0 200 +// CHECK-CL20: #define __OPENCL_C_VERSION__ 200 +// CHECK-FRM: #define __FAST_RELAXED_MATH__ 1 + Index: test/Frontend/stdlang.c === --- test/Frontend/stdlang.c +++ test/Frontend/stdlang.c @@ -1,5 +1,13 @@ -// RUN: %clang_cc1 -x cuda -std=c++11 -DCUDA %s -// RUN: %clang_cc1 -x cl -std=c99 -DOPENCL %s +// RUN: %clang_cc1 -verify -x cuda -std=c++11 -DCUDA %s +// RUN: %clang_cc1 -verify -x cl -DOPENCL %s +// RUN: %clang_cc1 -verify -x cl -cl-std=CL -DOPENCL %s +// RUN: %clang_cc1 -verify -x cl -cl-std=CL1.1 -DOPENCL %s +// RUN: %clang_cc1 -verify -x cl -cl-std=CL1.2 -DOPENCL %s +// RUN: %clang_cc1 -verify -x cl -cl-std=CL2.0 -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' +// CHECK-INVALID: error: invalid value 'invalid' in '-cl-std=invalid' // expected-no-diagnostics #if defined(CUDA) Index: test/Frontend/std.cl === --- test/Frontend/std.cl +++ /dev/null @@ -1,9 +0,0 @@ -// RUN: %clang_cc1 %s -fsyntax-only -cl-std=CL -// RUN: %clang_cc1 %s -fsyntax-only -cl-std=CL1.1 -// RUN: %clang_cc1 %s -fsyntax-only -cl-std=CL1.2 -// RUN: %clang_cc1 %s -fsyntax-only -cl-std=CL2.0 -// RUN: not %clang_cc1 %s -fsyntax-only -cl-std=invalid -DINVALID 2>&1 | FileCheck %s - -#ifdef INVALID -// CHECK: invalid value 'invalid' in '-cl-std=invalid' -#endif Index: lib/Frontend/InitPreprocessor.cpp === --- lib/Frontend/InitPreprocessor.cpp +++ lib/Frontend/InitPreprocessor.cpp @@ -408,6 +408,39 @@ if (LangOpts.ObjC1) Builder.defineMacro("__OBJC__"); + // OpenCL v1.0/1.1 s6.9, v1.2/2.0 s6.10: Preprocessor Directives and Macros. + if (LangOpts.OpenCL) { +// 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 +// necessarily the language standard with which the program is compiled. +// A shared OpenCL header file requires a macro to indicate the language +// standard. As a workaround, __CLANG_OPENCL_C_VERSION__ is defined for +// OpenCL v1.0 and v1.1. +switch (LangOpts.OpenCLVersion) { +case 100: + Builder.defineMacro("__OPENCL_C_VERSION__", "100"); + break; +case 110: + Builder.defineMacro("__OPENCL_C_VERSION__", "110"); + break; +
Re: [PATCH] D19071: [OpenCL] Add predefined macros.
Anastasia added inline comments. Comment at: lib/Frontend/InitPreprocessor.cpp:421 @@ +420,3 @@ +switch (LangOpts.OpenCLVersion) { +case 100: + Builder.defineMacro("__OPENCL_C_VERSION__", "100"); Yes, perfectly makes sense. I don't think passing C std flag should be allowed since OpenCL is based strictly on C99 and use of other versions are not possible anyways. Nice cleanup! Comment at: lib/Frontend/InitPreprocessor.cpp:439 @@ +438,3 @@ +Builder.defineMacro("CL_VERSION_1_2", "120"); +Builder.defineMacro("CL_VERSION_2_0", "200"); + Could you update the test please. Comment at: test/Frontend/stdlang.c:10 @@ -3,1 +9,3 @@ +#ifndef OPENCL_C99 // expected-no-diagnostics +#endif I think expected-no-diagnostics is only used if -verify is passed. http://reviews.llvm.org/D19071 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D19071: [OpenCL] Add predefined macros.
yaxunl updated the summary for this revision. yaxunl updated this revision to Diff 54243. yaxunl marked an inline comment as done. yaxunl added a comment. Added __OPENCL_C_VERSION__ and CL_VERSION_X_Y for all OpenCL versions. Also fixed the test using -std=c99 for OpenCL and limit allowed language standard for OpenCL. I think an OpenCL program by definition should follow certain OpenCL language standard. http://reviews.llvm.org/D19071 Files: lib/Frontend/CompilerInvocation.cpp lib/Frontend/InitPreprocessor.cpp test/Frontend/stdlang.c test/Preprocessor/predefined-macros.c Index: test/Preprocessor/predefined-macros.c === --- test/Preprocessor/predefined-macros.c +++ test/Preprocessor/predefined-macros.c @@ -146,3 +146,30 @@ // CHECK-SYNC_CAS_MIPS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1 // CHECK-SYNC_CAS_MIPS32-NOT: __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 // CHECK-SYNC_CAS_MIPS64: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1 + +// RUN: %clang_cc1 %s -E -dM -o - -x cl \ +// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-CL10 +// RUN: %clang_cc1 %s -E -dM -o - -x cl -cl-std=CL1.1 \ +// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-CL11 +// RUN: %clang_cc1 %s -E -dM -o - -x cl -cl-std=CL1.2 \ +// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-CL12 +// RUN: %clang_cc1 %s -E -dM -o - -x cl -cl-std=CL2.0 \ +// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-CL20 +// RUN: %clang_cc1 %s -E -dM -o - -x cl -cl-fast-relaxed-math \ +// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-FRM +// CHECK-CL10: #define CL_VERSION_1_0 100 +// CHECK-CL10: #define __OPENCL_C_VERSION__ 100 +// CHECK-CL11: #define CL_VERSION_1_0 100 +// CHECK-CL11: #define CL_VERSION_1_1 110 +// CHECK-CL11: #define __OPENCL_C_VERSION__ 110 +// CHECK-CL12: #define CL_VERSION_1_0 100 +// CHECK-CL12: #define CL_VERSION_1_1 110 +// CHECK-CL12: #define CL_VERSION_1_2 120 +// CHECK-CL12: #define __OPENCL_C_VERSION__ 120 +// CHECK-CL20: #define CL_VERSION_1_0 100 +// CHECK-CL20: #define CL_VERSION_1_1 110 +// CHECK-CL20: #define CL_VERSION_1_2 120 +// CHECK-CL20: #define CL_VERSION_2_0 200 +// CHECK-CL20: #define __OPENCL_C_VERSION__ 200 +// CHECK-FRM: #define __FAST_RELAXED_MATH__ 1 + Index: test/Frontend/stdlang.c === --- test/Frontend/stdlang.c +++ test/Frontend/stdlang.c @@ -1,9 +1,17 @@ // RUN: %clang_cc1 -x cuda -std=c++11 -DCUDA %s -// RUN: %clang_cc1 -x cl -std=c99 -DOPENCL %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: not %clang_cc1 -x cl -std=c99 -DOPENCL_C99 %s 2>&1 | FileCheck %s +// CHECK: error: invalid argument '-std=c99' not allowed with 'OpenCL' +#ifndef OPENCL_C99 // expected-no-diagnostics +#endif #if defined(CUDA) __attribute__((device)) void f_device(); -#elif defined(OPENCL) +#elif defined(OPENCL) || defined(OPENCL_C99) kernel void func(void); #endif Index: lib/Frontend/InitPreprocessor.cpp === --- lib/Frontend/InitPreprocessor.cpp +++ lib/Frontend/InitPreprocessor.cpp @@ -408,6 +408,39 @@ if (LangOpts.ObjC1) Builder.defineMacro("__OBJC__"); + // OpenCL v1.0/1.1 s6.9, v1.2/2.0 s6.10: Preprocessor Directives and Macros. + if (LangOpts.OpenCL) { +// 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 +// necessarily the language standard with which the program is compiled. +// A shared OpenCL header file requires a macro to indicate the language +// standard. As a workaround, __CLANG_OPENCL_C_VERSION__ is defined for +// OpenCL v1.0 and v1.1. +switch (LangOpts.OpenCLVersion) { +case 100: + Builder.defineMacro("__OPENCL_C_VERSION__", "100"); + break; +case 110: + Builder.defineMacro("__OPENCL_C_VERSION__", "110"); + break; +case 120: + Builder.defineMacro("__OPENCL_C_VERSION__", "120"); + break; +case 200: + Builder.defineMacro("__OPENCL_C_VERSION__", "200"); + break; +default: + llvm_unreachable("Unsupported OpenCL version"); +} +Builder.defineMacro("CL_VERSION_1_0", "100"); +Builder.defineMacro("CL_VERSION_1_1", "110"); +Builder.defineMacro("CL_VERSION_1_2", "120"); +Builder.defineMacro("CL_VERSION_2_0", "200"); + +if (LangOpts.FastRelaxedMath) + Builder.defineMacro("__FAST_RELAXED_MATH__"); + } // Not "standard" per se, but available even with the -undef flag. if (LangOpts.AsmPreprocessor) Builder.defineMacro("__ASSEMBLER__");
Re: [PATCH] D19071: [OpenCL] Add predefined macros.
yaxunl marked 7 inline comments as done. Comment at: lib/Frontend/InitPreprocessor.cpp:421 @@ +420,3 @@ +switch (LangOpts.OpenCLVersion) { +case 0: +case 100: yaxunl wrote: > pxli168 wrote: > > What is 0 stand for as OpenCLVersion, it seems the default OpenCLVersion if > > we did not pass any -cl-std=CLXX is 100. > > So maybe we did not need this case 0: > There is a test test/Frontend/stdlang.c: > > // RUN: %clang_cc1 -x cl -std=c99 -DOPENCL %s > > With this test, LangOpts.OpenCL is 1 but LangOpts.OpenCLVersion is 0. > > If we all agree that this test is invalid and -x cl can only be compiled with > OpenCL language standard and the default one is OpenCL 1.0, I can fix that > test first and then remove case 0 in this switch. Anastasia, What's your opinion on this? Should we limit the allowed language standard for cl to OpenCL standard only? Should I diagnose invalid language standard and also add a lit test for that? Thanks. Comment at: lib/Frontend/InitPreprocessor.cpp:439 @@ +438,3 @@ +if (LangOpts.OpenCLVersion >= 110) + Builder.defineMacro("CL_VERSION_1_1", "110"); +if (LangOpts.OpenCLVersion >= 120) Anastasia wrote: > yaxunl wrote: > > yaxunl wrote: > > > pxli168 wrote: > > > > These macros maybe need for all cl version, and in the header we should > > > > compare __OPENCL_C_VERSION__ with CL_VERSION_2_0 instead of the > > > > integer 200 in the header of http://reviews.llvm.org/D18369? > > > Each OpenCL version only defines some of these macros by spec. > > > > > > In the header file `__OPENCL_C_VERSION__` can compare with 200 since the > > > spec defines the integer value for `__OPENCL_C_VERSION__`. Comparing with > > > CL_VERSION_2_0 requires checking CL_VERSION_2_0 is available first. I > > > think probably I can define a macro > > > > > > #define _OPENCL20_AND_ABOVE defined(__OPENCL_C_VERSION__) and > > > defined(CL_VERSION_2_0) and __OPENCL_C_VERSION__ >= 200 > > > > > > and then use this macro for conditioning 2.0 specific functions. > > should be > > > > #if defined(__OPENCL_C_VERSION__) && defined(CL_VERSION_2_0) && > > __OPENCL_C_VERSION__ >= CL_VERSION_2_0 > > #define _CL20_AND_ABOVE 1 > > #endif > > > Where do you plan to add this code? > > My point is that the code is a bit complicated and messy with this checks and > on the other hand it's kind of logical that compiler supporting all CL > version would also accept all CL_VERSION_X_Y macros irrespectively from the > passed -cl-std flag... I don't think spec is being that explicit on how CL2.0 > compliant compiler should enable those macros when earlier versions of > -cl-std are being passed. OK I will add these macros. http://reviews.llvm.org/D19071 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D19071: [OpenCL] Add predefined macros.
Anastasia added inline comments. Comment at: lib/Frontend/InitPreprocessor.cpp:439 @@ +438,3 @@ +if (LangOpts.OpenCLVersion >= 110) + Builder.defineMacro("CL_VERSION_1_1", "110"); +if (LangOpts.OpenCLVersion >= 120) yaxunl wrote: > yaxunl wrote: > > pxli168 wrote: > > > These macros maybe need for all cl version, and in the header we should > > > compare __OPENCL_C_VERSION__ with CL_VERSION_2_0 instead of the integer > > > 200 in the header of http://reviews.llvm.org/D18369? > > Each OpenCL version only defines some of these macros by spec. > > > > In the header file `__OPENCL_C_VERSION__` can compare with 200 since the > > spec defines the integer value for `__OPENCL_C_VERSION__`. Comparing with > > CL_VERSION_2_0 requires checking CL_VERSION_2_0 is available first. I think > > probably I can define a macro > > > > #define _OPENCL20_AND_ABOVE defined(__OPENCL_C_VERSION__) and > > defined(CL_VERSION_2_0) and __OPENCL_C_VERSION__ >= 200 > > > > and then use this macro for conditioning 2.0 specific functions. > should be > > #if defined(__OPENCL_C_VERSION__) && defined(CL_VERSION_2_0) && > __OPENCL_C_VERSION__ >= CL_VERSION_2_0 > #define _CL20_AND_ABOVE 1 > #endif > Where do you plan to add this code? My point is that the code is a bit complicated and messy with this checks and on the other hand it's kind of logical that compiler supporting all CL version would also accept all CL_VERSION_X_Y macros irrespectively from the passed -cl-std flag... I don't think spec is being that explicit on how CL2.0 compliant compiler should enable those macros when earlier versions of -cl-std are being passed. http://reviews.llvm.org/D19071 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D19071: [OpenCL] Add predefined macros.
yaxunl marked 6 inline comments as done. Comment at: lib/Frontend/InitPreprocessor.cpp:426 @@ +425,3 @@ +case 110: + Builder.defineMacro("__CLANG_OPENCL_C_VERSION__", "110"); + break; Anastasia wrote: > So why we can't use unified __OPENCL_C_VERSION__? `__OPENCL_C_VERSION__` is not defined in OpenCL spec v1.0 and 1.1. Comment at: lib/Frontend/InitPreprocessor.cpp:438 @@ +437,3 @@ +Builder.defineMacro("CL_VERSION_1_0", "100"); +if (LangOpts.OpenCLVersion >= 110) + Builder.defineMacro("CL_VERSION_1_1", "110"); Anastasia wrote: > I am not sure we should add this conditionally though. If you want to compile > CL code like this (forcing pointer to point to private AS for all CL versions > the code is compiled for): > > #if __OPENCL_C_VERSION__ >= CL_VERSION_2_0 > private void* priv_ptr; > #else > void* priv_ptr; > #endif > > This code would fail with -cl-sdt=CL1.1 (because CL_VERSION_2_0 is no longer > defined), but the purpose of having version macros is to be able to condition > on the passed CL version in the particular compilation run to avoid the > compiler failure/miscompilation. This way we provide a way to select the > right CL code for all versions the code is being compiled (if such selection > is needed) to allow portability of CL code among OpenCL version. CL_VERSION_x_y is only defined in OpenCL spec version equal or above x.y. We can use macros like #if defined(__OPENCL_C_VERSION__) && defined(CL_VERSION_2_0) && __OPENCL_C_VERSION__ >= CL_VERSION_2_0 #define _CL20_AND_ABOVE 1 #endif Comment at: lib/Frontend/InitPreprocessor.cpp:439 @@ +438,3 @@ +if (LangOpts.OpenCLVersion >= 110) + Builder.defineMacro("CL_VERSION_1_1", "110"); +if (LangOpts.OpenCLVersion >= 120) yaxunl wrote: > pxli168 wrote: > > These macros maybe need for all cl version, and in the header we should > > compare __OPENCL_C_VERSION__ with CL_VERSION_2_0 instead of the integer > > 200 in the header of http://reviews.llvm.org/D18369? > Each OpenCL version only defines some of these macros by spec. > > In the header file `__OPENCL_C_VERSION__` can compare with 200 since the spec > defines the integer value for `__OPENCL_C_VERSION__`. Comparing with > CL_VERSION_2_0 requires checking CL_VERSION_2_0 is available first. I think > probably I can define a macro > > #define _OPENCL20_AND_ABOVE defined(__OPENCL_C_VERSION__) and > defined(CL_VERSION_2_0) and __OPENCL_C_VERSION__ >= 200 > > and then use this macro for conditioning 2.0 specific functions. should be #if defined(__OPENCL_C_VERSION__) && defined(CL_VERSION_2_0) && __OPENCL_C_VERSION__ >= CL_VERSION_2_0 #define _CL20_AND_ABOVE 1 #endif http://reviews.llvm.org/D19071 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D19071: [OpenCL] Add predefined macros.
Anastasia added inline comments. Comment at: lib/Frontend/InitPreprocessor.cpp:426 @@ +425,3 @@ +case 110: + Builder.defineMacro("__CLANG_OPENCL_C_VERSION__", "110"); + break; So why we can't use unified __OPENCL_C_VERSION__? Comment at: lib/Frontend/InitPreprocessor.cpp:438 @@ +437,3 @@ +Builder.defineMacro("CL_VERSION_1_0", "100"); +if (LangOpts.OpenCLVersion >= 110) + Builder.defineMacro("CL_VERSION_1_1", "110"); I am not sure we should add this conditionally though. If you want to compile CL code like this (forcing pointer to point to private AS for all CL versions the code is compiled for): #if __OPENCL_C_VERSION__ >= CL_VERSION_2_0 private void* priv_ptr; #else void* priv_ptr; #endif This code would fail with -cl-sdt=CL1.1 (because CL_VERSION_2_0 is no longer defined), but the purpose of having version macros is to be able to condition on the passed CL version in the particular compilation run to avoid the compiler failure/miscompilation. This way we provide a way to select the right CL code for all versions the code is being compiled (if such selection is needed) to allow portability of CL code among OpenCL version. http://reviews.llvm.org/D19071 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D19071: [OpenCL] Add predefined macros.
yaxunl added inline comments. Comment at: lib/Frontend/InitPreprocessor.cpp:421 @@ +420,3 @@ +switch (LangOpts.OpenCLVersion) { +case 0: +case 100: pxli168 wrote: > What is 0 stand for as OpenCLVersion, it seems the default OpenCLVersion if > we did not pass any -cl-std=CLXX is 100. > So maybe we did not need this case 0: There is a test test/Frontend/stdlang.c: // RUN: %clang_cc1 -x cl -std=c99 -DOPENCL %s With this test, LangOpts.OpenCL is 1 but LangOpts.OpenCLVersion is 0. If we all agree that this test is invalid and -x cl can only be compiled with OpenCL language standard and the default one is OpenCL 1.0, I can fix that test first and then remove case 0 in this switch. Comment at: lib/Frontend/InitPreprocessor.cpp:439 @@ +438,3 @@ +if (LangOpts.OpenCLVersion >= 110) + Builder.defineMacro("CL_VERSION_1_1", "110"); +if (LangOpts.OpenCLVersion >= 120) pxli168 wrote: > These macros maybe need for all cl version, and in the header we should > compare __OPENCL_C_VERSION__ with CL_VERSION_2_0 instead of the integer 200 > in the header of http://reviews.llvm.org/D18369? Each OpenCL version only defines some of these macros by spec. In the header file `__OPENCL_C_VERSION__` can compare with 200 since the spec defines the integer value for `__OPENCL_C_VERSION__`. Comparing with CL_VERSION_2_0 requires checking CL_VERSION_2_0 is available first. I think probably I can define a macro #define _OPENCL20_AND_ABOVE defined(__OPENCL_C_VERSION__) and defined(CL_VERSION_2_0) and __OPENCL_C_VERSION__ >= 200 and then use this macro for conditioning 2.0 specific functions. http://reviews.llvm.org/D19071 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D19071: [OpenCL] Add predefined macros.
pxli168 added inline comments. Comment at: lib/Frontend/InitPreprocessor.cpp:421 @@ +420,3 @@ +switch (LangOpts.OpenCLVersion) { +case 0: +case 100: What is 0 stand for as OpenCLVersion, it seems the default OpenCLVersion if we did not pass any -cl-std=CLXX is 100. So maybe we did not need this case 0: Comment at: lib/Frontend/InitPreprocessor.cpp:439 @@ +438,3 @@ +if (LangOpts.OpenCLVersion >= 110) + Builder.defineMacro("CL_VERSION_1_1", "110"); +if (LangOpts.OpenCLVersion >= 120) These macros maybe need for all cl version, and in the header we should compare __OPENCL_C_VERSION__ with CL_VERSION_2_0 instead of the integer 200 in the header of http://reviews.llvm.org/D18369? http://reviews.llvm.org/D19071 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D19071: [OpenCL] Add predefined macros.
bader added a comment. LGTM http://reviews.llvm.org/D19071 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits