Check assignment attributes compatibility

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() 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

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.