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

Test compilation failures on GCC 11: error: array subscript -1 is outside array bounds of 'char[6]' [-Werror=array-bounds] #303

Closed
sanjayankur31 opened this issue Apr 17, 2021 · 7 comments

Comments

@sanjayankur31
Copy link

Hi there,

While packaging the 0.38.0 release for Fedora, we're seeing the build fail when tests are enabled. (This is on Fedora 34 and 35, which are both using GCC 11 now). The failures are of this form:

[ 32%] Building CXX object test/CMakeFiles/gsl-lite-v1-no-exc-cpp11.t.dir/owner.t.cpp.o
cd /builddir/build/BUILD/gsl-lite-0.38.0/x86_64-redhat-linux-gnu/test && /usr/bin/g++ -Dgsl_CONFIG_CONTRACT_CHECKING_AUDIT -Dgsl_CONFIG_CONTRACT_VIOLATION_TERMINATES -Dgsl_C
ONFIG_DEFAULTS_VERSION=1 -Dgsl_CONFIG_UNENFORCED_CONTRACTS_ELIDE -Dgsl_TESTING_ -I/builddir/build/BUILD/gsl-lite-0.38.0/include -O2 -flto=auto -ffat-lto-objects -fexceptions
 -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protec
tor-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -m64  -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -Werror -Wall -Wextra -W
conversion -Wsign-conversion -fno-elide-constructors -fstrict-aliasing -Wstrict-aliasing=2 -pedantic -Wno-long-long -fno-exceptions -std=c++11 -Winvalid-pch -include /buildd
ir/build/BUILD/gsl-lite-0.38.0/x86_64-redhat-linux-gnu/test/CMakeFiles/gsl-lite-v1-no-exc-cpp11.t.dir/cmake_pch.hxx -o CMakeFiles/gsl-lite-v1-no-exc-cpp11.t.dir/owner.t.cpp.
o -c /builddir/build/BUILD/gsl-lite-0.38.0/test/owner.t.cpp                                                                                                                  
/builddir/build/BUILD/gsl-lite-0.38.0/test/string_span.t.cpp: In function '__lest_function__883(lest::env&)':
/builddir/build/BUILD/gsl-lite-0.38.0/test/string_span.t.cpp:889:11: error: array subscript -1 is outside array bounds of 'char[6]' [-Werror=array-bounds]
  889 |     a.back() = '2';                                                                                                                                                  
      |     ~~~~~~^~                       
/builddir/build/BUILD/gsl-lite-0.38.0/test/string_span.t.cpp:885:10: note: while referencing 'hello'
  885 |     char hello[] = "hello";                                                                                                                                          
      |          ^~~~~                                                                                        
...

The complete build log is here: gsl-lite-0.38.0-buildlog.txt

@sanjayankur31
Copy link
Author

I'm seeing similar errors on Fedora 33 which is on GCC 10, so this may not be a GCC related issue. Build log for GCC 10 build:
gsl-lite-0.38.0-buildlog-f33-gcc10.txt

@mbeutel
Copy link
Collaborator

mbeutel commented Apr 18, 2021

Thanks for the report.

This appears to be a compiler bug which first surfaced in GCC 10.3. Here's a minimal repro:
https://gcc.godbolt.org/z/4xaY9vfzW

The problem only occurs when "-O2" or higher is enabled, hence it doesn't appear in our CI because we only test with the Debug build configuration (to keep the overall build times low). I'll change that so at least one version of each compiler will also build the RelWithDebInfo configuration.

I'll issue a bug report with GCC.

@sanjayankur31
Copy link
Author

Thanks very much. If there's anything we can do to help with this, please do let us know.

@mbeutel
Copy link
Collaborator

mbeutel commented Apr 18, 2021

Bug report: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100137

For the time being, you can make your build work by adding -Wno-error=array-bounds to CXXFLAGS (or -Wno-array-bounds if you want to suppress the warning entirely).

@sanjayankur31
Copy link
Author

Thanks, I've added that to our build now.

Fedora currently builds for a number of architectures:

https://fedoraproject.org/wiki/Architectures

  • x86_64
  • i686
  • aarch64
  • ppc64le
  • armv7hl
  • s390x

I'm happy to report that it builds correctly and all tests pass on all architectures apart from s390x. I've filed a separate issue for that here: #304

Here are the test builds:

@mbeutel
Copy link
Collaborator

mbeutel commented Apr 19, 2021

Awesome, thanks.

I hope I can fix #304 and add the -Wno-error=array-bounds workaround to the test suite later this week. I'll then issue a bugfix release which also includes the fix to #302.

@mbeutel
Copy link
Collaborator

mbeutel commented Apr 19, 2021

RelWithDebInfo CI builds added in f5b5b93, so as expected the build now failed for GCC 10. Added error suppression in subsequent commit 2ad316d.

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