Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: std::move of empty absl::InlinedVector can result in Werror=uninitialized in gcc 12.2 with -O3 #1779

Open
elbartoishere opened this issue Oct 23, 2024 · 1 comment

Comments

@elbartoishere
Copy link

Describe the issue

Issue was hit when unrelated changes somehow changed layout of some struct causing the optimized build -O3 -Wall -Werror to fail with error:
/opt/compiler-explorer/libs/abseil/absl/container/internal/inlined_vector.h:522:5: error: 'test_obj1.absl::InlinedVector<unsigned int, 4, std::allocator<unsigned int> >::storage_.absl::inlined_vector_internal::Storage<unsigned int, 4, std::allocator<unsigned int> >::data_' is used uninitialized [-Werror=uninitialized]

Steps to reproduce the problem

It's not easy to reproduce but somehow in google test framework you can hit it rather easy:

TEST(TestCompile, trigger) {
    absl::InlinedVector<uint32_t, 4> test_obj1{};
    absl::InlinedVector<uint32_t, 4> test_obj2{std::move(test_obj1)};
    EXPECT_EQ(test_obj2.size(), 0);
}

https://godbolt.org/z/4aMTYbWKG

Not all gcc versions will report it but 12 and 13 do and you will need optimization.

What version of Abseil are you using?

Seen in all 20220623 and 20240722. (and version that godbolt uses)

What operating system and version are you using?

Should not really mater here:

$ uname -a
Linux 5007575312c8 5.15.0-102-generic #112-Ubuntu SMP Tue Mar 5 16:50:32 UTC 2024 x86_64 GNU/Linux
$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description:    Debian GNU/Linux 12 (bookworm)
Release:        12
Codename:       bookworm

What compiler and version are you using?

$ /usr/bin/x86_64-linux-gnu-g++-12 --version
x86_64-linux-gnu-g++-12 (Debian 12.2.0-14) 12.2.0
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

What build system are you using?

$ cmake --version
cmake version 3.25.1

Additional context

It's unclear if this is a compiler bug or technical correct as the MemcpyFrom function literately copies the uninitialized data_ union.

data_ = other_storage.data_;

@Quuxplusone
Copy link
Contributor

FWIW, this looks like basically a duplicate of https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95825 (same issue in boost::optional). That issue talks about copy-constructing rather than copy-assigning, but it feels like the same underlying issue. The best answer for now might be "just turn off that noisy GCC warning."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants