1 /* $NetBSD: d_c99_complex_split.c,v 1.13 2023/03/28 14:44:34 rillig Exp $ */
2 # 3 "d_c99_complex_split.c"
3
4 /*
5 * Checks that the real and imaginary parts of a complex number can be
6 * accessed (since C99).
7 */
8
9 /* lint1-extra-flags: -X 351 */
10
11 int
b(double a)12 b(double a)
13 {
14 return a == 0;
15 }
16
17 void
a(void)18 a(void)
19 {
20 double _Complex z = 0;
21 if (b(__real__ z) && b(__imag__ z))
22 return;
23 }
24
25 void sink(double _Complex);
26
27 /*
28 * Before tree.c 1.275 from 2021-04-09, lint wrongly warned that when
29 * '__real__ c' was assigned, 'c may be used before set'.
30 *
31 * As of 2021-04-09, support for _Complex is still very incomplete, see
32 * build_real_imag for details. For example, lint does not know that after
33 * the assignment to '__real__ c', the variable is partially initialized.
34 */
35 void
set_complex_complete(double re,double im)36 set_complex_complete(double re, double im)
37 {
38 double _Complex c;
39
40 __real__ c = re;
41 __imag__ c = im;
42 sink(c);
43 }
44
45 /*
46 * Before tree.c 1.275 from 2021-04-09, lint wrongly warned that when
47 * '__real__ c' was assigned, 'c may be used before set [158]'.
48 *
49 * As of 2021-04-09, support for _Complex is still very incomplete, see
50 * build_real_imag for details.
51 */
52 void
set_complex_only_real(double re)53 set_complex_only_real(double re)
54 {
55 double _Complex c;
56
57 __real__ c = re;
58 /* __imag__ c is left uninitialized */
59 sink(c); /* XXX: may be used before set */
60 }
61
62 /*
63 * Before tree.c 1.275 from 2021-04-09, lint wrongly warned that when
64 * '__imag__ c' was assigned, 'c may be used before set [158]'.
65 *
66 * As of 2021-04-09, support for _Complex is still very incomplete, see
67 * build_real_imag for details.
68 */
69 void
set_complex_only_imag(double im)70 set_complex_only_imag(double im)
71 {
72 double _Complex c;
73
74 /* __real__ c is left uninitialized */
75 __imag__ c = im;
76 sink(c); /* XXX: may be used before set */
77 }
78
79 void
precedence_cast_expression(void)80 precedence_cast_expression(void)
81 {
82 double _Complex z = 0;
83 if (b(__real__(double _Complex)z) && b(__imag__(double _Complex)z))
84 return;
85 if (b(__real__(z)) && b(__imag__(z)))
86 return;
87 }
88