Skip to content

Span size() broken on GCC > 5.4 #590

Closed

Description

Simple failing case:

std::array<int, 10> array;
gsl::span<int> test1 = gsl::make_span(array);

static gsl::span<int> test2;
test2 = test1;
std::cout << test1.size() << " " << test2.size();

Gives output:
10 0

As far as I'm aware, both spans should point to the same array, with identical size (which in fact happens on gcc-5.4).

This issue occurs only when using different optimization option than -O0 (-Og, -O1, -O2, -O3).

Tested on GCC 6.1, 6.2, 6.3, 7.1, 7.2, 7.3 (from https://godbolt.org/) - issue is identical.

Link to most-tailored case showing problem: https://godbolt.org/g/5u4XbD

A bit more sophisticated issue, showing that only assigning to static span, created earlier causes problem: https://godbolt.org/g/6AoWG3

I have tested where begin() and end() of each span was pointing to - they point at the same addresses, so even when size is incorrectly reported as 0, begin() and end() works fine.

I am aware that gcc >= 6 is not listed in supported platforms, so please close this issue if it is irrelevant.

Activity

  1. ggajoch commented on Nov 24, 2017

    @ggajoch
    Author

    For reference, after stripping down this snippet it turns out to be a gcc bug [1], affecting compiler versions from 6.1.0 onwards.
    So, this issue can be closed or left open for future reference.

    However, I tried and GSL tests passed successfully at gcc-6.3.0 on both Debug and Release targets.

    Maybe it could be worth having test checking for this condition, so when the test pass we know that this is fixed? I could submit a PR if you think that would be valuable contribution.

    [1] - https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83116

  2. neilmacintosh commented on Dec 21, 2017

    @neilmacintosh
    Contributor

    Thanks for such a detailed investigation and write-up Grzegorz Gajoch (@ggajoch)!

  3. ggajoch commented on Dec 21, 2017

    @ggajoch
    Author

    As a follow-up: this turned out to be a gcc bug, affecting every version above 5.4 - [1].
    This bug was fixed now in the trunk, fixing this test case as well - [2]. Target milestone for gcc is 6.5.

    [1] - https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83116
    [2] - https://godbolt.org/g/L6uUaZ

  4. changed the title [-]Span size() broken on GCC >= 6[/-] [+]Span size() broken on GCC > 5.4[/+] on Dec 21, 2017
  5. neilmacintosh commented on Apr 19, 2018

    @neilmacintosh
    Contributor

    I think it would be very useful to have a unit test that noticed whether the bug is present as Grzegorz Gajoch (@ggajoch) suggested.

  6. added
    Help Wanted
    Good First Issue
    on Apr 19, 2018
  7. Daniel599 commented on Jul 3, 2018

    @Daniel599
    Contributor

    Hi, I would like to help adding this test.
    The test fails on gcc-6.4 + release, should I disable the test for this config, or is there another option?

  8. annagrin commented on Jul 3, 2018

    @annagrin

    Daniel599 You can ifdef the test out based on gcc versions, only for the versions that fail, or better change the tests to expect failure for those versions, with a comment that this is a gcc bug

  9. Daniel599 commented on Jul 9, 2018

    @Daniel599
    Contributor

    Anna Gringauze (@annagrin) can you look into my PR please? Is that what you meant?
    Thanks.

  10. added a commit that references this issue on Jul 14, 2018
  11. JordanMaples commented on Aug 26, 2020

    @JordanMaples
    Contributor

    Maintainers' call: We believe this has now been fixed. Sorry about the delay.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Good First IssueHelp Wanted

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions