Skip to content

Always inline dyn_array_iterator constructor on AArch64 - #1280

Merged
Carson Radtke (carsonRadtke) merged 1 commit into
microsoft:mainfrom
mymedia2:patch-5
Sep 29, 2026
Merged

Carson Radtke (carsonRadtke) merged 1 commit into
microsoft:mainfrom
mymedia2:patch-5

Conversation

@mymedia2

Copy link
Copy Markdown
Contributor

Alas, I am still hit by that -Wstringop-overflow warning on AArch64 even in version 5.0.1. The warning appears depending on size of the translation unit, and it is not easy to prepare a minimal reproducible example. However, you can use the following to verify that the error exists in the main branch and that the proposed patch fixes it.

commands to reproduce
git checkout v5.0.1
docker run --rm -it -v $(pwd):/src/gsl -w /src/gsl debian:unstable
dpkg --add-architecture arm64
apt-get update
apt-get install -y --no-install-recommends g++-16-aarch64-linux-gnu pkgconf:arm64 libgtest-dev:arm64 cmake make
cmake -B build -DCMAKE_DISABLE_FIND_PACKAGE_Git=ON -DPKG_CONFIG_EXECUTABLE=/usr/bin/aarch64-linux-gnu-pkgconf -DCMAKE_CXX_COMPILER=/usr/bin/aarch64-linux-gnu-g++-16 -DCMAKE_BUILD_TYPE=Release -DCMAKE_VERBOSE_MAKEFILE=ON -DCMAKE_CXX_FLAGS=-std=c++20 -DGSL_CXX_STANDARD=20
make -C build -j$(nproc) dyn_array_tests

There are similar commands in my issue comment, but here I install pkgconf:arm64 and libgtest-dev:arm64 instead of ca-certificates and git. In Debian, we run CI tests without Internet access, and we are forced to use the packaged Google Test not downloading with Git.


I suggest adding a hint for early inliner in GCC, and thus working around the compiler bug.

Fixes: #1275
See also https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108912

@carsonRadtke

Copy link
Copy Markdown
Member

Repro on Compiler Explorer: https://godbolt.org/z/dav8ToW3v

Is there a reason to go the attribute route instead of the diagnostic suppression route? I don't think I have a preference either way, just curious if you considered it.

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstringop-overflow"
...
#pragma GCC diagnostic pop

@mymedia2

Copy link
Copy Markdown
Contributor Author

I suppose a variant with #pragma to suppress the diagnostic may be too broad and ignore valid warnings if any. The second question is where to put these pragmas? In tests/dyn_array_tests.cpp?

--- a/tests/dyn_array_tests.cpp
+++ b/tests/dyn_array_tests.cpp
@@ -156,8 +156,12 @@ TEST(dyn_array_tests, range_for)
 
 TEST(dyn_array_tests, use_std_algorithms)
 {
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wstringop-overflow"
     gsl::dyn_array<char> dodgers(26);
     std::generate(dodgers.begin(), dodgers.end(), [i = 0]() mutable { return 'a' + i++; });
+#pragma GCC diagnostic pop
+
     char ch = 'a';
     for (auto x : dodgers) EXPECT_EQ(x, ch++);
     EXPECT_EQ(std::find(dodgers.begin(), dodgers.end(), 'a'), dodgers.begin());

This hides the warning, but only in the test suite and does not help users who might stumble into this issue in their code in large translation units.

I searched through IPA dumps taken with the -fdump-ipa-inline-optimized flag and noticed that the compiler does not fully inline gsl::details::dyn_array_iterator<char>::dyn_array_iterator but replaces the call to the constructor with an internal gsl::details::dyn_array_iterator<char>::__ct_base.constprop function generated in the IPA-CP pass. When I added the [[gnu::always_inline]] attribute, std::generate was fully inlined into the test body as if it were in a translation unit with just one test case.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!

@carsonRadtke
Carson Radtke (carsonRadtke) merged commit a22ab8a into microsoft:main Sep 29, 2026
89 checks passed
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

Successfully merging this pull request may close these issues.

writing 16 bytes into a region of size 10

2 participants