This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PR19351, C++] Fix heap overflow in operator new[]


* Richard Guenther:

> I haven't yet looked at the code this check generates for the
> middle-end, but does it consider targets like m32c where addresses
> are 24bit but for example sizetype (and size_t?) is 16bit because
> m32c cannot do arithmetic in the larger mode?  I wonder if the code
> the FE presents us with is 1) correct, 2) results in absymal code on
> such targets.

I haven't got a full m32c tool-chain, so I could only compile a
minimal example:

struct foo {
  char bar[159];
};

void *
test (unsigned long s)
{
  return new foo[s];
}

This turns into:

__Z4testm:
.LFB0:
        enter   #0
.LCFI0:
        mov.w   5[fb],r0
        cmp.w   #412,r0
        jgtu    .L3
        mov.w   r0,r1
        sha.w   #5,r1
        mov.w   r0,r2
        sha.w   #7,r2
        add.w   r2,r1
        sub.w   r0,r1
        jsr.a   __Znaj
        exitd
.L3:
        mov.w   #-1,r1
        jsr.a   __Znaj
        exitd

412 is the correct magic constant for 16 bits.  (I'm using
size_type_node now, so the generated value should really correspond to
the size_t type.)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]