Skip to content

Commit f3508aa

Browse files
authored
[llvm][Support] Fix missing-field-initializer warnings for crashreporter_annotations_t (#154716)
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 ```
1 parent 6ac01d1 commit f3508aa

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

llvm/lib/Support/PrettyStackTrace.cpp

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,27 @@ static void PrintCurStackTrace(raw_ostream &OS) {
114114
// If any clients of llvm try to link to libCrashReporterClient.a themselves,
115115
// only one crash info struct will be used.
116116
extern "C" {
117+
#ifdef CRASHREPORTER_ANNOTATIONS_INITIALIZER
118+
// Should be available in CRASHREPORTER_ANNOTATIONS_VERSION > 5
119+
CRASHREPORTER_ANNOTATIONS_INITIALIZER()
120+
#else
121+
// Older CrashReporter annotations layouts
117122
CRASH_REPORTER_CLIENT_HIDDEN
118123
struct crashreporter_annotations_t gCRAnnotations
119-
__attribute__((section("__DATA," CRASHREPORTER_ANNOTATIONS_SECTION)))
120-
#if CRASHREPORTER_ANNOTATIONS_VERSION < 5
121-
= { CRASHREPORTER_ANNOTATIONS_VERSION, 0, 0, 0, 0, 0, 0 };
122-
#else
123-
= { CRASHREPORTER_ANNOTATIONS_VERSION, 0, 0, 0, 0, 0, 0, 0 };
124-
#endif
125-
}
124+
__attribute__((section("__DATA," CRASHREPORTER_ANNOTATIONS_SECTION))) = {
125+
CRASHREPORTER_ANNOTATIONS_VERSION,
126+
0,
127+
0,
128+
0,
129+
0,
130+
0,
131+
0,
132+
#if CRASHREPORTER_ANNOTATIONS_VERSION > 4
133+
0
134+
#endif // CRASHREPORTER_ANNOTATIONS_VERSION > 4
135+
};
136+
#endif // CRASHREPORTER_ANNOTATIONS_INITIALIZER
137+
} // extern "C"
126138
#elif defined(__APPLE__) && HAVE_CRASHREPORTER_INFO
127139
extern "C" const char *__crashreporter_info__
128140
__attribute__((visibility("hidden"))) = 0;

0 commit comments

Comments
 (0)