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

GCC 12.1 and LTO yields buffer overflow warnings #740

Closed
mattgodbolt opened this issue Jun 17, 2022 · 6 comments
Closed

GCC 12.1 and LTO yields buffer overflow warnings #740

mattgodbolt opened this issue Jun 17, 2022 · 6 comments

Comments

@mattgodbolt
Copy link

With LTO and optimization, and with some datetime functions referenced across TUs, GCC 12.1 errors about std::move() moving things into temporary buffers:

In function 'swap',
    inlined from 'iter_swap' at /opt/compiler-explorer/gcc-12.1.0/include/c++/12.1.0/bits/stl_algobase.h:182:11,
    inlined from '__reverse' at /opt/compiler-explorer/gcc-12.1.0/include/c++/12.1.0/bits/stl_algo.h:1107:18,
    inlined from 'reverse' at /opt/compiler-explorer/gcc-12.1.0/include/c++/12.1.0/bits/stl_algo.h:1134:21,
    inlined from 'read' at /opt/compiler-explorer/libs/date/v3.0.1/include/date/date.h:6513:21,
    inlined from 'read.constprop' at /opt/compiler-explorer/libs/date/v3.0.1/include/date/date.h:6474:9:
/opt/compiler-explorer/gcc-12.1.0/include/c++/12.1.0/bits/move.h:205:11: warning: writing 16 bytes into a region of size 11 [-Wstringop-overflow=]
  205 |       __a = _GLIBCXX_MOVE(__b);
      |           ^
/opt/compiler-explorer/libs/date/v3.0.1/include/date/date.h: In function 'read.constprop':
/opt/compiler-explorer/libs/date/v3.0.1/include/date/date.h:6506:15: note: destination object 'buf' of size 11
 6506 |         CharT buf[std::numeric_limits<unsigned>::digits10+2u] = {};
      |               ^

This took a while to repro, but:https://godbolt.org/z/e75YG6ano and could easily be a compiler bug, but I figured I'd post here first of all. This code has been working fine for years on earlier compilers (not that that's a guarantee of correctness!).

@HowardHinnant
Copy link
Owner

Thanks for the heads up.

If you are able to edit date.h, can you try changing:

        CharT buf[std::numeric_limits<unsigned>::digits10+2u] = {};
        auto e = buf;

to:

        CharT buf[std::numeric_limits<unsigned>::digits10+2u] = {};
        CharT* e = buf;

?

(just the second line changes above).

I'd try this experiment myself, but I couldn't figure out how to edit date.h on compiler explorer, and I'm so far unable to duplicate on wandbox. Though I did note that on an older clang, with auto e = , the type of e comes out to CharT*.

@mattgodbolt
Copy link
Author

Thanks! Ironically I have as much difficulty editing date.h as you, both on CE and on the one place I use it at work (which is where I discovered the issue). Will give it a go!

@mattgodbolt
Copy link
Author

This heinous link: https://godbolt.org/z/hPaqz7TY1 shows on line 6514 (!) of the date.h inlined I have modified to CharT *e = buf; but the error persists, unfortunately.

@HowardHinnant
Copy link
Owner

Thanks for your investigation. At this point I'm tempted to blame it on compiler error.

@mattgodbolt
Copy link
Author

Sounds good to me! I'll file it, closing this!

@mattgodbolt
Copy link
Author

The gcc bug I filed: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106020

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