Question about OpenCL language standard option

Hi all,

I got a error from a opencl test. The test code is as following:

source code:
__kernel void test_fn(__global uint *src, __global uint4 *results) {
   const size_t SIZE = 128;
   int tid = get_global_id(0);
   if (tid*4 >= SIZE)
   __private uint sPrivateStorage[SIZE];
   for (size_t i=0 ; i<SIZE ; i++)
     sPrivateStorage[i] = src[i];
   results[tid] = vload4(tid, sPrivateStorage);

and the error message is as following:

"error: variable length arrays are not supported in OpenCL
   __private uint sPrivateStorage[SIZE];"

The problem is that 'isArraySizeVLA' function calls 'VerifyIntegerConstantExpression' with 'S.LangOpts.GNUMode'. The OpenCL Language standard option does not have this option. It causes a error because 'AllowFold' is not set to 1. In order to fix this error, I think that we need to insert 'GNUMode' to OpenCL LANGSTANDARD or modify sligtly checking code. How do you feel about this? I can not guarantee the side effect of 'GNUMode' with OpenCL. I have attached a simple patch as reference. If there is something wrong, please let me know.

JinGu Kang

clang.patch (1.3 KB)

Hi JinGu,

I'm not sure I understand.. VLAs are *not* supported in OpenCL. See Restrictions 6.9.d.


Joey, JinGu,

I believe JinGu was expecting the array to be not-a-VLA, because its
size is "const". In C++ JinGu would be correct; that array's size *is*
a compile-time constant in C++, but in C (and therefore in OpenCL)
it's not constant, because it depends on the value of a variable. (The
variable's type happens to be const-qualified, but that doesn't matter
in C.)

If this test case came from an official OpenCL test suite, IMHO the
right course of action is almost certainly to contact the maker of
that test suite and get them to change their test, rather than add an
extension to Clang just for this one special case. (Alternatively, is
there such a thing as OpenCL++? Should this test be compiled in that


Hi Arthur, Joey,

I appreciate your response. As Arthur mentioned, I assumed this is not VLA because there is 'const' qualifier and this example is included in one OpenCL test-suite and clang folded this with 'GNUMode' not VLA. I am sorry it was my mistake. Thank you for your response, again.

JinGu Kang

2013-11-30 오전 10:59, Arthur O'Dwyer 쓴 글: