array bounds violations with precompiled headers

Bug #1983852 reported by Michał Sawicz
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
gcc
Incomplete
Medium
gcc-12 (Ubuntu)
Confirmed
High
Unassigned

Bug Description

When the gcc 12 toolchain appeared in proposed, Mir stopped building on arm64 on kinetic:

https://launchpad.net/~mir-team/+archive/ubuntu/dev/+packages?field.name_filter=mir&field.status_filter=&field.series_filter=kinetic

The error seems to be a compiler issue:

```
[ 90%] Building CXX object tests/unit-tests/CMakeFiles/mir_unit_tests.dir/input/test_config_changer.cpp.o
cd /<<PKGBUILDDIR>>/build-arm64/tests/unit-tests && /usr/bin/c++ -DBOOST_ALL_NO_LIB -DBOOST_DATE_TIME_DYN_LINK -DBOOST_FILESYSTEM_DYN_LINK -DBOOST_IOSTREAMS_DYN_LINK -DBOOST_PROGRAM_OPTIONS_DYN_LINK -DBOOST_SYSTEM_DYN_LINK -DEGL_NO_X11 -DGTEST_VERSION_MAJOR=1 -DGTEST_VERSION_MINOR=12 -DGTEST_VERSION_PATCH=1 -DLTTNG_UST_HAVE_SDT_INTEGRATION -DMESA_EGL_NO_X11_HEADERS -DMIR_BUILD_PLATFORM_EGLSTREAM_KMS -DMIR_BUILD_PLATFORM_GBM_KMS -DMIR_BUILD_PLATFORM_X11 -DMIR_DRMMODEADDFB_HAS_CONST_SIGNATURE -DMIR_SERVER_GRAPHICS_PLATFORM_ABI_STRING=\"20\" -DMIR_VERSION_MAJOR=2 -DMIR_VERSION_MICRO=0 -DMIR_VERSION_MINOR=8 -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -Dmir_unit_tests_EXPORTS -I/usr/src/googletest/googlemock/include -I/<<PKGBUILDDIR>>/include/miral -I/<<PKGBUILDDIR>>/src/include/server -I/usr/include/uuid -I/<<PKGBUILDDIR>>/include/test -I/<<PKGBUILDDIR>>/include/renderer -I/<<PKGBUILDDIR>>/include/renderers/gl -I/<<PKGBUILDDIR>>/tests/include -I/<<PKGBUILDDIR>> -I/usr/include/libdrm -I/usr/include/umockdev-1.0 -I/usr/include/glib-2.0 -I/usr/lib/aarch64-linux-gnu/glib-2.0/include -I/<<PKGBUILDDIR>>/include/renderers/sw -I/<<PKGBUILDDIR>>/src/include/cookie -I/<<PKGBUILDDIR>>/src/include/platform -I/<<PKGBUILDDIR>>/src/include/client -I/<<PKGBUILDDIR>>/src/include/common -I/<<PKGBUILDDIR>>/src/include/gl -I/<<PKGBUILDDIR>>/src/platforms/common/client -I/<<PKGBUILDDIR>>/src/platforms/common/server -I/usr/include/gio-unix-2.0 -I/usr/include/libmount -I/usr/include/blkid -I/<<PKGBUILDDIR>>/build-arm64/src/platform/graphics -I/<<PKGBUILDDIR>>/include/platform -I/<<PKGBUILDDIR>>/include/wayland -I/<<PKGBUILDDIR>>/build-arm64/src/wayland -I/<<PKGBUILDDIR>>/include/core -I/<<PKGBUILDDIR>>/include/common -I/<<PKGBUILDDIR>>/include/cookie -g -O2 -ffile-prefix-map=/<<PKGBUILDDIR>>=. -flto=auto -ffat-lto-objects -flto=auto -ffat-lto-objects -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -pthread -g -Wall -fno-strict-aliasing -pedantic -Wnon-virtual-dtor -Wextra -fPIC -Werror -Wno-mismatched-tags -Wno-psabi -flto -ffat-lto-objects -Wno-error=null-dereference -Wno-error=overloaded-virtual -Wno-sign-compare -Wno-error=maybe-uninitialized -fno-lto -Dregister= -Wno-error=infinite-recursion -std=c++20 -Winvalid-pch -include /<<PKGBUILDDIR>>/build-arm64/tests/unit-tests/CMakeFiles/mir_unit_tests.dir/cmake_pch.hxx -MD -MT tests/unit-tests/CMakeFiles/mir_unit_tests.dir/input/test_config_changer.cpp.o -MF CMakeFiles/mir_unit_tests.dir/input/test_config_changer.cpp.o.d -o CMakeFiles/mir_unit_tests.dir/input/test_config_changer.cpp.o -c /<<PKGBUILDDIR>>/tests/unit-tests/input/test_config_changer.cpp
In file included from /usr/include/c++/12/ios:40,
                 from /usr/include/c++/12/ostream:38,
                 from /usr/include/c++/12/bits/unique_ptr.h:41,
                 from /usr/include/c++/12/memory:76,
                 from /usr/src/googletest/googlemock/include/gmock/gmock-actions.h:139,
                 from /usr/src/googletest/googlemock/include/gmock/gmock.h:56,
                 from /<<PKGBUILDDIR>>/build-arm64/tests/acceptance-tests/CMakeFiles/mir_acceptance_tests.dir/cmake_pch.hxx:5,
                 from <command-line>:
In static member function ‘static constexpr std::char_traits<char>::char_type* std::char_traits<char>::copy(char_type*, const char_type*, std::size_t)’,
    inlined from ‘constexpr std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’ at /usr/include/c++/12/bits/basic_string.h:674:23,
    inlined from ‘constexpr std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(__cxx11::basic_string<_CharT, _Traits, _Allocator>&&, const _CharT*) [with _CharT = char; _Traits = char_traits<char>; _Alloc = allocator<char>]’ at /usr/include/c++/12/bits/basic_string.h:3554:43,
    inlined from ‘testing::internal::TypedExpectation<F>& testing::internal::MockSpec<F>::InternalExpectedAt(const char*, int, const char*, const char*) [with F = void(const std::shared_ptr<mir::input::Device>&)]’ at /usr/src/googletest/googlemock/include/gmock/gmock-spec-builders.h:1278:23,
    inlined from ‘virtual void TestInputDeviceHub_notifies_input_device_observer_about_available_devices_Test::TestBody()’ at /<<PKGBUILDDIR>>/tests/acceptance-tests/test_input_device_hub.cpp:73:5:
/usr/include/c++/12/bits/char_traits.h:431:56: error: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ forming offset [32, 36] is out of the bounds [0, 32] of object ‘<anonymous>’ with type ‘std::__cxx11::basic_string<char>’ [-Werror=array-bounds]
  431 | return static_cast<char_type*>(__builtin_memcpy(__s1, __s2, __n));
      | ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
In file included from /usr/src/googletest/googlemock/include/gmock/gmock-function-mocker.h:43,
                 from /usr/src/googletest/googlemock/include/gmock/gmock.h:58:
/usr/src/googletest/googlemock/include/gmock/gmock-spec-builders.h: In member function ‘virtual void TestInputDeviceHub_notifies_input_device_observer_about_available_devices_Test::TestBody()’:
/usr/src/googletest/googlemock/include/gmock/gmock-spec-builders.h:1278:63: note: ‘<anonymous>’ declared here
 1278 | const std::string source_text(std::string("EXPECT_CALL(") + obj + ", " +
      | ~~~~~~~~~~~~~~~~~~~~~~~^~~~~
In static member function ‘static constexpr std::char_traits<char>::char_type* std::char_traits<char>::copy(char_type*, const char_type*, std::size_t)’,
    inlined from ‘constexpr std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’ at /usr/include/c++/12/bits/basic_string.h:674:23,
    inlined from ‘constexpr std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(__cxx11::basic_string<_CharT, _Traits, _Allocator>&&, const _CharT*) [with _CharT = char; _Traits = char_traits<char>; _Alloc = allocator<char>]’ at /usr/include/c++/12/bits/basic_string.h:3554:43,
    inlined from ‘testing::internal::TypedExpectation<F>& testing::internal::MockSpec<F>::InternalExpectedAt(const char*, int, const char*, const char*) [with F = void(const std::shared_ptr<mir::input::Device>&)]’ at /usr/src/googletest/googlemock/include/gmock/gmock-spec-builders.h:1278:23,
    inlined from ‘virtual void TestInputDeviceHub_notifies_input_device_observer_about_available_devices_Test::TestBody()’ at /<<PKGBUILDDIR>>/tests/acceptance-tests/test_input_device_hub.cpp:73:5:
/usr/include/c++/12/bits/char_traits.h:431:56: error: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ forming offset [32, 38] is out of the bounds [0, 32] of object ‘<anonymous>’ with type ‘std::__cxx11::basic_string<char>’ [-Werror=array-bounds]
  431 | return static_cast<char_type*>(__builtin_memcpy(__s1, __s2, __n));
      | ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
/usr/src/googletest/googlemock/include/gmock/gmock-spec-builders.h: In member function ‘virtual void TestInputDeviceHub_notifies_input_device_observer_about_available_devices_Test::TestBody()’:
/usr/src/googletest/googlemock/include/gmock/gmock-spec-builders.h:1278:69: note: ‘<anonymous>’ declared here
 1278 | const std::string source_text(std::string("EXPECT_CALL(") + obj + ", " +
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~
In static member function ‘static constexpr std::char_traits<char>::char_type* std::char_traits<char>::copy(char_type*, const char_type*, std::size_t)’,
    inlined from ‘constexpr std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’ at /usr/include/c++/12/bits/basic_string.h:674:23,
    inlined from ‘constexpr std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(__cxx11::basic_string<_CharT, _Traits, _Allocator>&&, const _CharT*) [with _CharT = char; _Traits = char_traits<char>; _Alloc = allocator<char>]’ at /usr/include/c++/12/bits/basic_string.h:3554:43,
    inlined from ‘testing::internal::TypedExpectation<F>& testing::internal::MockSpec<F>::InternalExpectedAt(const char*, int, const char*, const char*) [with F = void(const std::shared_ptr<mir::input::Device>&)]’ at /usr/src/googletest/googlemock/include/gmock/gmock-spec-builders.h:1278:23,
    inlined from ‘virtual void TestInputDeviceHub_notifies_input_device_observer_about_available_devices_Test::TestBody()’ at /<<PKGBUILDDIR>>/tests/acceptance-tests/test_input_device_hub.cpp:73:5:
/usr/include/c++/12/bits/char_traits.h:431:56: error: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ forming offset [32, 53] is out of the bounds [0, 32] of object ‘<anonymous>’ with type ‘std::__cxx11::basic_string<char>’ [-Werror=array-bounds]
  431 | return static_cast<char_type*>(__builtin_memcpy(__s1, __s2, __n));
      | ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
/usr/src/googletest/googlemock/include/gmock/gmock-spec-builders.h: In member function ‘virtual void TestInputDeviceHub_notifies_input_device_observer_about_available_devices_Test::TestBody()’:
/usr/src/googletest/googlemock/include/gmock/gmock-spec-builders.h:1278:76: note: ‘<anonymous>’ declared here
 1278 | const std::string source_text(std::string("EXPECT_CALL(") + obj + ", " +
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
 1279 | call + ")");
      | ~~~~
In static member function ‘static constexpr std::char_traits<char>::char_type* std::char_traits<char>::copy(char_type*, const char_type*, std::size_t)’,
    inlined from ‘constexpr std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’ at /usr/include/c++/12/bits/basic_string.h:674:23,
    inlined from ‘constexpr std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(__cxx11::basic_string<_CharT, _Traits, _Allocator>&&, const _CharT*) [with _CharT = char; _Traits = char_traits<char>; _Alloc = allocator<char>]’ at /usr/include/c++/12/bits/basic_string.h:3554:43,
    inlined from ‘testing::internal::TypedExpectation<F>& testing::internal::MockSpec<F>::InternalExpectedAt(const char*, int, const char*, const char*) [with F = void(const std::shared_ptr<mir::input::Device>&)]’ at /usr/src/googletest/googlemock/include/gmock/gmock-spec-builders.h:1278:23,
    inlined from ‘virtual void TestInputDeviceHub_notifies_input_device_observer_about_available_devices_Test::TestBody()’ at /<<PKGBUILDDIR>>/tests/acceptance-tests/test_input_device_hub.cpp:73:5:
/usr/include/c++/12/bits/char_traits.h:431:56: error: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ forming offset [32, 54] is out of the bounds [0, 32] of object ‘source_text’ with type ‘const std::string’ {aka ‘const std::__cxx11::basic_string<char>’} [-Werror=array-bounds]
  431 | return static_cast<char_type*>(__builtin_memcpy(__s1, __s2, __n));
      | ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
/usr/src/googletest/googlemock/include/gmock/gmock-spec-builders.h: In member function ‘virtual void TestInputDeviceHub_notifies_input_device_observer_about_available_devices_Test::TestBody()’:
/usr/src/googletest/googlemock/include/gmock/gmock-spec-builders.h:1278:23: note: ‘source_text’ declared here
 1278 | const std::string source_text(std::string("EXPECT_CALL(") + obj + ", " +
      | ^~~~~~~~~~~
cc1plus: all warnings being treated as errors
make[3]: *** [tests/acceptance-tests/CMakeFiles/mir_acceptance_tests.dir/build.make:192: tests/acceptance-tests/CMakeFiles/mir_acceptance_tests.dir/test_input_device_hub.cpp.o] Error 1
make[3]: Leaving directory '/<<PKGBUILDDIR>>/build-arm64'
make[2]: *** [CMakeFiles/Makefile2:4768: tests/acceptance-tests/CMakeFiles/mir_acceptance_tests.dir/all] Error 2
make[2]: *** Waiting for unfinished jobs....
```

I'm working on getting a small reproducer, but so far I've confirmed disabling precompiled headers makes the issue go away.

ProblemType: Bug
DistroRelease: Ubuntu 22.10
Package: g++-12 12.1.0-5ubuntu1
ProcVersionSignature: User Name 5.15.0-43.46-generic 5.15.39
Uname: Linux 5.15.0-43-generic aarch64
NonfreeKernelModules: tls binfmt_misc veth unix_diag nft_masq nft_chain_nat bridge stp llc zfs zunicode zzstd zlua zcommon znvpair zavl icp spl ebtable_filter ebtables ip6table_raw ip6table_mangle ip6table_nat ip6table_filter ip6_tables iptable_raw iptable_mangle iptable_nat nf_nat nf_conntrack nf_defrag_ipv6 nf_defrag_ipv4 iptable_filter bpfilter nf_tables nfnetlink nls_iso8859_1 sch_fq_codel dm_multipath scsi_dh_rdac scsi_dh_emc scsi_dh_alua ipmi_devintf ipmi_msghandler drm efi_pstore ip_tables x_tables autofs4 btrfs blake2b_generic zstd_compress raid10 raid456 async_raid6_recov async_memcpy async_pq async_xor async_tx xor xor_neon raid6_pq libcrc32c raid1 raid0 multipath linear crct10dif_ce virtio_net net_failover failover virtio_blk aes_neon_bs aes_neon_blk crypto_simd cryptd
ApportVersion: 2.22.0-0ubuntu4
Architecture: arm64
CasperMD5CheckResult: unknown
Date: Mon Aug 8 10:16:17 2022
ProcEnviron:
 TERM=screen-256color
 PATH=(custom, no user)
 LANG=C.UTF-8
 SHELL=/bin/bash
SourcePackage: gcc-12
UpgradeStatus: No upgrade log present (probably fresh install)

Revision history for this message
Michał Sawicz (saviq) wrote :
description: updated
Revision history for this message
Michał Sawicz (saviq) wrote (last edit ):
Download full text (9.5 KiB)

I got this reproduced down to:

```cpp
class Class
{
    public:
        void member(bool) {};
};

namespace
{

struct MockClass : public Class
{
    MOCK_METHOD1(member, void(bool));
};

}

TEST(Test, tests)
{
    MockClass object;
    EXPECT_CALL(object, member(testing::_));
}
```

The cmake_pch.hxx:

```cpp
/* generated by CMake */

#pragma GCC system_header
#ifdef __cplusplus
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <vector>
#include <string>
#include <exception>
#include <memory>
#endif // __cplusplus
```

The compiler command:

```
/usr/bin/g++-12 -DBOOST_ALL_NO_LIB -DBOOST_DATE_TIME_DYN_LINK -DBOOST_FILESYSTEM_DYN_LINK -DBOOST_IOSTREAMS_DYN_LINK -DBOOST_PROGRAM_OPTIONS_DYN_LINK -DBOOST_SYSTEM_DYN_LINK -DEGL_NO_X11 -DGTEST_VERSION_MAJOR=1 -DGTEST_VERSION_MINOR=12 -DGTEST_VERSION_PATCH=1 -DLTTNG_UST_HAVE_SDT_INTEGRATION -DMESA_EGL_NO_X11_HEADERS -DMIR_BUILD_PLATFORM_GBM_KMS -DMIR_DRMMODEADDFB_HAS_CONST_SIGNATURE -DMIR_VERSION_MAJOR=2 -DMIR_VERSION_MICRO=0 -DMIR_VERSION_MINOR=8 -D_FILE_OFFSET_BITS=64 -I/usr/src/googletest/googlemock/include -O2 -ffat-lto-objects -pthread -fPIC -std=c++20 -include /home/ubuntu/mir/build-arm64/tests/acceptance-tests/CMakeFiles/mir_acceptance_tests.dir/cmake_pch.hxx -c tmp.cpp

In file included from /usr/include/c++/12/ios:40,
                 from /usr/include/c++/12/ostream:38,
                 from /usr/include/c++/12/bits/unique_ptr.h:41,
                 from /usr/include/c++/12/memory:76,
                 from /usr/src/googletest/googlemock/include/gmock/gmock-actions.h:139,
                 from /usr/src/googletest/googlemock/include/gmock/gmock.h:56,
                 from /home/ubuntu/mir/build-arm64/tests/acceptance-tests/CMakeFiles/mir_acceptance_tests.dir/cmake_pch.hxx:5,
                 from <command-line>:
In static member function ‘static constexpr std::char_traits<char>::char_type* std::char_traits<char>::copy(char_type*, const char_type*, std::size_t)’,
    inlined from ‘constexpr std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&&) [with _CharT = char; _Traits = std::char_traits<char>;
 _Alloc = std::allocator<char>]’ at /usr/include/c++/12/bits/basic_string.h:674:23,
    inlined from ‘constexpr std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(__cxx11::basic_string<_CharT, _Traits, _Allocator>&&, const _CharT*) [with _CharT = char; _Traits = char
_traits<char>; _Alloc = allocator<char>]’ at /usr/include/c++/12/bits/basic_string.h:3554:43,
    inlined from ‘testing::internal::TypedExpectation<F>& testing::internal::MockSpec<F>::InternalExpectedAt(const char*, int, const char*, const char*) [with F = void(bool)]’ at /usr/src/googletest/goog
lemock/include/gmock/gmock-spec-builders.h:1278:23,
    inlined from ‘virtual void Test_tests_Test::TestBody()’ at tmp.cpp:20:5:
/usr/include/c++/12/bits/char_traits.h:431:56: warning: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ writing 19 bytes into a region of size 16 overflows the destination [-Wstringop-ove
rflow=]
  431 | return static_cast<char_type*>(__builtin_memcpy(__s1, __s2, __n));
      | ...

Read more...

Revision history for this message
Michał Sawicz (saviq) wrote :

> I also can't reproduce on a clean system…

OK, including the actual precompiled header file (cmake_pch.hxx.gch) allowed me to reproduce again. I will find the command to generate it.

Michał Sawicz (saviq)
summary: `forming offset [32, 36] is out of the bounds` error on arm64 with
- precompiled headers
+ precompiled headers on arm64
Revision history for this message
Michał Sawicz (saviq) wrote : Re: `forming offset [32, 36] is out of the bounds` error on arm64 with precompiled headers on arm64

The full command used to precompile the header:

```
/usr/bin/g++-12 -DBOOST_ALL_NO_LIB -DBOOST_DATE_TIME_DYN_LINK -DBOOST_FILESYSTEM_DYN_LINK -DBOOST_IOSTREAMS_DYN_LINK -DBOOST_PROGRAM_OPTIONS_DYN_LINK -DBOOST_SYSTEM_DYN_LINK -DEGL_NO_X11 -DGTEST_VERSION_MAJOR=1 -DGTEST_VERSION_MINOR=12 -DGTEST_VERSION_PATCH=1 -DLTTNG_UST_HAVE_SDT_INTEGRATION -DMESA_EGL_NO_X11_HEADERS -DMIR_BUILD_PLATFORM_GBM_KMS -DMIR_DRMMODEADDFB_HAS_CONST_SIGNATURE -DMIR_VERSION_MAJOR=2 -DMIR_VERSION_MICRO=0 -DMIR_VERSION_MINOR=8 -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -I/usr/src/googletest/googlemock/include -I/home/ubuntu/mir/include/miral -I/home/ubuntu/mir/src/include/server -I/usr/include/uuid -I/home/ubuntu/mir/include/test -I/home/ubuntu/mir/include/renderer -I/home/ubuntu/mir/include/renderers/gl -I/home/ubuntu/mir/build-arm64/src/platform/graphics -I/home/ubuntu/mir/include/platform -I/home/ubuntu/mir/src/include/platform -I/home/ubuntu/mir/include/wayland -I/home/ubuntu/mir/build-arm64/src/wayland -I/home/ubuntu/mir/include/core -I/home/ubuntu/mir/include/common -I/home/ubuntu/mir/include/cookie -g -O2 -ffile-prefix-map=/home/ubuntu/mir=. -flto=auto -ffat-lto-objects -flto=auto -ffat-lto-objects -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -pthread -g -Wall -fno-strict-aliasing -pedantic -Wnon-virtual-dtor -Wextra -fPIC -Werror -Wno-mismatched-tags -Wno-psabi -flto -ffat-lto-objects -Wno-error=null-dereference -Wno-error=overloaded-virtual -Wno-sign-compare -Wno-error=maybe-uninitialized -fno-lto -Wno-error=infinite-recursion -std=c++20 -Winvalid-pch -x c++-header -include cmake_pch.hxx -o cmake_pch.hxx.gch -c cmake_pch.hxx.cxx
```

I'll try and strip it down further, but at least this is a portable reproducer.

Replacing `g++-12` with `g++-11` makes it compile.

Revision history for this message
Michał Sawicz (saviq) wrote :

OK got the smallest reproducer I could come up with:

cmake_pch.hxx
```cpp
/* generated by CMake */

#pragma GCC system_header
#ifdef __cplusplus
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#endif // __cplusplus
```

cmake_pch.hxx.cxx
```cpp
/* generated by CMake */
```

tmp.cpp
```cpp
class Class
{
    public:
        void member(bool) {};
};

namespace
{

struct MockClass : public Class
{
    MOCK_METHOD1(member, void(bool));
};

}

TEST(Test, tests)
{
    MockClass object;
    EXPECT_CALL(object, member(testing::_));
}
```

```
/usr/bin/g++-12 -I/usr/src/googletest/googlemock/include -O2 -std=c++20 -include cmake_pch.hxx -include cmake_pch.hxx -x c++-header -o cmake_pch.hxx.gch -c cmake_pch.hxx.cxx
/usr/bin/g++-12 -I/usr/src/googletest/googlemock/include -O2 -std=c++20 -include cmake_pch.hxx -c tmp.cpp
```

Replace with `g++-11`, and it's fine.

Revision history for this message
Michał Sawicz (saviq) wrote :

This now spread to other architectures, and migrated despite this bug:

https://launchpad.net/~mir-team/+archive/ubuntu/dev/+sourcepub/13898542/+listing-archive-extra

summary: - `forming offset [32, 36] is out of the bounds` error on arm64 with
- precompiled headers on arm64
+ `forming offset [32, 36] is out of the bounds` error with precompiled
+ headers
Revision history for this message
In , Michał Sawicz (saviq) wrote :
Download full text (9.9 KiB)

Created attachment 53527
Header and source files needed to reproduce

NB: googletest required to reproduce.

Given the three minimal source files and the commands:

```
/usr/bin/g++-12 -I/usr/src/googletest/googlemock/include -O2 -std=c++20 -include cmake_pch.hxx -include cmake_pch.hxx -x c++-header -o cmake_pch.hxx.gch -c cmake_pch.hxx.cxx
/usr/bin/g++-12 -I/usr/src/googletest/googlemock/include -O2 -std=c++20 -include cmake_pch.hxx -c tmp.cpp
```

gcc-12 errors out with the following:

```
In file included from /usr/include/c++/12/ios:40,
                 from /usr/include/c++/12/ostream:38,
                 from /usr/include/c++/12/bits/unique_ptr.h:41,
                 from /usr/include/c++/12/memory:76,
                 from /usr/src/googletest/googlemock/include/gmock/gmock-actions.h:139,
                 from /usr/src/googletest/googlemock/include/gmock/gmock.h:56,
                 from ./cmake_pch.hxx:5,
                 from <command-line>:
In static member function ‘static constexpr std::char_traits<char>::char_type* std::char_traits<char>::copy(char_type*, const char_type*, std::size_t)’,
    inlined from ‘constexpr std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&&) [with _CharT = char; _Traits = std::char_traits<char>;
 _Alloc = std::allocator<char>]’ at /usr/include/c++/12/bits/basic_string.h:675:23,
    inlined from ‘constexpr std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(__cxx11::basic_string<_CharT, _Traits, _Allocator>&&, const _CharT*) [with _CharT = char; _Traits = char
_traits<char>; _Alloc = allocator<char>]’ at /usr/include/c++/12/bits/basic_string.h:3555:43,
    inlined from ‘testing::internal::TypedExpectation<F>& testing::internal::MockSpec<F>::InternalExpectedAt(const char*, int, const char*, const char*) [with F = void(bool)]’ at /usr/src/googletest/goog
lemock/include/gmock/gmock-spec-builders.h:1278:23,
    inlined from ‘virtual void Test_tests_Test::TestBody()’ at tmp.cpp:20:5:
/usr/include/c++/12/bits/char_traits.h:431:56: warning: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ writing 19 bytes into a region of size 16 overflows...

Revision history for this message
Michał Sawicz (saviq) wrote : Re: `forming offset [32, 36] is out of the bounds` error with precompiled headers
Revision history for this message
In , Rguenth (rguenth) wrote :

You say that without using a PCH it doesn't warn?

Revision history for this message
In , Michał Sawicz (saviq) wrote :

@Richard correct, if you skip the precompilation, it compiles fine:

```
$ rm cmake_pch.hxx.gch
$ /usr/bin/g++-12 -I/usr/src/googletest/googlemock/include -O2 -std=c++20 -include cmake_pch.hxx -c tmp.cpp
$
```

Changed in gcc-12 (Ubuntu):
importance: Undecided → High
Revision history for this message
In , Pinskia (pinskia) wrote :

Can you attach the preprocessed source for the cmake_pch.hxx file?

Revision history for this message
In , Michał Sawicz (saviq) wrote :

Created attachment 53756
Preprocessed header source

I believe that should be it.

Changed in gcc:
importance: Unknown → Medium
status: Unknown → Incomplete
Revision history for this message
Dan Bungert (dbungert) wrote : Re: `forming offset [32, 36] is out of the bounds` error with precompiled headers

Michał, I assume you still see this?
A fresh try in a container with the version from comment #5 worked well for me.

Simon Chopin (schopin)
Changed in gcc-12 (Ubuntu):
status: New → Incomplete
Revision history for this message
Michał Sawicz (saviq) wrote :

@Dan @Simon yes, still here on kinetic:

$ g++ --version
g++ (Ubuntu 12.2.0-3ubuntu1) 12.2.0

$ /usr/bin/g++-12 -I/usr/src/googletest/googlemock/include -O2 -std=c++20 -include cmake_pch.hxx -include cmake_pch.hxx -x c++-header -o cmake_pch.hxx.gch -c cmake_pch.hxx.cxx

$ /usr/bin/g++-12 -I/usr/src/googletest/googlemock/include -O2 -std=c++20 -include cmake_pch.hxx -c tmp.cpp

# blowup

Are you sure it's using the precompiled header for you?

Revision history for this message
Dan Bungert (dbungert) wrote :

aha I see the problem.
This is a warnings-to-errors thing.
The original command line has -Werror, but the sample command line does not.
Also the sample in the comments doesn't produce the "forming offset" message, so I have adjusted the title.

Frankly, I think treating array-bounds warnings as errors is quite sensible.

summary: - `forming offset [32, 36] is out of the bounds` error with precompiled
- headers
+ array bounds violations with precompiled headers
Changed in gcc-12 (Ubuntu):
status: Incomplete → Confirmed
Revision history for this message
Benjamin Drung (bdrung) wrote :
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.