xref: /netbsd-src/tests/usr.bin/xlint/lint1/d_gcc_compound_statements2.c (revision 7d62b00eb9ad855ffcd7da46b41e23feb5476fac)
1 /*	$NetBSD: d_gcc_compound_statements2.c,v 1.5 2022/02/26 20:36:11 rillig Exp $	*/
2 # 3 "d_gcc_compound_statements2.c"
3 
4 /*
5  * GCC statement expressions with non-expressions.
6  *
7  * https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html
8  */
9 
10 struct cpu_info {
11 	int bar;
12 };
13 
14 int
15 statement_expr_with_decl_and_stmt(void)
16 {
17 	return ({
18 	    struct cpu_info *ci;
19 	    __asm__ volatile("movl %%fs:4,%0":"=r" (ci));
20 	    ci;
21 	})->bar;
22 }
23 
24 int
25 statement_expr_with_only_stmt(void)
26 {
27 	struct cpu_info ci = { 0 };
28 	return ({
29 		if (ci.bar > 0)
30 			ci.bar++;
31 		ci;
32 	}).bar;
33 }
34 
35 /*
36  * Since main1.c 1.58 from 2021-12-17 and before tree.c 1.404 from
37  * 2022-02-26, lint ran into an assertion failure due to a use-after-free.
38  * When typeok checked the operand types of the '=', the left node and the
39  * right node overlapped by 16 out of their 40 bytes on x86_64.
40  */
41 void
42 statement_expr_with_loop(unsigned u)
43 {
44 	u = ({
45 		do {
46 		} while (0);
47 		u;
48 	});
49 }
50