Skip to content
This repository has been archived by the owner on Sep 19, 2023. It is now read-only.

8288759: GCC 12 fails to compile signature.cpp due to -Wstringop-overread #49

Closed

Conversation

shipilev
Copy link
Member

@shipilev shipilev commented Jun 20, 2022

Trying to compile with GCC 12.1.1 (current Fedora Rawhide) yields this failure:

In file included from /home/test/shipilev-jdk/src/hotspot/share/utilities/globalDefinitions_gcc.hpp:35,
                 from /home/test/shipilev-jdk/src/hotspot/share/utilities/globalDefinitions.hpp:35,
                 from /home/test/shipilev-jdk/src/hotspot/share/memory/allocation.hpp:29,
                 from /home/test/shipilev-jdk/src/hotspot/share/classfile/classLoaderData.hpp:28,
                 from /home/test/shipilev-jdk/src/hotspot/share/precompiled/precompiled.hpp:34:
In function 'const void* memchr(const void*, int, size_t)',
    inlined from 'int SignatureStream::scan_type(BasicType)' at /home/test/shipilev-jdk/src/hotspot/share/runtime/signature.cpp:343:32,
    inlined from 'void SignatureStream::next()' at /home/test/shipilev-jdk/src/hotspot/share/runtime/signature.cpp:373:19,
    inlined from 'void SignatureIterator::do_parameters_on(T*) [with T = Fingerprinter]' at /home/test/shipilev-jdk/src/hotspot/share/runtime/signature.hpp:635:41,
    inlined from 'void SignatureIterator::do_parameters_on(T*) [with T = Fingerprinter]' at /home/test/shipilev-jdk/src/hotspot/share/runtime/signature.hpp:629:6,
    inlined from 'void Fingerprinter::compute_fingerprint_and_return_type(bool)' at /home/test/shipilev-jdk/src/hotspot/share/runtime/signature.cpp:169:19:
/usr/include/string.h:102:27: error: 'void* __builtin_memchr(const void*, int, long unsigned int)' specified bound [18446744073709486082, 0] exceeds maximum object size 9223372036854775807 [-Werror=stringop-overread]
  102 |   return __builtin_memchr (__s, __c, __n);
      |          ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
cc1plus: all warnings being treated as errors

As @kimbarrett says: "The warning is indicating an actual problem with the code. The while loop on line 338 may terminate with end == limit if the string consists of just a sequence of '[' and then ends. If the loop ends for that reason, we later read base[limit], invoking UB as limit is the length of base."

Additional testing:

  • Linux x86_64 fastdebug build with GCC 12.1.1
  • Linux x86_64 fastdebug build with GCC 9.4.0

Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8288759: GCC 12 fails to compile signature.cpp due to -Wstringop-overread

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk19 pull/49/head:pull/49
$ git checkout pull/49

Update a local copy of the PR:
$ git checkout pull/49
$ git pull https://git.openjdk.org/jdk19 pull/49/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 49

View PR using the GUI difftool:
$ git pr show -t 49

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk19/pull/49.diff

@bridgekeeper
Copy link

bridgekeeper bot commented Jun 20, 2022

👋 Welcome back shade! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot added the rfr Pull request is ready for review label Jun 20, 2022
@openjdk
Copy link

openjdk bot commented Jun 20, 2022

@shipilev The following label will be automatically applied to this pull request:

  • hotspot

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the hotspot hotspot-dev@openjdk.org label Jun 20, 2022
@mlbridge
Copy link

mlbridge bot commented Jun 20, 2022

Webrevs

@shipilev
Copy link
Member Author

Any takers? :)

Copy link

@coleenp coleenp left a comment

Choose a reason for hiding this comment

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

Seems fine.

@openjdk
Copy link

openjdk bot commented Jun 23, 2022

@shipilev This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8288759: GCC 12 fails to compile signature.cpp due to -Wstringop-overread

Reviewed-by: coleenp

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been no new commits pushed to the master branch. If another commit should be pushed before you perform the /integrate command, your PR will be automatically rebased. If you prefer to avoid any potential automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jun 23, 2022
@shipilev
Copy link
Member Author

Seems fine.

Thanks! @kimbarrett, want to take a look as well?

src/hotspot/share/utilities/compilerWarnings_gcc.hpp Outdated Show resolved Hide resolved
src/hotspot/share/runtime/signature.cpp Outdated Show resolved Hide resolved
@shipilev shipilev changed the title 8288759: GCC 12 fails to compile signature.cpp due to -Wstringop-overread bug 8288759: GCC 12 fails to compile signature.cpp due to -Wstringop-overread Jul 4, 2022
@shipilev
Copy link
Member Author

shipilev commented Jul 4, 2022

@kimbarrett, @coleenp -- I redid the fix to fix the actual warning instead. I opted to return limit on the failure path + assert it does not actually happen in practice. It looks that returning limit is acceptable, as it rolls over to the "end of signature" on error. We can make that fatal() instead, but I don't like to penalize release builds unnecessarily.

Copy link

@kimbarrett kimbarrett left a comment

Choose a reason for hiding this comment

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

The proposed fix seems plausible, and addresses the warning. I was a little worried that someone might come along later and try to change it to just

assert(end < limit, "invalid type");

but presumably that will get the warning again during testing.

I tried to think of a less contrived way to write this while still addressing the warning. I haven't come up with anything better, assuming returning limit is okay.

But I'm entirely unfamiliar with the signature code, so don't know if returning limit is okay. So don't count me as a reviewer for this change (and I won't hit the Approve button).

@shipilev
Copy link
Member Author

shipilev commented Aug 2, 2022

Closed in favor of openjdk/jdk#9711

@shipilev shipilev closed this Aug 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
hotspot hotspot-dev@openjdk.org ready Pull request is ready to be integrated rfr Pull request is ready for review
3 participants