Skip to content

Commit ce60d0b

Browse files
committed
[C] Suppress maybe-uninitialized warnings in GCC.
GCC is known to emit false positives when it cannot detect if a variable is initialized.
1 parent 6ffbd10 commit ce60d0b

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/c/CGenerator.java

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,14 @@ private static void generateGroupHeaderFunctions(
337337

338338
"SBE_ONE_DEF uint64_t %3$s_sbe_position(const struct %3$s *const codec)\n" +
339339
"{\n" +
340+
"#if defined(__GNUG__) && !defined(__clang__)\n" +
341+
"#pragma GCC diagnostic push\n" +
342+
"#pragma GCC diagnostic ignored \"-Wmaybe-uninitialized\"\n" +
343+
"#endif\n" +
340344
" return *codec->position_ptr;\n" +
345+
"#if defined(__GNUG__) && !defined(__clang__)\n" +
346+
"#pragma GCC diagnostic pop\n" +
347+
"#endif\n" +
341348
"}\n\n" +
342349

343350
"SBE_ONE_DEF bool %3$s_set_sbe_position(struct %3$s *const codec, const uint64_t position)\n" +
@@ -358,14 +365,28 @@ private static void generateGroupHeaderFunctions(
358365

359366
"SBE_ONE_DEF bool %3$s_has_next(const struct %3$s *const codec)\n" +
360367
"{\n" +
368+
"#if defined(__GNUG__) && !defined(__clang__)\n" +
369+
"#pragma GCC diagnostic push\n" +
370+
"#pragma GCC diagnostic ignored \"-Wmaybe-uninitialized\"\n" +
371+
"#endif\n" +
361372
" return codec->index + 1 < codec->count;\n" +
373+
"#if defined(__GNUG__) && !defined(__clang__)\n" +
374+
"#pragma GCC diagnostic pop\n" +
375+
"#endif\n" +
362376
"}\n\n" +
363377

364378
"SBE_ONE_DEF struct %3$s *%3$s_next(struct %3$s *const codec)\n" +
365379
"{\n" +
366380
" codec->offset = *codec->position_ptr;\n" +
381+
"#if defined(__GNUG__) && !defined(__clang__)\n" +
382+
"#pragma GCC diagnostic push\n" +
383+
"#pragma GCC diagnostic ignored \"-Wmaybe-uninitialized\"\n" +
384+
"#endif\n" +
367385
" if (SBE_BOUNDS_CHECK_EXPECT(((codec->offset + codec->block_length) " +
368386
"> codec->buffer_length), false))\n" +
387+
"#if defined(__GNUG__) && !defined(__clang__)\n" +
388+
"#pragma GCC diagnostic pop\n" +
389+
"#endif\n" +
369390
" {\n" +
370391
" errno = E108;\n" +
371392
" return NULL;\n" +
@@ -1341,7 +1362,14 @@ private CharSequence generateLoadValue(
13411362
{
13421363
sb.append(String.format(
13431364
" %1$s val;\n" +
1365+
"#if defined(__GNUG__) && !defined(__clang__)\n" +
1366+
"#pragma GCC diagnostic push\n" +
1367+
"#pragma GCC diagnostic ignored \"-Wmaybe-uninitialized\"\n" +
1368+
"#endif\n" +
13441369
" memcpy(&val, codec->buffer + codec->offset + %2$s, sizeof(%1$s));\n" +
1370+
"#if defined(__GNUG__) && !defined(__clang__)\n" +
1371+
"#pragma GCC diagnostic pop\n" +
1372+
"#endif\n" +
13451373
" %4$s %3$s(val);",
13461374
cTypeName,
13471375
offsetStr,
@@ -1400,7 +1428,14 @@ private CharSequence generateStoreValue(
14001428
{
14011429
sb.append(String.format(
14021430
" %1$s val = %2$s(value);\n" +
1403-
" memcpy(codec->buffer + codec->offset + %3$s, &val, sizeof(%1$s));",
1431+
"#if defined(__GNUG__) && !defined(__clang__)\n" +
1432+
"#pragma GCC diagnostic push\n" +
1433+
"#pragma GCC diagnostic ignored \"-Wmaybe-uninitialized\"\n" +
1434+
"#endif\n" +
1435+
" memcpy(codec->buffer + codec->offset + %3$s, &val, sizeof(%1$s));\n" +
1436+
"#if defined(__GNUG__) && !defined(__clang__)\n" +
1437+
"#pragma GCC diagnostic pop\n" +
1438+
"#endif",
14041439
cTypeName,
14051440
byteOrderStr,
14061441
offsetStr));

0 commit comments

Comments
 (0)