Debian Codegraph @

gcc/testsuite/gcc.dg/pr123356-1.c

raw
1 /* { dg-do run } */
2 /* { dg-options "-O2" } */
3
4 typedef struct
5 {
6 long coeffs;
7 }
8 fmpz_poly_struct;
9 typedef struct
10 {
11 } n_poly_struct;
12 typedef struct
13 {
14 n_poly_struct * coeffs;
15 long alloc;
16 long length;
17 } n_bpoly_struct;
18 typedef struct
19 {
20 fmpz_poly_struct * coeffs;
21 long alloc;
22 long length;
23 } fmpz_bpoly_struct;
24 typedef fmpz_bpoly_struct fmpz_bpoly_t[];
25
26 __attribute__((noinline))
27 fmpz_poly_struct * fmpz_bpoly_swap_(fmpz_bpoly_t B, fmpz_bpoly_t Q)
28 {
29 fmpz_bpoly_struct t = *B;
30 *B = *Q;
31 *Q = t;
32 return B->coeffs;
33 }
34
35 __attribute__((noinline,optimize("no-strict-aliasing")))
36 fmpz_poly_struct * fmpz_bpoly_swap_2(fmpz_bpoly_t B, fmpz_bpoly_t Q)
37 {
38 fmpz_bpoly_struct t = *B;
39 *B = *Q;
40 *Q = t;
41 return B->coeffs;
42 }
43
44 int main(){
45 fmpz_poly_struct B_coeffs = {0}, Q_coeffs = {0};
46 fmpz_bpoly_t B = {0};
47 fmpz_bpoly_t Q = {0};
48 B->coeffs = &B_coeffs;
49 Q->coeffs = &Q_coeffs;
50 if (fmpz_bpoly_swap_(B, Q) != &Q_coeffs)
51 __builtin_abort();
52 B->coeffs = &B_coeffs;
53 Q->coeffs = &Q_coeffs;
54 if (fmpz_bpoly_swap_2(B, Q) != &Q_coeffs)
55 __builtin_abort();
56 return 0;
57 }
58