The following fixes a mistake in an earlier patch of mine fixing PR71002. fold-const.c make_bit_field_ref doesn't care about alias sets of references it merges but as it commons to a common base it assumed the original refs were aliased by the new one. The testcase of PR71002 shows this is not true for union references which are punned to alias-set zero. Now my fix retained the alias-set of (one of!) the original refs if it wasn't equal to the alias-set of the common inner ref. That obviously breaks things if the alias sets of the other original refs do not alias this one.
The following rectifies this by only handling the alias-set zero case as required by the original PR. Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk and branch. Richard. 2016-10-28 Richard Biener <rguent...@suse.de> PR middle-end/78128 PR middle-end/71002 * fold-const.c (make_bit_field_ref): Only adjust alias set when the original alias set was zero. Index: gcc/fold-const.c =================================================================== --- gcc/fold-const.c (revision 241642) +++ gcc/fold-const.c (working copy) @@ -3787,11 +3787,11 @@ make_bit_field_ref (location_t loc, tree { tree result, bftype; - if (get_alias_set (inner) != get_alias_set (orig_inner)) + alias_set_type iset = get_alias_set (orig_inner); + if (iset == 0 && get_alias_set (inner) != iset) inner = fold_build2 (MEM_REF, TREE_TYPE (inner), build_fold_addr_expr (inner), - build_int_cst - (reference_alias_ptr_type (orig_inner), 0)); + build_int_cst (ptr_type_node, 0)); if (bitpos == 0 && !reversep) {