xref: /netbsd-src/tests/usr.bin/xlint/lint1/d_gcc_compound_statements2.c (revision e6298b924c5ba98f3a22919b56dab04a87cdbb1c)
1 /*	$NetBSD: d_gcc_compound_statements2.c,v 1.6 2023/07/07 19:45:22 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 /* lint1-extra-flags: -X 351 */
11 
12 struct cpu_info {
13 	int bar;
14 };
15 
16 int
statement_expr_with_decl_and_stmt(void)17 statement_expr_with_decl_and_stmt(void)
18 {
19 	return ({
20 	    struct cpu_info *ci;
21 	    __asm__ volatile("movl %%fs:4,%0":"=r" (ci));
22 	    ci;
23 	})->bar;
24 }
25 
26 int
statement_expr_with_only_stmt(void)27 statement_expr_with_only_stmt(void)
28 {
29 	struct cpu_info ci = { 0 };
30 	return ({
31 		if (ci.bar > 0)
32 			ci.bar++;
33 		ci;
34 	}).bar;
35 }
36 
37 /*
38  * Since main1.c 1.58 from 2021-12-17 and before tree.c 1.404 from
39  * 2022-02-26, lint ran into an assertion failure due to a use-after-free.
40  * When typeok checked the operand types of the '=', the left node and the
41  * right node overlapped by 16 out of their 40 bytes on x86_64.
42  */
43 void
statement_expr_with_loop(unsigned u)44 statement_expr_with_loop(unsigned u)
45 {
46 	u = ({
47 		do {
48 		} while (0);
49 		u;
50 	});
51 }
52