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__"); Index: lib/Frontend/CompilerInvocation.cpp =================================================================== --- lib/Frontend/CompilerInvocation.cpp +++ 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:
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits