https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122483
--- Comment #34 from Alex Coplan <acoplan at gcc dot gnu.org> --- I'd just like to note some inconsistency in the implementation of r16-4667-gdcf69bdcd49bcc that came up in the ML discussion. I ended up taking a closer look at this following Joseph's comments on what the rules should be. Consider the following C testcase on x86-64, compiled with -fcf-protection: ``` /* Accepted: although comp_type_attributes returns 0, we override it with the !TYPE_ATTRIBUTES (newdecl) clause. */ int f1(int) [[gnu::nocf_check]]; int f1(int); /* Rejected: comp_type_attributes -> 0, no !TYPE_ATTRIBUTES (newdecl) override. */ int f2(int); int f2(int) [[gnu::nocf_check]]; /* Accepted: reproducible does not affect type identity, so the types are compatible. */ int f3(int); int f3(int) [[reproducible]]; /* Accepted (as above), no override needed. */ int f4(int) [[reproducible]]; int f4(int); /* Accepted again due to the !TYPE_ATTRIBTUES (newdecl) override. But the first of these being accepted shows at least that the attributes are mutually compatible. */ int f5(int) [[gnu::nocf_check, reproducible]]; int f5(int); /* Rejected, but should it be? Given we allow the f1, f3, and f5 decl pairs here, it is arguably inconsistent to reject this case. */ int f6(int) [[gnu::nocf_check]]; int f6(int) [[reproducible]]; /* Rejected as per f2. */ int f7(int) [[reproducible]]; int f7(int) [[gnu::nocf_check]]; ``` (https://godbolt.org/z/7z9q9eo5d). That example (particularly f6 being rejected) shows that the current logic is inconsistent. Perhaps a more consistent rule would be to change the condition for the "override" clause firing to be "do none of the attributes in TYPE_ATTRIBUTES (newdecl) affect type identity" instead of checking just !TYPE_ATTRIBUTES (newdecl). Just for clarity, by "override clause" I mean the clause in c/decl.cc:diagnose_mismatched_decls added by r16-4667, starting with: + { + if (TREE_CODE (olddecl) == FUNCTION_DECL) + { + tree attrs = TYPE_ATTRIBUTES (TREE_TYPE (olddecl)); + if (attrs && !TYPE_ATTRIBUTES (TREE_TYPE (newdecl))) I don't feel strongly either way, and I think that particular decision is largely orthogonal to what we want to do for arm::streaming and friends (i.e. not allow the comptypes result to be overriden by such logic), but it seemed worth noting here for reference and in case others feel that we ought to change those semantics. It also shows that this inconsistency is a property of the logic in r16-4667 (and pre-existing C++ frontend behaviour) and not a property of the patches on the list.
