@@ -451,14 +451,13 @@ void c_typecheck_baset::typecheck_expr_main(exprt &expr)
451451    exprt default_match=nil_exprt ();
452452    exprt assoc_match=nil_exprt ();
453453
454-     const  typet &op_type = follow ( op.type () );
454+     const  typet &op_type = op.type ();
455455
456456    for (const  auto  &irep : generic_associations)
457457    {
458458      if (irep.get (ID_type_arg) == ID_default)
459459        default_match = static_cast <const  exprt &>(irep.find (ID_value));
460-       else  if (
461-         op_type == follow (static_cast <const  typet &>(irep.find (ID_type_arg))))
460+       else  if (op_type == static_cast <const  typet &>(irep.find (ID_type_arg)))
462461      {
463462        assoc_match = static_cast <const  exprt &>(irep.find (ID_value));
464463      }
@@ -590,11 +589,9 @@ void c_typecheck_baset::typecheck_expr_builtin_offsetof(exprt &expr)
590589
591590  for (const  auto  &op : member.operands ())
592591  {
593-     type = follow (type);
594- 
595592    if (op.id () == ID_member)
596593    {
597-       if (type.id ()!=ID_union  && type.id ()!=ID_struct )
594+       if (type.id () != ID_union_tag  && type.id () != ID_struct_tag )
598595      {
599596        error ().source_location  = expr.source_location ();
600597        error () << " offsetof of member expects struct/union type, " 
@@ -607,20 +604,23 @@ void c_typecheck_baset::typecheck_expr_builtin_offsetof(exprt &expr)
607604
608605      while (!found)
609606      {
610-         PRECONDITION (type.id () == ID_union  || type.id () == ID_struct );
607+         PRECONDITION (type.id () == ID_union_tag  || type.id () == ID_struct_tag );
611608
612-         const  struct_union_typet &struct_union_type=
613-           to_struct_union_type (type);
609+         const  struct_union_typet &struct_union_type =
610+           type.id () == ID_struct_tag ? static_cast <const  struct_union_typet &>(
611+                                          follow_tag (to_struct_tag_type (type)))
612+                                      : static_cast <const  struct_union_typet &>(
613+                                          follow_tag (to_union_tag_type (type)));
614614
615615        //  direct member?
616616        if (struct_union_type.has_component (component_name))
617617        {
618618          found=true ;
619619
620-           if (type.id ()==ID_struct )
620+           if (type.id () == ID_struct_tag )
621621          {
622-             auto  o_opt =
623-               member_offset_expr ( to_struct_type (type), component_name, *this );
622+             auto  o_opt =  member_offset_expr ( 
623+               follow_tag ( to_struct_tag_type (type) ), component_name, *this );
624624
625625            if (!o_opt.has_value ())
626626            {
@@ -650,10 +650,10 @@ void c_typecheck_baset::typecheck_expr_builtin_offsetof(exprt &expr)
650650            {
651651              if (has_component_rec (c.type (), component_name, *this ))
652652              {
653-                 if (type.id ()==ID_struct )
653+                 if (type.id () == ID_struct_tag )
654654                {
655655                  auto  o_opt = member_offset_expr (
656-                     to_struct_type ( type), c.get_name (), *this );
656+                     follow_tag ( to_struct_tag_type ( type) ), c.get_name (), *this );
657657
658658                  if (!o_opt.has_value ())
659659                  {
@@ -669,9 +669,10 @@ void c_typecheck_baset::typecheck_expr_builtin_offsetof(exprt &expr)
669669                      o_opt.value (), size_type ()));
670670                }
671671
672-                 typet tmp = follow ( c.type () );
672+                 typet tmp = c.type ();
673673                type=tmp;
674-                 CHECK_RETURN (type.id () == ID_union || type.id () == ID_struct);
674+                 CHECK_RETURN (
675+                   type.id () == ID_union_tag || type.id () == ID_struct_tag);
675676                found2=true ;
676677                break ; //  we run into another iteration of the outer loop
677678              }
@@ -1375,7 +1376,7 @@ void c_typecheck_baset::typecheck_expr_rel(
13751376
13761377  if (expr.id ()==ID_equal || expr.id ()==ID_notequal)
13771378  {
1378-     if (follow ( o_type0)== follow ( o_type1) )
1379+     if (o_type0 ==  o_type1)
13791380    {
13801381      if (o_type0.id () != ID_array)
13811382      {
@@ -1528,10 +1529,7 @@ void c_typecheck_baset::typecheck_expr_member(exprt &expr)
15281529  exprt &op0 = to_unary_expr (expr).op ();
15291530  typet type=op0.type ();
15301531
1531-   type = follow (type);
1532- 
1533-   if (type.id ()!=ID_struct &&
1534-      type.id ()!=ID_union)
1532+   if (type.id () != ID_struct_tag && type.id () != ID_union_tag)
15351533  {
15361534    error ().source_location  = expr.source_location ();
15371535    error () << " member operator requires structure type " 
@@ -1540,8 +1538,11 @@ void c_typecheck_baset::typecheck_expr_member(exprt &expr)
15401538    throw  0 ;
15411539  }
15421540
1543-   const  struct_union_typet &struct_union_type=
1544-     to_struct_union_type (type);
1541+   const  struct_union_typet &struct_union_type =
1542+     type.id () == ID_struct_tag ? static_cast <const  struct_union_typet &>(
1543+                                    follow_tag (to_struct_tag_type (type)))
1544+                                : static_cast <const  struct_union_typet &>(
1545+                                    follow_tag (to_union_tag_type (type)));
15451546
15461547  if (struct_union_type.is_incomplete ())
15471548  {
@@ -1583,7 +1584,9 @@ void c_typecheck_baset::typecheck_expr_member(exprt &expr)
15831584  if (op0.get_bool (ID_C_lvalue))
15841585    expr.set (ID_C_lvalue, true );
15851586
1586-   if (op0.type ().get_bool (ID_C_constant) || type.get_bool (ID_C_constant))
1587+   if (
1588+     op0.type ().get_bool (ID_C_constant) ||
1589+     struct_union_type.get_bool (ID_C_constant))
15871590    expr.type ().set (ID_C_constant, true );
15881591
15891592  //  copy method identifier
@@ -3643,11 +3646,10 @@ exprt c_typecheck_baset::do_special_functions(
36433646
36443647    //  The value doesn't matter at all, we only care about the type.
36453648    //  Need to sync with typeclass.h.
3646-     typet type = follow (object.type ());
3647- 
36483649    //  use underlying type for bit fields
3649-     if (type.id () == ID_c_bit_field)
3650-       type = to_c_bit_field_type (type).underlying_type ();
3650+     const  typet &type = object.type ().id () == ID_c_bit_field
3651+                           ? to_c_bit_field_type (object.type ()).underlying_type ()
3652+                           : object.type ();
36513653
36523654    unsigned  type_number;
36533655
@@ -3659,23 +3661,17 @@ exprt c_typecheck_baset::do_special_functions(
36593661    }
36603662    else 
36613663    {
3662-       type_number =
3663-         type.id () == ID_empty
3664-           ? 0u 
3665-           : (type.id () == ID_bool || type.id () == ID_c_bool)
3666-               ? 4u 
3667-               : (type.id () == ID_pointer || type.id () == ID_array)
3668-                   ? 5u 
3669-                   : type.id () == ID_floatbv
3670-                       ? 8u 
3671-                       : (type.id () == ID_complex &&
3672-                          to_complex_type (type).subtype ().id () == ID_floatbv)
3673-                           ? 9u 
3674-                           : type.id () == ID_struct
3675-                               ? 12u 
3676-                               : type.id () == ID_union
3677-                                   ? 13u 
3678-                                   : 1u ; //  int, short, char, enum_tag
3664+       type_number = type.id () == ID_empty                                ? 0u 
3665+                     : (type.id () == ID_bool || type.id () == ID_c_bool)   ? 4u 
3666+                     : (type.id () == ID_pointer || type.id () == ID_array) ? 5u 
3667+                     : type.id () == ID_floatbv                            ? 8u 
3668+                     : (type.id () == ID_complex &&
3669+                        to_complex_type (type).subtype ().id () == ID_floatbv)
3670+                       ? 9u 
3671+                     : type.id () == ID_struct_tag ? 12u 
3672+                     : type.id () == ID_union_tag
3673+                       ? 13u 
3674+                       : 1u ; //  int, short, char, enum_tag
36793675    }
36803676
36813677    exprt tmp=from_integer (type_number, expr.type ());
0 commit comments