[cfe-dev] Allow implicit copy constructor between address spaces in C++

Alp Toker alp at nuanti.com
Sun May 4 18:47:39 PDT 2014


On 05/05/2014 01:08, Adam Strzelecki wrote:
> Unfortunately it doesn’t work for me. Clang throws an assertion about what I should do, while I am trying do exactly opposite  :>

Like I mentioned you can remove any assertions arising to see it in 
action because we're intentionally using the C code path in this quick 
patch.

There's a case for providing compatibility with the C assignment syntax 
for C-like POD structs in C++ given the neat upgrade path.

I'm intrigued by the suggestion of doing this with a template -- 
Richard, could you expound on that?

Alp.



>
> clang-3.5: /home/ono/Projects/llvm/tools/clang/lib/AST/ExprClassification.cpp:619: clang::Expr::Classification::ModifiableType IsModifiable(clang::ASTContext&, const clang::Expr*, clang::Expr::Classification::Kinds, clang::SourceLocation&): Assertion `(E->getObjectKind() == OK_ObjCProperty || !Ctx.getLangOpts().CPlusPlus) && "C++ struct assignment should be resolved by the " "copy assignment operator."' failed.
>
> Code I am testing on:
>
> typedef struct Point { float x, y; } Point;
> float test(int i, //
>             __attribute__((address_space(1))) const Point *in,
>             __attribute__((address_space(1))) Point *out) {
>    Point r;
>    __builtin_assign(r, in[i]);
>    out[i] = r;
>    return r.x * r.y;
> }
>
> Change proposed by Alp:
>
> --- a/include/clang/Basic/Builtins.def
> +++ b/include/clang/Basic/Builtins.def
> @@ -1204,6 +1204,7 @@ BUILTIN(__builtin_smulll_overflow, "bSLLiCSLLiCSLLi*", "n")
>   
>   // Clang builtins (not available in GCC).
>   BUILTIN(__builtin_addressof, "v*v&", "nct")
> +BUILTIN(__builtin_assign, "v.", "t")
>   
>   #undef BUILTIN
>   #undef LIBBUILTIN
> --- a/lib/Sema/SemaChecking.cpp
> +++ b/lib/Sema/SemaChecking.cpp
> @@ -296,6 +296,12 @@ Sema::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
>       if (SemaBuiltinAddressof(*this, TheCall))
>         return ExprError();
>       break;
> +  case Builtin::BI__builtin_assign:
> +    if (checkArgCount(*this, TheCall, 2))
> +      return true;
> +    return CreateBuiltinBinOp(TheCall->getLocStart(), BO_Assign,
> +                              TheCall->getArg(0), TheCall->getArg(1));
> +    break;
>     }

-- 
http://www.nuanti.com
the browser experts




More information about the cfe-dev mailing list