[cfe-dev] Allow implicit copy constructor between address spaces in C++
Alp Toker
alp at nuanti.com
Sun May 4 10:35:38 PDT 2014
I'm not sure an attribute makes sense if you're looking for C-style
assignment.
Try adding a builtin instead:
Builtins.def:
BUILTIN(__builtin_assign, "v.", "t")
SemaChecking.cpp:
case Builtin::BI__builtin_assign:
if (checkArgCount(*this, TheCall, 2)) return true;
return CreateBuiltinBinOp(TheCall->getLocStart(), BO_Assign,
TheCall->getArg(0), TheCall->getArg(1));
Usage, ignoring harmless asserts:
#ifdef __cplusplus
#define assign(x,y) __builtin_assign(x,y)
#else
#define assign(x,y) (x = y)
#endif
assign(r, a[0]);
On the other hand there's an expectation that valid C often builds in
C++ mode so it might be worth using CXXRecordDecl::isCLike() to support
the C syntax directly in C++ as an extension.
Alp.
On 03/05/2014 21:31, Adam Strzelecki wrote:
> FYI. Continuing my effort I have added "pod_assign" variable attribute, that triggers POD assign rather than constructor on object (behavior described in previous post). There was nothing better that came to my mind to circumvent problems described previously.
>
> https://github.com/ujhpc/clang/commits/patch/pod-assign-attr
> https://github.com/ujhpc/clang/commits/patch/openclxx
>
> Here is working code:
>
>> struct Point {
>> float x, y;
>> };
>> typedef struct Point Point;
>>
>> float test(int i, // index
>> __attribute__((address_space(1))) const Point *in,
>> __attribute__((address_space(1))) Point *out) {
>> __attribute__((pod_assign)) Point r = in[i];
>> out[i] = r;
>> return r.x * r.y;
>> }
> Now both C++ and C modes generate identical ll assembly. Now it is time to test whether using C++ goodness will produce runnable SPIR kernels.
>
> Regards,
--
http://www.nuanti.com
the browser experts
More information about the cfe-dev
mailing list