diff options
author | Qing Zhao <qing.zhao@oracle.com> | 2022-10-07 14:59:01 +0000 |
---|---|---|
committer | Qing Zhao <qing.zhao@oracle.com> | 2022-10-07 17:44:14 +0000 |
commit | b9ad850e86b863c24f6f4f5acf08d49944cc7bbe (patch) | |
tree | 75c67c9441b7ee72843604f81d79a1c97b9d254d /gcc/testsuite/gcc.dg/strict-flex-array-3.c | |
parent | 1879e48f3d8595bc9e7f583bbd12df3c6f5c42dc (diff) | |
download | gcc-b9ad850e86b863c24f6f4f5acf08d49944cc7bbe.zip gcc-b9ad850e86b863c24f6f4f5acf08d49944cc7bbe.tar.gz gcc-b9ad850e86b863c24f6f4f5acf08d49944cc7bbe.tar.bz2 |
Use array_at_struct_end_p in __builtin_object_size [PR101836]
Use array_at_struct_end_p to determine whether the trailing array
of a structure is flexible array member in __builtin_object_size.
gcc/ChangeLog:
PR tree-optimization/101836
* tree-object-size.cc (addr_object_size): Use array_at_struct_end_p
to determine a flexible array member reference.
gcc/testsuite/ChangeLog:
PR tree-optimization/101836
* gcc.dg/pr101836.c: New test.
* gcc.dg/pr101836_1.c: New test.
* gcc.dg/pr101836_2.c: New test.
* gcc.dg/pr101836_3.c: New test.
* gcc.dg/pr101836_4.c: New test.
* gcc.dg/pr101836_5.c: New test.
* gcc.dg/strict-flex-array-2.c: New test.
* gcc.dg/strict-flex-array-3.c: New test.
Diffstat (limited to 'gcc/testsuite/gcc.dg/strict-flex-array-3.c')
-rw-r--r-- | gcc/testsuite/gcc.dg/strict-flex-array-3.c | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/strict-flex-array-3.c b/gcc/testsuite/gcc.dg/strict-flex-array-3.c new file mode 100644 index 0000000..602f99d --- /dev/null +++ b/gcc/testsuite/gcc.dg/strict-flex-array-3.c @@ -0,0 +1,60 @@ +/* test the combination of attribute strict_flex_array and option + -fstrict-flex-arrays: when both attribute and option specified, + attribute will have higher priority. */ +/* { dg-do run } */ +/* { dg-options "-O2 -fstrict-flex-arrays=0" } */ + +#include <stdio.h> + +#define expect(p, _v) do { \ + size_t v = _v; \ + if (p == v) \ + printf("ok: %s == %zd\n", #p, p); \ + else \ + { \ + printf("WAT: %s == %zd (expected %zd)\n", #p, p, v); \ + __builtin_abort (); \ + } \ +} while (0); + +struct trailing_array_1 { + int a; + int b; + int c[4] __attribute__ ((strict_flex_array (1))); +}; + +struct trailing_array_2 { + int a; + int b; + int c[1] __attribute__ ((strict_flex_array (2))); +}; + +struct trailing_array_3 { + int a; + int b; + int c[0] __attribute__ ((strict_flex_array (3))); +}; +struct trailing_array_4 { + int a; + int b; + int c[]; +}; + +void __attribute__((__noinline__)) stuff( + struct trailing_array_1 *normal, + struct trailing_array_2 *trailing_1, + struct trailing_array_3 *trailing_0, + struct trailing_array_4 *trailing_flex) +{ + expect(__builtin_object_size(normal->c, 1), 16); + expect(__builtin_object_size(trailing_1->c, 1), 4); + expect(__builtin_object_size(trailing_0->c, 1), 0); + expect(__builtin_object_size(trailing_flex->c, 1), -1); +} + +int main(int argc, char *argv[]) +{ + stuff((void *)argv[0], (void *)argv[0], (void *)argv[0], (void *)argv[0]); + + return 0; +} |