+ bool packedp = false;
+
+ if (TREE_CODE(to) == COMPONENT_REF
+&& (TYPE_PACKED (TREE_TYPE (TREE_OPERAND (to, 0)))
+ || (TREE_CODE (TREE_OPERAND (to, 1)) == FIELD_DECL
+&& DECL_PACKED (TREE_OPERAND (to, 1)))))
+ packedp = true;
note that this is not a reliable way of determining if a field is packed
(yes, the existing code is broken in the same way). I realize that you
are only using this for diagnostic purposes, still something worth
mentioning.
Indeed, ideally DECL_PACKED shouldn't be used outside stor-layout.c and
dwarf2out.c in the middle-end.
I dislike passing around the packedp flag throughout the expander and to
warn inside the expander. First, the flag has a name that can be confusing
(it does not conservatively flag all packed accesses). Second, why don't
you warn for this from inside the frontend when the bitfield access is
generated? This way the diagnostic won't depend on optimization levels
and you avoid uglifying the expander.
Seconded. If the -fstrict-volatile-bitfields support is still incomplete,
let's take this opportunity to clean it up. Testing DECL_PACKED or issuing
a warning from the RTL expander is to be avoided.