Debian Codegraph @

gcc/testsuite/g++.dg/cpp23/pr117287-attr.C

raw
1 // P1774R8 - Portable assumptions
2 // { dg-do run { target c++23 } }
3 // { dg-options "-O2 --param=logical-op-non-short-circuit=0" }
4 // Test the we can optimize based on conditions in assume.
5
6 static inline bool
7 foo (unsigned x)
8 {
9 return x == 4 || x == 5 || x == 9 || x == 10;
10 }
11
12 int v;
13
14 [[gnu::noipa]] void
15 bar (const char *p)
16 {
17 if (p[0] != (v ? 'a' : 'b') || p[1])
18 __builtin_abort ();
19 }
20
21 [[gnu::noipa]] void
22 baz (unsigned x)
23 {
24 bool a = x == 5;
25 [[assume (foo (x))]];
26 bar (a ? "a" : "b");
27 }
28
29 int
30 main ()
31 {
32 baz (4);
33 v = 1;
34 baz (5);
35 v = 0;
36 baz (9);
37 baz (10);
38 }