diff --git a/gcc/ipa-struct-reorg/ipa-struct-reorg.cc b/gcc/ipa-struct-reorg/ipa-struct-reorg.cc index 851bda65cd5f7b28f3bfdb2ec04b151cacf96852..e8a84abbdf24ca4ace6c21256e5742ca34e83a91 100644 --- a/gcc/ipa-struct-reorg/ipa-struct-reorg.cc +++ b/gcc/ipa-struct-reorg/ipa-struct-reorg.cc @@ -5014,35 +5014,21 @@ ipa_struct_reorg::wholeaccess (tree expr, tree base, if (TREE_CODE (expr) == ADDR_EXPR && TREE_OPERAND (expr, 0) == base) return true; - if (!accesstype) + if (!accesstype || !handled_type (TREE_TYPE (expr)) || !t || !t->type) return false; - if (!types_compatible_p (TREE_TYPE (expr), TREE_TYPE (accesstype))) - return false; - - if (!handled_type (TREE_TYPE (expr))) - return false; - - if (!t || !t->type) - return false; - - tree type = TYPE_MAIN_VARIANT (t->type); + /* T *_1; _2 = MEM[(T *)_1]. */ if (TREE_CODE (expr) == MEM_REF - && POINTER_TYPE_P (TREE_TYPE (expr)) - && POINTER_TYPE_P (accesstype) - && POINTER_TYPE_P (TREE_TYPE (accesstype)) + && integer_zerop (TREE_OPERAND (expr, 1)) && POINTER_TYPE_P (TREE_TYPE (base)) - && TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (base))) == type - && TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (expr))) == type - && TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (accesstype))) == type) - return false; - - srtype *other_type = find_type (inner_type (TREE_TYPE (expr))); + && types_compatible_p (TREE_TYPE (TREE_TYPE (base)), t->type)) + return POINTER_TYPE_P (accesstype) + && types_compatible_p (TREE_TYPE (accesstype), t->type); - if (t == other_type) - return true; + if (!types_compatible_p (TREE_TYPE (expr), TREE_TYPE (accesstype))) + return false; - return false; + return t == find_type (inner_type (TREE_TYPE (expr))); } bool diff --git a/gcc/testsuite/gcc.dg/struct/dfc_wholeaccess.c b/gcc/testsuite/gcc.dg/struct/dfc_wholeaccess.c new file mode 100644 index 0000000000000000000000000000000000000000..60d73f0f0ed79e3c8d436085e7a975c5b16ce257 --- /dev/null +++ b/gcc/testsuite/gcc.dg/struct/dfc_wholeaccess.c @@ -0,0 +1,18 @@ +/* { dg-do compile } */ + +struct Type_A; + +// Optimized type. +struct Type_B { + int b; +}; + +__attribute__((used)) static void test() { + struct Type_A* a; + struct Type_B* b; + + // MEM[(Type_B*)a] = *b; + *((struct Type_B*)a) = *b; +} + +// This testsuite should be compiled successfully without ICE.