[libc-commits] [libc] [libc][pthread] fix -Wmissing-field-initializers (PR #126314)

Nick Desaulniers via libc-commits libc-commits at lists.llvm.org
Wed Feb 12 09:24:04 PST 2025


================
@@ -25,8 +27,49 @@
 #define PTHREAD_PROCESS_PRIVATE 0
 #define PTHREAD_PROCESS_SHARED 1
 
-#define PTHREAD_MUTEX_INITIALIZER {0}
-#define PTHREAD_RWLOCK_INITIALIZER {0}
+#ifdef __linux__
+#define PTHREAD_MUTEX_INITIALIZER                                              \
+  {                                                                            \
+      /* .__timed = */ 0,                                                      \
+      /* .__recursive = */ 0,                                                  \
+      /* .__robust = */ 0,                                                     \
+      /* .__owner = */ NULL,                                                   \
+      /* .__lock_count = */ 0, /* .__futex_word = */                           \
+      {                                                                        \
+          /* .__word = */ 0,                                                   \
+      },                                                                       \
+  }
+#else
+#define PTHREAD_MUTEX_INITIALIZER                                              \
+  {                                                                            \
+      /* .__timed = */ 0,      /* .__recursive = */ 0,                         \
+      /* .__robust = */ 0,     /* .__owner = */ NULL,                          \
+      /* .__lock_count = */ 0,                                                 \
+  }
+#endif
+
+#define PTHREAD_RWLOCK_INITIALIZER                                             \
+  {                                                                            \
+      /* .__is_pshared = */ 0,                                                 \
+      /* .__preference = */ 0,                                                 \
+      /* .__state = */ 0,                                                      \
+      /* .__write_tid = */ 0, /* .__wait_queue_mutex = */                      \
----------------
nickdesaulniers wrote:

It does.  That makes me sad to mix comments that look like designated initializers, but only for top level members, with more aggregate initializers without such comments for nested members, but I lack the will to wrestle with the formatter.

I think we _could_ put a .clang-format file in this dir, and use https://clang.llvm.org/docs/ClangFormatStyleOptions.html#whitespacesensitivemacros to turn off formatting for this macro.

https://github.com/llvm/llvm-project/pull/126314


More information about the libc-commits mailing list