diff --git a/gcc/ipa-struct-reorg/ipa-struct-reorg.cc b/gcc/ipa-struct-reorg/ipa-struct-reorg.cc index e8a84abbdf24ca4ace6c21256e5742ca34e83a91..1140edd1d73fac20d369b0f645fd57950d100439 100644 --- a/gcc/ipa-struct-reorg/ipa-struct-reorg.cc +++ b/gcc/ipa-struct-reorg/ipa-struct-reorg.cc @@ -5365,8 +5365,8 @@ ipa_struct_reorg::record_stmt_expr (tree expr, cgraph_node *node, gimple *stmt) srfield *field; bool realpart, imagpart, address; bool escape_from_base = false; - if (!get_type_field (expr, base, indirect, type, field, - realpart, imagpart, address, escape_from_base)) + if (!get_type_field (expr, base, indirect, type, field, realpart, + imagpart, address, escape_from_base, false, true)) return; if (current_layout_opt_level > NONE) @@ -5375,7 +5375,6 @@ ipa_struct_reorg::record_stmt_expr (tree expr, cgraph_node *node, gimple *stmt) type->mark_escape (escape_non_optimize, stmt); } - /* Record it. */ type->add_access (new sraccess (expr, stmt, node, find_function (node), type, base, field)); @@ -6554,6 +6553,7 @@ ipa_struct_reorg::prune_escaped_types (void) /* If contains or is contained by the escape type, mark them as escaping. */ propagate_escape (); + propagate_escape_via_no_record_var (); } if (current_layout_opt_level >= STRUCT_REORDER_FIELDS) { diff --git a/gcc/testsuite/gcc.dg/struct/sr_early_void_ptr.c b/gcc/testsuite/gcc.dg/struct/sr_early_void_ptr.c new file mode 100644 index 0000000000000000000000000000000000000000..5ff166f08081a60189d74cf0e6155165172453d8 --- /dev/null +++ b/gcc/testsuite/gcc.dg/struct/sr_early_void_ptr.c @@ -0,0 +1,28 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-fgimple" } */ + +#include + +struct S { + int a; + int b; + int c; +}; + +__attribute__((noinline)) void __GIMPLE(ssa,startwith("struct_reorg")) test() { + void* _1; + + __BB(2): + _1 = calloc(1UL, 12UL); + __MEM ((int*)_1 + 4UL) = 0; + __MEM ((struct S*)_1).a = 0; + + return; +} + +int main() { + test(); + return 0; +} + +/* { dg-final { scan-ipa-dump "struct S(\[0-9\]*) has escaped" "struct_reorg" } } */ diff --git a/gcc/testsuite/gcc.dg/struct/sr_no_recorded_local_void_ptr.c b/gcc/testsuite/gcc.dg/struct/sr_no_recorded_local_void_ptr.c new file mode 100644 index 0000000000000000000000000000000000000000..d917b66f82fe2b1d6aff87872f5cac02889d977f --- /dev/null +++ b/gcc/testsuite/gcc.dg/struct/sr_no_recorded_local_void_ptr.c @@ -0,0 +1,23 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-fgimple" } */ + +#include + +struct S { + int a; + int b; +}; + +__attribute__((noinline)) void __GIMPLE(startwith("struct_reorg")) test() { + void* ptr; + + ptr = calloc(1UL, 8UL); + __MEM ((struct S*)ptr).a = 0; +} + +int main() { + test(); + return 0; +} + +/* { dg-final { scan-ipa-dump "struct S has escaped: \"Type escapes via no record var\"" "struct_reorg" } } */