http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59287
Bug ID: 59287 Summary: points-to analysis confused by union accesses Product: gcc Version: 4.9.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: rguenth at gcc dot gnu.org static void get_constraint_for_component_ref (tree t, vec<ce_s> *results, bool address_p, bool lhs_p) { ... /* Handle type-punning through unions. If we are extracting a pointer from a union via a possibly type-punning access that pointer points to anything, similar to a conversion of an integer to a pointer. */ if (!lhs_p) { tree u; for (u = t; TREE_CODE (u) == COMPONENT_REF || TREE_CODE (u) == ARRAY_REF; u = TREE_OPERAND (u, 0)) if (TREE_CODE (u) == COMPONENT_REF && TREE_CODE (TREE_TYPE (TREE_OPERAND (u, 0))) == UNION_TYPE) { struct constraint_expr temp; temp.offset = 0; temp.var = anything_id; temp.type = ADDRESSOF; results->safe_push (temp); return; } } has the adverse affect that if you have code like foo (TREE_CODE (t)) then it makes ANYTHING escape ... which is the worst thing that can happen. The above shouldn't be necessary.