View | Details | Return to bug 58970 | Differences between
and this patch

Collapse All | Expand All

(-)gcc/expr.c (-3 / +4 lines)
Lines 4584-4590 get_bit_range (unsigned HOST_WIDE_INT *bitstart, Link Here
4584
      HOST_WIDE_INT adjust = bitoffset - *bitpos;
4584
      HOST_WIDE_INT adjust = bitoffset - *bitpos;
4585
4585
4586
      gcc_assert ((adjust % BITS_PER_UNIT) == 0);
4586
      gcc_assert ((adjust % BITS_PER_UNIT) == 0);
4587
      gcc_assert (*offset != NULL_TREE);
4587
      if (*offset == NULL_TREE)
4588
	*offset = size_zero_node;
4588
4589
4589
      *bitpos += adjust;
4590
      *bitpos += adjust;
4590
      *offset
4591
      *offset
Lines 6710-6716 get_inner_reference (tree exp, HOST_WIDE_INT *pbit Link Here
6710
      tem = tem.sext (TYPE_PRECISION (sizetype));
6711
      tem = tem.sext (TYPE_PRECISION (sizetype));
6711
      tem = tem.lshift (BITS_PER_UNIT == 8 ? 3 : exact_log2 (BITS_PER_UNIT));
6712
      tem = tem.lshift (BITS_PER_UNIT == 8 ? 3 : exact_log2 (BITS_PER_UNIT));
6712
      tem += bit_offset;
6713
      tem += bit_offset;
6713
      if (tem.fits_shwi ())
6714
      if (tem.fits_shwi () && !tem.is_negative ())
6714
	{
6715
	{
6715
	  *pbitpos = tem.to_shwi ();
6716
	  *pbitpos = tem.to_shwi ();
6716
	  *poffset = offset = NULL_TREE;
6717
	  *poffset = offset = NULL_TREE;
Lines 6721-6727 get_inner_reference (tree exp, HOST_WIDE_INT *pbit Link Here
6721
  if (offset)
6722
  if (offset)
6722
    {
6723
    {
6723
      /* Avoid returning a negative bitpos as this may wreak havoc later.  */
6724
      /* Avoid returning a negative bitpos as this may wreak havoc later.  */
6724
      if (bit_offset.is_negative ())
6725
      if (bit_offset.is_negative () || !bit_offset.fits_shwi())
6725
        {
6726
        {
6726
	  double_int mask
6727
	  double_int mask
6727
	    = double_int::mask (BITS_PER_UNIT == 8
6728
	    = double_int::mask (BITS_PER_UNIT == 8
(-)gcc/testsuite/gcc.dg/pr58970.c (+35 lines)
Line 0 Link Here
1
/* PR middle-end/58970 */
2
/* { dg-do compile } */
3
/* { dg-options "-O2" } */
4
5
struct S
6
{
7
  struct
8
  {
9
    unsigned int b:1;
10
  } t[1];
11
};
12
13
void
14
foo (int x, struct S *p)
15
{
16
  if (x == -1)
17
    p->t[x].b = 0;
18
}
19
20
struct T
21
{
22
  char x;
23
  struct
24
  {
25
    unsigned char a : 8;
26
    unsigned char b : 1;
27
  } t[1];
28
};
29
 
30
void
31
bar (int x, struct T *p)
32
{
33
  if (x == -1)
34
    p->t[x].b = 0;
35
}

Return to bug 58970