1 /* This file was miscompiled by an earlier version of the object size
2 checking patch. Object size in one of the memcpy calls was
3 incorrectly determined to be 0 while it should be (size_t) -1
5 /* { dg-do compile } */
6 /* { dg-options "-O2 -ftrack-macro-expansion=0" } */
8 #include "../gcc.c-torture/execute/builtins/chk.h"
11 extern void *malloc (__SIZE_TYPE__
);
18 /* Here all object sizes are not known at compile time. There
19 should be no warning, nor any checker functions called. */
22 foo (const struct A
*x
, int y
, const unsigned char *z
)
27 b
= (x
->i
& 0xff) == 1 ? 3 : 4;
29 c
= bar (x
->j
* x
->k
);
31 const unsigned char *d
= z
;
33 unsigned char *f
= c
+ x
->j
* x
->k
;
38 unsigned int h
= *d
++;
75 /* The same routine, slightly modified:
76 1) c has known size at compile time
77 2) e += h was changed into e += 16.
78 GCC could actually through VRP determine that
79 in e += h is (h >= 0 && h <= 127), thus know
80 it is pointer addition and not subtraction and
81 know e's __builtin_object_size (e, 0) is at 512,
82 but we are not there yet. */
85 baz (const struct A
*x
, const unsigned char *z
)
90 b
= (x
->i
& 0xff) == 1 ? 3 : 4;
93 const unsigned char *d
= z
;
95 unsigned char *f
= c
+ x
->j
* x
->k
;
100 unsigned int h
= *d
++;
118 memcpy (e
, d
, 513); /* { dg-warning "writing" "memcpy" } */