annotate clang/test/Sema/warn-uninitialized-statement-expression.c @ 222:81f6424ef0e3 llvm-original

LLVM original branch
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 18 Jul 2021 22:10:01 +0900 (2021-07-18)
parents 1d019706d866
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // RUN: %clang_cc1 -fsyntax-only -Wuninitialized -verify %s
anatofuz
parents:
diff changeset
2
anatofuz
parents:
diff changeset
3 void init(int *);
anatofuz
parents:
diff changeset
4
anatofuz
parents:
diff changeset
5 void foo(void) {
anatofuz
parents:
diff changeset
6 int i = ({
anatofuz
parents:
diff changeset
7 init(&i);
anatofuz
parents:
diff changeset
8 i;
anatofuz
parents:
diff changeset
9 });
anatofuz
parents:
diff changeset
10 }
anatofuz
parents:
diff changeset
11
anatofuz
parents:
diff changeset
12 void foo_bad(void) {
anatofuz
parents:
diff changeset
13 int i = ({
anatofuz
parents:
diff changeset
14 int z = i; // expected-warning{{variable 'i' is uninitialized when used within its own initialization}}
anatofuz
parents:
diff changeset
15 init(&i);
anatofuz
parents:
diff changeset
16 i;
anatofuz
parents:
diff changeset
17 });
anatofuz
parents:
diff changeset
18 }
anatofuz
parents:
diff changeset
19
anatofuz
parents:
diff changeset
20 struct widget {
anatofuz
parents:
diff changeset
21 int x, y;
anatofuz
parents:
diff changeset
22 };
anatofuz
parents:
diff changeset
23 void init2(struct widget *);
anatofuz
parents:
diff changeset
24
anatofuz
parents:
diff changeset
25 void bar(void) {
anatofuz
parents:
diff changeset
26 struct widget my_widget = ({
anatofuz
parents:
diff changeset
27 init2(&my_widget);
anatofuz
parents:
diff changeset
28 my_widget;
anatofuz
parents:
diff changeset
29 });
anatofuz
parents:
diff changeset
30 struct widget a = (init2(&a), a);
anatofuz
parents:
diff changeset
31 }
anatofuz
parents:
diff changeset
32
anatofuz
parents:
diff changeset
33 void bar_bad(void) {
anatofuz
parents:
diff changeset
34 struct widget my_widget = ({
anatofuz
parents:
diff changeset
35 struct widget z = my_widget; // expected-warning{{variable 'my_widget' is uninitialized when used within its own initialization}}
anatofuz
parents:
diff changeset
36 int x = my_widget.x; //FIXME: There should be an uninitialized warning here
anatofuz
parents:
diff changeset
37 init2(&my_widget);
anatofuz
parents:
diff changeset
38 my_widget;
anatofuz
parents:
diff changeset
39 });
anatofuz
parents:
diff changeset
40 }
anatofuz
parents:
diff changeset
41
anatofuz
parents:
diff changeset
42 void baz(void) {
anatofuz
parents:
diff changeset
43 struct widget a = ({
anatofuz
parents:
diff changeset
44 struct widget b = ({
anatofuz
parents:
diff changeset
45 b = a; // expected-warning{{variable 'a' is uninitialized when used within its own initialization}}
anatofuz
parents:
diff changeset
46 });
anatofuz
parents:
diff changeset
47 a;
anatofuz
parents:
diff changeset
48 });
anatofuz
parents:
diff changeset
49 }
anatofuz
parents:
diff changeset
50
anatofuz
parents:
diff changeset
51 void f(void) {
anatofuz
parents:
diff changeset
52 struct widget *a = ({
anatofuz
parents:
diff changeset
53 init2(a); // expected-warning{{variable 'a' is uninitialized when used within its own initialization}}
anatofuz
parents:
diff changeset
54 a;
anatofuz
parents:
diff changeset
55 });
anatofuz
parents:
diff changeset
56 }