https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99525

            Bug ID: 99525
           Summary: wrong location of implicitly generated assignment to
                    polymorphic class
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

The first warning points to the assignment expression in the calling function. 
But the second warning instead points to the class head instead, making it
difficult to see what caused it.  It too should point to the assignment
expression in the calling function.

The wrong location is first seen in the einline dump.

$ cat x.C && gcc -O2 -S -Wall -fdump-tree-einline-lineno=/dev/stdout x.C
struct X
{
  int i;
};

char a[sizeof (X) - 1];

void f (X x)
{
  X *p = (X*)a;
  *p = x;
}

struct Y
{
  int i;
  virtual ~Y ();
};

void f (Y y)
{
  Y *p = (Y*)a;
  *p = y;
}

;; Function f (_Z1f1X, funcdef_no=0, decl_uid=2351, cgraph_uid=1,
symbol_order=1)

Iterations: 0
void f (struct X x)
{
  struct X * p;

  <bb 2> :
  [x.C:10:6] p_1 = [x.C:10:14] &a;
  [x.C:11:6] [x.C:11:6] *p_1 = x;
  [x.C:12:1] return;

}



;; Function Y::operator= (_ZN1YaSERKS_, funcdef_no=2, decl_uid=2391,
cgraph_uid=2, symbol_order=2)

Iterations: 0
struct Y & Y::operator= (struct Y * const this, const struct Y & D.2392)
{
  int _1;
  struct Y & _6;

  <bb 2> :
  [x.C:14:8] _1 = _3(D)->i;
  [x.C:14:8] this_4(D)->i = _1;
  [x.C:14:8] _6 = this_4(D);
  [x.C:14:8] return _6;

}



;; Function f (_Z1f1Y, funcdef_no=1, decl_uid=2388, cgraph_uid=3,
symbol_order=3)

Iterations: 1

Symbols to be put in SSA form
{ D.2402 }
Incremental SSA update started at block: 0
Number of blocks in CFG: 5
Number of blocks to update: 4 ( 80%)


Merging blocks 2 and 4
Merging blocks 2 and 3
void f (struct Y & y)
{
  struct Y * p;
  int _5;

  <bb 2> :
  [x.C:22:6] p_1 = [x.C:22:14] &a;
  [x.C:14:8] _5 = MEM[(const struct Y &)y_3(D)].i;
  [x.C:14:8] p_1->i = _5;
  [x.C:24:1] return;

}


x.C: In function ‘void f(X)’:
x.C:11:6: warning: array subscript ‘X[0]’ is partly outside array bounds of
‘char [3]’ [-Warray-bounds]
   11 |   *p = x;
      |   ~~~^~~
x.C:6:6: note: while referencing ‘a’ of size 0
    6 | char a[sizeof (X) - 1];
      |      ^
x.C: In function ‘void f(Y)’:
x.C:14:8: warning: array subscript ‘Y[0]’ is partly outside array bounds of
‘char [3]’ [-Warray-bounds]
   14 | struct Y
      |        ^
x.C:6:6: note: while referencing ‘a’ of size 0
    6 | char a[sizeof (X) - 1];
      |      ^

Reply via email to