https://gcc.gnu.org/g:6ccdbf6eea18109b5c5deb515d0d82c0078d807a

commit 6ccdbf6eea18109b5c5deb515d0d82c0078d807a
Author: Mikael Morin <mik...@gcc.gnu.org>
Date:   Thu Mar 6 11:10:40 2025 +0100

    gimple-exec Restauration tests print_first_data_ref_part

Diff:
---
 gcc/cgraphunit.cc | 353 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 349 insertions(+), 4 deletions(-)

diff --git a/gcc/cgraphunit.cc b/gcc/cgraphunit.cc
index 71eaf0509fdf..51fa9143f7ca 100644
--- a/gcc/cgraphunit.cc
+++ b/gcc/cgraphunit.cc
@@ -2582,7 +2582,7 @@ public:
   void print_function_exit (struct function * func);
   void print_bb_jump (edge e);
   void print_bb_entry (basic_block bb);
-  tree print_first_data_ref_part (exec_context & context, tree data_ref, const 
data_value & value, unsigned offset, int * ignored_bits);
+  tree print_first_data_ref_part (exec_context & context, tree data_ref, 
unsigned offset, int * ignored_bits);
   void print_value_update (exec_context & context, tree, const data_value &); 
   void end_stmt (gimple *);
   void print_at (const data_value & value, tree type, unsigned offset, 
unsigned width);
@@ -2979,7 +2979,7 @@ find_mem_ref_replacement (exec_context & context, tree 
data_ref,
 
 
 tree
-context_printer::print_first_data_ref_part (exec_context & context, tree 
data_ref, const data_value & value, unsigned offset, int * ignored_bits)
+context_printer::print_first_data_ref_part (exec_context & context, tree 
data_ref, unsigned offset, int * ignored_bits)
 {
   switch (TREE_CODE (data_ref))
     {
@@ -2988,7 +2988,7 @@ context_printer::print_first_data_ref_part (exec_context 
& context, tree data_re
        tree mem_replacement = find_mem_ref_replacement (context, data_ref,
                                                         offset);
        if (mem_replacement != NULL_TREE)
-         return print_first_data_ref_part (context, mem_replacement, value, 0, 
ignored_bits);
+         return print_first_data_ref_part (context, mem_replacement, 0, 
ignored_bits);
       }
 
     /* Fall through.  */
@@ -3018,7 +3018,7 @@ context_printer::print_value_update (exec_context & 
context, tree lhs, const dat
   while (previously_done < width)
     {
       int ignored_bits = 0;
-      tree type_done = print_first_data_ref_part (context, lhs, value,
+      tree type_done = print_first_data_ref_part (context, lhs,
                                                  previously_done,
                                                  &ignored_bits);
       if (type_done == NULL_TREE)
@@ -5466,6 +5466,350 @@ data_storage_set_at_tests ()
 }
 
 
+void
+context_printer_print_first_data_ref_part_tests ()
+{
+  vec<tree> empty{};
+
+  tree der2i = make_node (RECORD_TYPE);
+  tree der2i_i2 = build_decl (input_location, FIELD_DECL,
+                             get_identifier ("der2i_i2"), integer_type_node);
+  DECL_CONTEXT (der2i_i2) = der2i;
+  DECL_CHAIN (der2i_i2) = NULL_TREE;
+  tree der2i_i1 = build_decl (input_location, FIELD_DECL,
+                             get_identifier ("der2i_i1"), integer_type_node);
+  DECL_CONTEXT (der2i_i1) = der2i;
+  DECL_CHAIN (der2i_i1) = der2i_i2;
+  TYPE_FIELDS (der2i) = der2i_i1;
+  layout_type (der2i);
+
+  tree var2i = create_var (der2i, "var2i");
+
+  heap_memory mem1;
+  context_printer printer1;
+  pretty_printer & pp1 = printer1.pp;
+  exec_context ctx1 = context_builder ().build (mem1, printer1);
+
+  tree res1 = printer1.print_first_data_ref_part (ctx1, var2i, 0, nullptr);
+
+  ASSERT_EQ (res1, integer_type_node);
+  const char * str1 = pp_formatted_text (&pp1);
+  ASSERT_STREQ (str1, "# var2i.der2i_i1");
+
+
+  context_printer printer2;
+  pretty_printer & pp2 = printer2.pp;
+
+  vec<tree> decls2{};
+  decls2.safe_push (var2i);
+
+  context_builder builder2 {};
+  builder2.add_decls (&decls2);
+  exec_context ctx2 = builder2.build (mem1, printer2);
+
+  tree mem_var2i = build2 (MEM_REF, der2i,
+                          build1 (ADDR_EXPR, ptr_type_node, var2i),
+                          build_zero_cst (ptr_type_node));
+
+  tree res2 = printer2.print_first_data_ref_part (ctx2, mem_var2i, 0, nullptr);
+
+  ASSERT_EQ (res2, integer_type_node);
+  const char * str2 = pp_formatted_text (&pp2);
+  ASSERT_STREQ (str2, "# var2i.der2i_i1");
+
+
+  context_printer printer3;
+  pretty_printer & pp3 = printer3.pp;
+
+  context_builder builder3 {};
+  builder3.add_decls (&decls2);
+  exec_context ctx3 = builder3.build (mem1, printer3);
+
+  tree long_var2i = build2 (MEM_REF, long_integer_type_node,
+                          build1 (ADDR_EXPR, ptr_type_node, var2i),
+                          build_zero_cst (ptr_type_node));
+
+  tree res3 = printer3.print_first_data_ref_part (ctx3, long_var2i, 0, 
nullptr);
+
+  ASSERT_EQ (res3, integer_type_node);
+  const char * str3 = pp_formatted_text (&pp3);
+  ASSERT_STREQ (str3, "# var2i.der2i_i1");
+
+
+  tree der2s = make_node (RECORD_TYPE);
+  tree der2s_s2 = build_decl (input_location, FIELD_DECL,
+                             get_identifier ("der2s_s2"),
+                             short_integer_type_node);
+  DECL_CONTEXT (der2s_s2) = der2s;
+  DECL_CHAIN (der2s_s2) = NULL_TREE;
+  tree der2s_s1 = build_decl (input_location, FIELD_DECL,
+                             get_identifier ("der2s_s1"),
+                             short_integer_type_node);
+  DECL_CONTEXT (der2s_s1) = der2s;
+  DECL_CHAIN (der2s_s1) = der2s_s2;
+  TYPE_FIELDS (der2s) = der2s_s1;
+  layout_type (der2s);
+
+
+  tree der1d1i = make_node (RECORD_TYPE);
+  tree der1d1i_i2 = build_decl (input_location, FIELD_DECL,
+                               get_identifier ("der1d1i_i2"), 
integer_type_node);
+  DECL_CONTEXT (der1d1i_i2) = der1d1i;
+  DECL_CHAIN (der1d1i_i2) = NULL_TREE;
+  tree der1d1i_d1 = build_decl (input_location, FIELD_DECL,
+                               get_identifier ("der1d1i_d1"), der2s);
+  DECL_CONTEXT (der1d1i_d1) = der1d1i;
+  DECL_CHAIN (der1d1i_d1) = der1d1i_i2;
+  TYPE_FIELDS (der1d1i) = der1d1i_d1;
+  layout_type (der1d1i);
+
+  tree var1d1i = create_var (der1d1i, "var1d1i");
+
+  context_printer printer4;
+  pretty_printer & pp4 = printer4.pp;
+
+  vec<tree> decls4{};
+  decls4.safe_push (var1d1i);
+
+  context_builder builder4 {};
+  builder4.add_decls (&decls4);
+  exec_context ctx4 = builder4.build (mem1, printer4);
+
+  tree mem_var1d1i = build2 (MEM_REF, long_integer_type_node,
+                            build1 (ADDR_EXPR, ptr_type_node, var1d1i),
+                            build_zero_cst (ptr_type_node));
+
+  tree res4 = printer4.print_first_data_ref_part (ctx4, mem_var1d1i, 0, 
nullptr);
+
+  ASSERT_EQ (res4, short_integer_type_node);
+  const char * str4 = pp_formatted_text (&pp4);
+  ASSERT_STREQ (str4, "# var1d1i.der1d1i_d1.der2s_s1");
+
+
+  context_printer printer5;
+  pretty_printer & pp5 = printer5.pp;
+
+  context_builder builder5 {};
+  builder5.add_decls (&decls4);
+  exec_context ctx5 = builder5.build (mem1, printer5);
+
+  tree mem_var1d1i_s2 = build2 (MEM_REF, short_integer_type_node,
+                               build1 (ADDR_EXPR, ptr_type_node, var1d1i),
+                               build_int_cst (ptr_type_node,
+                                              sizeof (short)));
+
+  tree res5 = printer5.print_first_data_ref_part (ctx5, mem_var1d1i_s2, 0, 
nullptr);
+
+  ASSERT_EQ (res5, short_integer_type_node);
+  const char * str5 = pp_formatted_text (&pp5);
+  ASSERT_STREQ (str5, "# var1d1i.der1d1i_d1.der2s_s2");
+
+
+  tree der4c = make_node (RECORD_TYPE);
+  tree der4c_c4 = build_decl (input_location, FIELD_DECL,
+                             get_identifier ("der4c_c4"),
+                             char_type_node);
+  DECL_CONTEXT (der4c_c4) = der4c;
+  DECL_CHAIN (der4c_c4) = NULL_TREE;
+  tree der4c_c3 = build_decl (input_location, FIELD_DECL,
+                             get_identifier ("der4c_c3"),
+                             char_type_node);
+  DECL_CONTEXT (der4c_c3) = der4c;
+  DECL_CHAIN (der4c_c3) = der4c_c4;
+  tree der4c_c2 = build_decl (input_location, FIELD_DECL,
+                             get_identifier ("der4c_c2"),
+                             char_type_node);
+  DECL_CONTEXT (der4c_c2) = der4c;
+  DECL_CHAIN (der4c_c2) = der4c_c3;
+  tree der4c_c1 = build_decl (input_location, FIELD_DECL,
+                             get_identifier ("der4c_c1"),
+                             char_type_node);
+  DECL_CONTEXT (der4c_c1) = der4c;
+  DECL_CHAIN (der4c_c1) = der4c_c2;
+  TYPE_FIELDS (der4c) = der4c_c1;
+  layout_type (der4c);
+
+  tree var4c = create_var (der4c, "var4c");
+
+  context_printer printer6;
+  pretty_printer & pp6 = printer6.pp;
+
+  vec<tree> decls6{};
+  decls6.safe_push (var4c);
+
+  context_builder builder6 {};
+  builder6.add_decls (&decls6);
+  exec_context ctx6 = builder6.build (mem1, printer6);
+
+  tree mem_var4c = build2 (MEM_REF, long_integer_type_node,
+                          build1 (ADDR_EXPR, ptr_type_node, var4c),
+                          build_int_cst (ptr_type_node, 2));
+
+  tree res6 = printer6.print_first_data_ref_part (ctx6, mem_var4c, 0, nullptr);
+
+  ASSERT_EQ (res6, char_type_node);
+  const char * str6 = pp_formatted_text (&pp6);
+  ASSERT_STREQ (str6, "# var4c.der4c_c3");
+
+
+  tree der1i1d = make_node (RECORD_TYPE);
+  tree der1i1d_d2 = build_decl (input_location, FIELD_DECL,
+                               get_identifier ("der1i1d_d2"),
+                               der4c);
+  DECL_CONTEXT (der1i1d_d2) = der1i1d;
+  DECL_CHAIN (der1i1d_d2) = NULL_TREE;
+  tree der1i1d_i1 = build_decl (input_location, FIELD_DECL,
+                               get_identifier ("der1i1d_i1"),
+                               integer_type_node);
+  DECL_CONTEXT (der1i1d_i1) = der1i1d;
+  DECL_CHAIN (der1i1d_i1) = der1i1d_d2;
+  TYPE_FIELDS (der1i1d) = der1i1d_i1;
+  layout_type (der1i1d);
+
+  tree var1i1d = create_var (der1i1d, "var1i1d");
+
+  context_printer printer7;
+  pretty_printer & pp7 = printer7.pp;
+
+  vec<tree> decls7{};
+  decls7.safe_push (var1i1d);
+
+  context_builder builder7 {};
+  builder7.add_decls (&decls7);
+  exec_context ctx7 = builder7.build (mem1, printer7);
+
+  tree mem_var1i1d = build2 (MEM_REF, char_type_node,
+                            build1 (ADDR_EXPR, ptr_type_node, var1i1d),
+                            build_int_cst (ptr_type_node,
+                                           sizeof (int) + 1));
+
+  tree res7 = printer7.print_first_data_ref_part (ctx7, mem_var1i1d, 0, 
nullptr);
+
+  ASSERT_EQ (res7, char_type_node);
+  const char * str7 = pp_formatted_text (&pp7);
+  ASSERT_STREQ (str7, "# var1i1d.der1i1d_d2.der4c_c2");
+
+
+  tree i5 = build_array_type_nelts (integer_type_node, 5);
+
+  tree var_i5 = create_var (i5, "var_i5");
+
+  context_printer printer8;
+  pretty_printer & pp8 = printer8.pp;
+
+  vec<tree> decls8{};
+  decls8.safe_push (var_i5);
+
+  context_builder builder8 {};
+  builder8.add_decls (&decls8);
+  exec_context ctx8 = builder8.build (mem1, printer8);
+
+  tree mem_var_i5 = build2 (MEM_REF, char_type_node,
+                           build1 (ADDR_EXPR, ptr_type_node, var_i5),
+                           build_int_cst (ptr_type_node,
+                                          3 * sizeof (int)));
+
+  tree res8 = printer8.print_first_data_ref_part (ctx8, mem_var_i5, 0, 
nullptr);
+
+  ASSERT_EQ (res8, integer_type_node);
+  const char * str8 = pp_formatted_text (&pp8);
+  ASSERT_STREQ (str8, "# var_i5[3]");
+
+
+  context_printer printer9;
+  pretty_printer & pp9 = printer9.pp;
+
+  context_builder builder9 {};
+  builder9.add_decls (&decls8);
+  exec_context ctx9 = builder9.build (mem1, printer9);
+
+  tree mem2_var_i5 = build2 (MEM_REF, char_type_node,
+                            build1 (ADDR_EXPR, ptr_type_node, var_i5),
+                            build_int_cst (ptr_type_node,
+                                           sizeof (int)));
+
+  tree res9 = printer9.print_first_data_ref_part (ctx9, mem2_var_i5,
+                                                 HOST_BITS_PER_INT, nullptr);
+
+  ASSERT_EQ (res9, integer_type_node);
+  const char * str9 = pp_formatted_text (&pp9);
+  ASSERT_STREQ (str9, "# var_i5[2]");
+
+
+  tree a5c4 = build_array_type_nelts (der4c, 5);
+
+  tree der1i1a5d = make_node (RECORD_TYPE);
+  tree der1i1a5d_a5d2 = build_decl (input_location, FIELD_DECL,
+                                   get_identifier ("der1i1a5d_a5d2"),
+                                   a5c4);
+  DECL_CONTEXT (der1i1a5d_a5d2) = der1i1a5d;
+  DECL_CHAIN (der1i1a5d_a5d2) = NULL_TREE;
+  tree der1i1a5d_i1 = build_decl (input_location, FIELD_DECL,
+                                 get_identifier ("der1i1a5d_i1"),
+                                 integer_type_node);
+  DECL_CONTEXT (der1i1a5d_i1) = der1i1a5d;
+  DECL_CHAIN (der1i1a5d_i1) = der1i1a5d_a5d2;
+  TYPE_FIELDS (der1i1a5d) = der1i1a5d_i1;
+  layout_type (der1i1a5d);
+
+  tree var_d1i1a5d = create_var (der1i1a5d, "var_d1i1a5d");
+
+  context_printer printer10;
+  pretty_printer & pp10 = printer10.pp;
+
+  vec<tree> decls10{};
+  decls10.safe_push (var_d1i1a5d);
+
+  context_builder builder10 {};
+  builder10.add_decls (&decls10);
+  exec_context ctx10 = builder10.build (mem1, printer10);
+
+  tree mem_var_d1i1a5d = build2 (MEM_REF, char_type_node,
+                                build1 (ADDR_EXPR, ptr_type_node, var_d1i1a5d),
+                                build_int_cst (ptr_type_node,
+                                               sizeof (int) + 13));
+
+  tree res10 = printer10.print_first_data_ref_part (ctx10, mem_var_d1i1a5d, 0, 
nullptr);
+
+  ASSERT_EQ (res10, char_type_node);
+  const char * str10 = pp_formatted_text (&pp10);
+  ASSERT_STREQ (str10, "# var_d1i1a5d.der1i1a5d_a5d2[3].der4c_c2");
+
+
+  tree var_i = create_var (integer_type_node, "var_i");
+  tree ptr = create_var (ptr_type_node, "ptr");
+
+  context_printer printer11;
+  pretty_printer & pp11 = printer11.pp;
+
+  vec<tree> decls11{};
+  decls11.safe_push (var_i);
+  decls11.safe_push (ptr);
+
+  context_builder builder11 {};
+  builder11.add_decls (&decls11);
+  exec_context ctx11 = builder11.build (mem1, printer11);
+
+  data_storage *var_storage = ctx11.find_reachable_var (var_i);
+  storage_address var_address (var_storage->get_ref (), 0);
+
+  data_value ptr_val (ptr_type_node);
+  ptr_val.set_address (var_address);
+
+  data_storage *ptr_storage = ctx11.find_reachable_var (ptr);
+  ptr_storage->set (ptr_val);
+
+  tree ref_ptr = build2 (MEM_REF, integer_type_node, ptr,
+                        build_zero_cst (ptr_type_node));
+
+  tree res11 = printer11.print_first_data_ref_part (ctx11, ref_ptr, 0, 
nullptr);
+
+  ASSERT_EQ (res11, integer_type_node);
+  const char * str11 = pp_formatted_text (&pp11);
+  ASSERT_STREQ (str11, "# var_i");
+}
+
+
 void
 context_printer_print_value_update_tests ()
 {
@@ -7269,6 +7613,7 @@ gimple_exec_cc_tests ()
   data_value_set_at_tests ();
   data_value_print_tests ();
   data_storage_set_at_tests ();
+  context_printer_print_first_data_ref_part_tests ();
   context_printer_print_value_update_tests ();
   exec_context_evaluate_tests ();
   exec_context_evaluate_literal_tests ();

Reply via email to