[cfe-commits] [PATCH] OpenCL error for elements in a struct

Anton Lokhmotov Anton.Lokhmotov at arm.com
Thu Jun 14 04:08:56 PDT 2012


Hi Tanya,

> OpenCL does not allow elements of a struct to be in different address
> spaces. The attached patch checks for this and throws an error. It
> includes a test case.

I can see how your patch attempts to directly support the following
restriction in the spec:

"Elements of a struct or union must belong to the same address space.
Declaring a struct
or union whose elements are in different address spaces is illegal."

(Seems to be unchanged since OpenCL v1.0; 6.8.o in OpenCL v1.1).

However, I think it's a flaw in the spec as elements of a struct or union
should not have any address space qualifiers.

In fact, there's an assertion in clang/lib/Sema/SemaExprMember.cpp:1611
which on:

__kernel void abc()
{
  struct __e {
    __local int a;
    __local int b;
  } x;

 x.a = 1;
 x.b = 2;
}

produces:

clang::ExprResult BuildFieldReferenceExpr(clang::Sema&, clang::Expr*, bool,
const clang::CXXScopeSpec&, clang::FieldDecl*, clang::DeclAccessPair, const
clang::DeclarationNameInfo&): Assertion `!MemberQuals.hasAddressSpace()'
failed.
Stack dump:
0.      11.cl:8:6: current parser token '='
1.      11.cl:2:1: parsing function body 'abc'
2.      11.cl:2:1: in compound statement ('{}')
Aborted

So I'm not sure this check should be implemented, although better error
handling (than just an assertion) of address space qualifiers on struct and
union members would be most welcome!

Best, Anton.







More information about the cfe-commits mailing list