(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.target/
sh/
torture/
pr58314.c
       1  /* { dg-additional-options "-std=gnu99" }  */
       2  /* { dg-do compile }  */
       3  
       4  typedef unsigned short __u16;
       5  typedef unsigned int __u32;
       6  typedef signed short s16;
       7  
       8  
       9  static inline 
      10  __attribute__((always_inline))
      11  __attribute__((__const__))
      12  __u16 __arch_swab16(__u16 x)
      13  {
      14   __asm__(
      15    "swap.b		%1, %0"
      16    : "=r" (x)
      17    : "r" (x));
      18   return x;
      19  }
      20  
      21  void u16_add_cpu(__u16 *var)
      22  {
      23    *var = __arch_swab16(*var);
      24  }
      25  
      26  typedef struct xfs_mount {
      27   int m_attr_magicpct;
      28  } xfs_mount_t;
      29  
      30  typedef struct xfs_da_args {
      31   struct xfs_mount *t_mountp;
      32   int index;
      33  } xfs_da_args_t;
      34  
      35  typedef struct xfs_dabuf {
      36   void *data;
      37  } xfs_dabuf_t;
      38  
      39  typedef struct xfs_attr_leaf_map {
      40   __u16 base;
      41   __u16 size;
      42  } xfs_attr_leaf_map_t;
      43  typedef struct xfs_attr_leaf_hdr {
      44   __u16 count;
      45   xfs_attr_leaf_map_t freemap[3];
      46  } xfs_attr_leaf_hdr_t;
      47  
      48  typedef struct xfs_attr_leaf_entry {
      49    __u16 nameidx;
      50  } xfs_attr_leaf_entry_t;
      51  
      52  typedef struct xfs_attr_leafblock {
      53   xfs_attr_leaf_hdr_t hdr;
      54   xfs_attr_leaf_entry_t entries[1];
      55  } xfs_attr_leafblock_t;
      56  
      57  int xfs_attr_leaf_entsize (xfs_attr_leafblock_t*, int);
      58  
      59  int
      60  xfs_attr_leaf_remove(xfs_attr_leafblock_t *leaf, xfs_da_args_t *args)
      61  {
      62   xfs_attr_leaf_hdr_t *hdr;
      63   xfs_attr_leaf_map_t *map;
      64   xfs_attr_leaf_entry_t *entry;
      65   int before, after, smallest, entsize;
      66   int tablesize, tmp, i;
      67   xfs_mount_t *mp;
      68   hdr = &leaf->hdr;
      69   mp = args->t_mountp;
      70  
      71   entry = &leaf->entries[args->index];
      72  
      73   tablesize = __arch_swab16(hdr->count);
      74  
      75   map = &hdr->freemap[0];
      76   tmp = map->size;
      77   before = after = -1;
      78   smallest = 3 - 1;
      79   entsize = xfs_attr_leaf_entsize(leaf, args->index);
      80  
      81   for (i = 0; i < 2; map++, i++) {
      82  
      83    if (map->base == tablesize)
      84      u16_add_cpu(&map->base);
      85  
      86    if (__arch_swab16(map->base)  + __arch_swab16(map->size)  == __arch_swab16(entry->nameidx))
      87     before = i;
      88    else if (map->base == entsize)
      89     after = i;
      90    else if (__arch_swab16(map->size) < tmp)
      91     smallest = i;
      92   }
      93  
      94   if (before >= 0)
      95    {
      96     map = &hdr->freemap[after];
      97     map->base = entry->nameidx;
      98  
      99    }
     100  
     101    map = &hdr->freemap[smallest];
     102  
     103    map->base = __arch_swab16(entry->nameidx);
     104  
     105   return(tmp < mp->m_attr_magicpct);
     106  }