Nathan-Huckleberry created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Do not automatically self references of structs in statement expression
as warnings. Instead wait for uninitialized cfg analysis.
https://bugs.llvm.org/show_bug.cgi?id=42604


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D64678

Files:
  clang/test/Sema/warn-uninitialized-statement-expression.c


Index: clang/test/Sema/warn-uninitialized-statement-expression.c
===================================================================
--- /dev/null
+++ clang/test/Sema/warn-uninitialized-statement-expression.c
@@ -0,0 +1,41 @@
+// RUN: %clang_cc1 -fsyntax-only -Wuninitialized -verify %s
+
+void init(int*);
+
+void foo(void) {
+    int i = ({
+        int z = i; // expected-warning{{variable 'i' is uninitialized when 
used within its own initialization}}
+        init(&i);
+        i;
+    });
+}
+
+struct widget {
+    int x, y;
+};
+void init2(struct widget*);
+
+void bar(void) {
+    struct widget my_widget = ({
+        struct widget z = my_widget; // expected-warning{{variable 'my_widget' 
is uninitialized when used within its own initialization}}
+        int x = my_widget.x;
+        init2(&my_widget);
+        my_widget;
+    });
+}
+
+void baz(void) {
+  struct widget a = ({
+    struct widget b = ({
+      b = a;  // expected-warning{{variable 'a' is uninitialized when used 
within its own initialization}}
+    });
+    a;
+  });
+}
+
+void f(void) {
+  struct widget* a = ({
+    init2(a);  // expected-warning{{variable 'a' is uninitialized when used 
within its own initialization}}
+    a;
+  });
+}


Index: clang/test/Sema/warn-uninitialized-statement-expression.c
===================================================================
--- /dev/null
+++ clang/test/Sema/warn-uninitialized-statement-expression.c
@@ -0,0 +1,41 @@
+// RUN: %clang_cc1 -fsyntax-only -Wuninitialized -verify %s
+
+void init(int*);
+
+void foo(void) {
+    int i = ({
+        int z = i; // expected-warning{{variable 'i' is uninitialized when used within its own initialization}}
+        init(&i);
+        i;
+    });
+}
+
+struct widget {
+    int x, y;
+};
+void init2(struct widget*);
+
+void bar(void) {
+    struct widget my_widget = ({
+        struct widget z = my_widget; // expected-warning{{variable 'my_widget' is uninitialized when used within its own initialization}}
+        int x = my_widget.x;
+        init2(&my_widget);
+        my_widget;
+    });
+}
+
+void baz(void) {
+  struct widget a = ({
+    struct widget b = ({
+      b = a;  // expected-warning{{variable 'a' is uninitialized when used within its own initialization}}
+    });
+    a;
+  });
+}
+
+void f(void) {
+  struct widget* a = ({
+    init2(a);  // expected-warning{{variable 'a' is uninitialized when used within its own initialization}}
+    a;
+  });
+}
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to