Skip to content

Conversation

@Michael137
Copy link
Member

Use CRASHREPORTER_ANNOTATIONS_INITIALIZER when possible, which will handle the field initialization for us. That's what we already do in compiler-rt:

#if HAVE_CRASHREPORTERCLIENT_H
// Available in CRASHREPORTER_ANNOTATIONS_VERSION 5+
# ifdef CRASHREPORTER_ANNOTATIONS_INITIALIZER
CRASHREPORTER_ANNOTATIONS_INITIALIZER()
# else
// Support for older CrashRerporter annotiations
CRASH_REPORTER_CLIENT_HIDDEN
struct crashreporter_annotations_t gCRAnnotations
__attribute__((section("__DATA," CRASHREPORTER_ANNOTATIONS_SECTION))) = {
CRASHREPORTER_ANNOTATIONS_VERSION,
0,
0,
0,
0,
0,
0,
# if CRASHREPORTER_ANNOTATIONS_VERSION > 4
0,
# endif

This way we won't get these warnings when the layout of crashreporter_annotations_t changes:

llvm/lib/Support/PrettyStackTrace.cpp:92:65: warning: missing field 'blah' initializer [-Wmissing-field-initializers]
        = { CRASHREPORTER_ANNOTATIONS_VERSION, 0, 0, 0, 0, 0, 0, 0 };
                                                                  ^
1 warning generated

…notations_t

Use `CRASHREPORTER_ANNOTATIONS_INITIALIZER` when possible, which will
handle the field initialization for us. That's what we already do in
compiler-rt:
https://github.com/llvm/llvm-project/blob/0c480dd4b61e285bfda4de99c77da28922e64b94/compiler-rt/lib/sanitizer_common/sanitizer_mac.cpp#L799-L817

This way we won't get these warnings when the layout of
crashreporter_annotations_t changes:
```
llvm/lib/Support/PrettyStackTrace.cpp:92:65: warning: missing field 'blah' initializer [-Wmissing-field-initializers]
        = { CRASHREPORTER_ANNOTATIONS_VERSION, 0, 0, 0, 0, 0, 0, 0 };
                                                                  ^
1 warning generated
```
@llvmbot
Copy link
Member

llvmbot commented Aug 21, 2025

@llvm/pr-subscribers-llvm-support

Author: Michael Buch (Michael137)

Changes

Use CRASHREPORTER_ANNOTATIONS_INITIALIZER when possible, which will handle the field initialization for us. That's what we already do in compiler-rt:

#if HAVE_CRASHREPORTERCLIENT_H
// Available in CRASHREPORTER_ANNOTATIONS_VERSION 5+
# ifdef CRASHREPORTER_ANNOTATIONS_INITIALIZER
CRASHREPORTER_ANNOTATIONS_INITIALIZER()
# else
// Support for older CrashRerporter annotiations
CRASH_REPORTER_CLIENT_HIDDEN
struct crashreporter_annotations_t gCRAnnotations
__attribute__((section("__DATA," CRASHREPORTER_ANNOTATIONS_SECTION))) = {
CRASHREPORTER_ANNOTATIONS_VERSION,
0,
0,
0,
0,
0,
0,
# if CRASHREPORTER_ANNOTATIONS_VERSION > 4
0,
# endif

This way we won't get these warnings when the layout of crashreporter_annotations_t changes:

llvm/lib/Support/PrettyStackTrace.cpp:92:65: warning: missing field 'blah' initializer [-Wmissing-field-initializers]
        = { CRASHREPORTER_ANNOTATIONS_VERSION, 0, 0, 0, 0, 0, 0, 0 };
                                                                  ^
1 warning generated

Full diff: https://github.com/llvm/llvm-project/pull/154716.diff

1 Files Affected:

  • (modified) llvm/lib/Support/PrettyStackTrace.cpp (+19-7)
diff --git a/llvm/lib/Support/PrettyStackTrace.cpp b/llvm/lib/Support/PrettyStackTrace.cpp
index 3f03368c5d22e..8182468d28303 100644
--- a/llvm/lib/Support/PrettyStackTrace.cpp
+++ b/llvm/lib/Support/PrettyStackTrace.cpp
@@ -114,15 +114,27 @@ static void PrintCurStackTrace(raw_ostream &OS) {
 //  If any clients of llvm try to link to libCrashReporterClient.a themselves,
 //  only one crash info struct will be used.
 extern "C" {
+#ifdef CRASHREPORTER_ANNOTATIONS_INITIALIZER
+// Available in CRASHREPORTER_ANNOTATIONS_VERSION 5+
+CRASHREPORTER_ANNOTATIONS_INITIALIZER()
+#else
+// Older CrashReporter annotations layouts
 CRASH_REPORTER_CLIENT_HIDDEN
 struct crashreporter_annotations_t gCRAnnotations
-        __attribute__((section("__DATA," CRASHREPORTER_ANNOTATIONS_SECTION)))
-#if CRASHREPORTER_ANNOTATIONS_VERSION < 5
-        = { CRASHREPORTER_ANNOTATIONS_VERSION, 0, 0, 0, 0, 0, 0 };
-#else
-        = { CRASHREPORTER_ANNOTATIONS_VERSION, 0, 0, 0, 0, 0, 0, 0 };
-#endif
-}
+    __attribute__((section("__DATA," CRASHREPORTER_ANNOTATIONS_SECTION))) = {
+        CRASHREPORTER_ANNOTATIONS_VERSION,
+        0,
+        0,
+        0,
+        0,
+        0,
+        0,
+#if CRASHREPORTER_ANNOTATIONS_VERSION > 4
+        0
+#endif // CRASHREPORTER_ANNOTATIONS_VERSION > 4
+};
+#endif // CRASHREPORTER_ANNOTATIONS_INITIALIZER
+} // extern "C"
 #elif defined(__APPLE__) && HAVE_CRASHREPORTER_INFO
 extern "C" const char *__crashreporter_info__
     __attribute__((visibility("hidden"))) = 0;

@Michael137 Michael137 changed the title [llvm][Support] Fix missing initializer warnings for crashreporter_an… [llvm][Support] Fix missing initializer warnings for crashreporter_annotations_t Aug 21, 2025
@Michael137 Michael137 changed the title [llvm][Support] Fix missing initializer warnings for crashreporter_annotations_t [llvm][Support] Fix missing-field-initializer warnings for crashreporter_annotations_t Aug 21, 2025
Copy link
Contributor

@fhahn fhahn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks

@Michael137 Michael137 merged commit f3508aa into llvm:main Aug 21, 2025
9 checks passed
@Michael137 Michael137 deleted the llvm/crannotations-warnigns branch August 21, 2025 12:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants