Skip to content

[libc][test] spew of -Wuninitialized with gcc-14 #124814

@nickdesaulniers

Description

@nickdesaulniers

I'm seeing a large spew of:

In constructor ‘__llvm_libc_20_0_0_git::testing::FormatSectionMatcher::FormatSectionMatcher(__llvm_libc_20_0_0_git::printf_core::FormatSection)’,
    inlined from ‘virtual void LlvmLibcPrintfParserTest_DoublePercentIsAllowedInvalidIndex::Run()’ at /android0/llvm-project/libc/test/src/stdio/printf_core/parser_test.cpp:626:3:
/android0/llvm-project/libc/test/UnitTest/PrintfMatcher.h:25:9: error: ‘expected0.__llvm_libc_20_0_0_git::printf_core::FormatSection::conv_val_ptr’ is used uninitialized [-Werror=uninitialized]
   25 |       : expected(expectedValue) {}
      |         ^~~~~~~~~~~~~~~~~~~~~~~
/android0/llvm-project/libc/test/src/stdio/printf_core/parser_test.cpp: In member function ‘virtual void LlvmLibcPrintfParserTest_DoublePercentIsAllowedInvalidIndex::Run()’:
/android0/llvm-project/libc/test/src/stdio/printf_core/parser_test.cpp:621:46: note: ‘expected0.__llvm_libc_20_0_0_git::printf_core::FormatSection::conv_val_ptr’ was declared here
  621 |   LIBC_NAMESPACE::printf_core::FormatSection expected0;
      |                                              ^~~~~~~~~

when building the unit tests with gcc-14.

Perhaps EXPECT_PFORMAT_EQ is a macro that constructs a FormatSectionMatcher, which copy constructs the FormatSection expected (highlighted in the diagnostic), but the default implicit copy constructor of FormatSectionMatcher is copying over every field, where fields such as FormatSection::conv_val_ptr and FormatSection::conv_val_raw have not been initialized!

I wonder if we should either:

  • have the unit tests that default construct FormatSection's initialize conv_val_ptr and conv_val_raw
  • explicitly delete the implicit default constructor for FormatSection and update the tests
  • other?

Observed while trying to test #124036.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions