Skip to content

8320353: Reenable stringop-overflow warnings #26067

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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

toxaart
Copy link
Contributor

@toxaart toxaart commented Jul 1, 2025

Hi, please consider the following changes:

this PR addresses the issue of stringop-overflow warnings produced by GCC. The compiler does think that the thread pointer returned by JavaThread::current() can be null, though it cant. The thread pointer ends up being an argument in __atomic_load, and the compiler reports the warning related to argument of that method.

The patch adds a hint to the compiler by means of __builtin_unreachable() intrinsic, which tells the compiler that certain piece of code will never be reached (case of thread pointer being null). This solves the issue.

Tested in tiers 1-3 and GHA.


Progress

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

Issue

  • JDK-8320353: Reenable stringop-overflow warnings (Enhancement - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 26067

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/26067.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Jul 1, 2025

👋 Welcome back toxaart! 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
Copy link

openjdk bot commented Jul 1, 2025

@toxaart This change is no longer ready for integration - check the PR body for details.

@openjdk
Copy link

openjdk bot commented Jul 1, 2025

@toxaart The following labels will be automatically applied to this pull request:

  • build
  • graal
  • hotspot

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

@openjdk openjdk bot added graal graal-dev@openjdk.org build build-dev@openjdk.org hotspot hotspot-dev@openjdk.org labels Jul 1, 2025
@toxaart toxaart marked this pull request as ready for review July 1, 2025 15:04
@openjdk openjdk bot added the rfr Pull request is ready for review label Jul 1, 2025
@mlbridge
Copy link

mlbridge bot commented Jul 1, 2025

Webrevs

Copy link
Member

@magicus magicus left a comment

Choose a reason for hiding this comment

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

Build changes look good. Someone else will have to review the hotspot changes.

/reviewers 2

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jul 1, 2025
@openjdk
Copy link

openjdk bot commented Jul 1, 2025

@magicus
The total number of required reviews for this PR (including the jcheck configuration and the last /reviewers command) is now set to 2 (with at least 1 Reviewer, 1 Author).

@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Jul 1, 2025
Copy link
Member

@dholmes-ora dholmes-ora left a comment

Choose a reason for hiding this comment

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

Sorry but I really dislike seeing this compiler-specific pollution in shared code. It is even worse that you have to put it in two places (what is so special about the jvmci code to require this?) just because gcc is "too dumb" keep track of things.

Also IIUC from JBS the problem was only seen building Zero, so maybe we can do something there that is Zero specific?

Sorry.

#if defined(__GNUC__) && !defined(__clang__) && !defined(PRODUCT)
if (thread == nullptr) {
// This is to prevent --stringop-overflow warning from GCC on linux/fastdebug.
// GCC does believe that JavaThread::current() can return nullptr,
Copy link
Member

Choose a reason for hiding this comment

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

does believe -> believes

@@ -1067,7 +1067,16 @@ class JavaThread: public Thread {
public:
// Returns the running thread as a JavaThread
static JavaThread* current() {
return JavaThread::cast(Thread::current());
auto result = JavaThread::cast(Thread::current());
Copy link
Contributor

Choose a reason for hiding this comment

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

Why auto when the type is known?

@TheShermanTanker
Copy link
Contributor

TheShermanTanker commented Jul 2, 2025

A less messy solution could be to use PRAGMA_STRINGOP_OVERFLOW_IGNORED instead. The conditionals for the PRAGMA IGNORED macros are already all handled for you, so there's no need to put conditionalizations at the use sites. As an example, simply do the following:

PRAGMA_DIAG_PUSH
PRAGMA_STRINGOP_OVERFLOW_IGNORED
// Problem code here
PRAGMA_DIAG_POP

The first 2 macros are placed directly in front of the problem code, and the last goes behind.

__builtin_unreachable();
}
#endif
return result;

Choose a reason for hiding this comment

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

Similarly here, I think this could be replaced with asserting non-null.

// therefore 2nd hint is needed.
__builtin_unreachable();
}
#endif

Choose a reason for hiding this comment

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

I think this could be replaced with asserting non-null. A failed assert calls a noreturn reporting
function.

@@ -923,6 +923,17 @@ int CodeInstaller::estimate_stubs_size(HotSpotCompiledCodeStream* stream, JVMCI_
// perform data and call relocation on the CodeBuffer
JVMCI::CodeInstallResult CodeInstaller::initialize_buffer(JVMCIObject compiled_code, CodeBuffer& buffer, HotSpotCompiledCodeStream* stream, u1 code_flags, JVMCI_TRAPS) {
JavaThread* thread = stream->thread();
#if defined(__GNUC__) && !defined(__clang__) && !defined(PRODUCT)

Choose a reason for hiding this comment

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

Note that !PRODUCT does not imply ASSERT. There is also the "optimized" build type, which
defines neither PRODUCT nor ASSERT. I have no idea whether the false-positive gcc warnings
occur in that build configuration. If so, then my suggestion of using an assertion to give the compiler
the clue it needs won't work. But I'm guessing that isn't a problem, in which case the macro check
should be defined(ASSERT).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build build-dev@openjdk.org graal graal-dev@openjdk.org hotspot hotspot-dev@openjdk.org rfr Pull request is ready for review
Development

Successfully merging this pull request may close these issues.

6 participants