Check assignment attributes compatibility

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Check assignment attributes compatibility

Eric Fiselier via cfe-dev
Hi,

I am new to clang development, and I would like to have some warnings if an assignment of function pointer doesn't match the LHS attributes: void __attribute__((Attrs)) (*func)() = foo should warn if foo doesn't have Attrs.

I have started adding some code around Sema::CheckSingleAssignmentConstraints. I can get the attrs from the LHS, LHSType.getTypePtr() / ->getAs<TypedefType>() if necessary / ->getDecl() and use attribute getters. However, I have more trouble with the RHS for some reason, RHS.get()->getType() is a FunctionProtoType. How can I get the associated attributes from there?

thanks a lot
--
Marc-André Lureau

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Check assignment attributes compatibility

Eric Fiselier via cfe-dev
Attributes are not reflected in the canonical type. They may only appear on the fully-sugared type, which isn't always available. Some attributes, like calling convention attributes, noreturn, regparm, and some other misc things, are embedded in the canonical FunctionProtoType, but this is only implemented on a case-by-case basis as required by overload resolution and other language extension rules.

I think your best path forward is to embed the attributes you care about in FunctionProtoType::ExtProtoInfo.

On Sun, Jul 2, 2017 at 7:05 AM, Marc-André Lureau via cfe-dev <[hidden email]> wrote:
Hi,

I am new to clang development, and I would like to have some warnings if an assignment of function pointer doesn't match the LHS attributes: void __attribute__((Attrs)) (*func)() = foo should warn if foo doesn't have Attrs.

I have started adding some code around Sema::CheckSingleAssignmentConstraints. I can get the attrs from the LHS, LHSType.getTypePtr() / ->getAs<TypedefType>() if necessary / ->getDecl() and use attribute getters. However, I have more trouble with the RHS for some reason, RHS.get()->getType() is a FunctionProtoType. How can I get the associated attributes from there?

thanks a lot
--
Marc-André Lureau

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev



_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev