[PATCH] D64678: [Sema] Fix -Wuninitialized for struct assignment from GNU C statement expression

Nathan Huckleberry via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 12 16:19:19 PDT 2019


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;
+  });
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D64678.209635.patch
Type: text/x-patch
Size: 1224 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190712/b836bb84/attachment.bin>


More information about the cfe-commits mailing list