libcpp, c, middle-end: Optimize initializers using #embed in C
[official-gcc.git] / gcc / testsuite / gcc.dg / builtin-dynamic-object-size-20.c
blob2c8e07dd98d605ef3f7f9afbdfb0f3d291d3ceb2
1 /* PR 109334
2 * { dg-do run }
3 * { dg-options "-O1" } */
6 [[gnu::noinline,gnu::noipa]]
7 int f(int n, int buf[n])
8 [[gnu::access(read_only, 2, 1)]]
10 return __builtin_dynamic_object_size(buf, 0);
13 [[gnu::noinline,gnu::noipa]]
14 int g(int n, int buf[])
15 [[gnu::access(read_only, 2, 1)]]
17 return __builtin_dynamic_object_size(buf, 0);
20 [[gnu::noinline,gnu::noipa]]
21 int h(int n, int buf[n])
23 return __builtin_dynamic_object_size(buf, 0);
26 int dummy(int x) { return x + 1; }
28 [[gnu::noinline,gnu::noipa]]
29 int i(int n, int buf[dummy(n)])
31 return __builtin_dynamic_object_size(buf, 0);
34 int main()
36 int n = 10;
37 int buf[n];
38 if (n * sizeof(int) != f(n, buf))
39 __builtin_abort();
40 if (n * sizeof(int) != g(n, buf))
41 __builtin_abort();
42 if (n * sizeof(int) != h(n, buf))
43 __builtin_abort();
45 (void)i(n, buf);
47 return 0;