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

Build error: "statement has no effect" with J9CLASS_DEPTH() in java_lang_invoke_MethodHandleNatives.cpp #20170

Closed
knn-k opened this issue Sep 17, 2024 · 5 comments · Fixed by #20173

Comments

@knn-k
Copy link
Contributor

knn-k commented Sep 17, 2024

Building OpenJ9 Java 17 with GCC 13.2.0 on Ubuntu 24.04.1 generates the following error:

/home/openj9/openj9-openjdk-jdk17/openj9/runtime/jcl/common/java_lang_invoke_MethodHandleNatives.cpp: In function 'j
int Java_java_lang_invoke_MethodHandleNatives_getMembers(JNIEnv*, jclass, jclass, jstring, jstring, jint, jclass, jint,
jobjectArray)':
/home/openj9/openj9-openjdk-jdk17/openj9/runtime/oti/j9class.h:35:68: error: statement has no effect [-Werror=unused-value]
   35 | #define J9CLASS_DEPTH(clazz) (((UDATA)(clazz)->classDepthAndFlags) & J9AccClassDepthMask)
      |                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
/home/openj9/openj9-openjdk-jdk17/openj9/runtime/jcl/common/java_lang_invoke_MethodHandleNatives.cpp:1466:49: note: in expansion of macro 'J9CLASS_DEPTH'
 1466 |                                                 J9CLASS_DEPTH(defClass);
      |                                                 ^~~~~~~~~~~~~
/home/openj9/openj9-openjdk-jdk17/openj9/runtime/oti/j9class.h:35:68: error: statement has no effect [-Werror=unused-value]
   35 | #define J9CLASS_DEPTH(clazz) (((UDATA)(clazz)->classDepthAndFlags) & J9AccClassDepthMask)
      |                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
/home/openj9/openj9-openjdk-jdk17/openj9/runtime/jcl/common/java_lang_invoke_MethodHandleNatives.cpp:1571:49: note: in expansion of macro 'J9CLASS_DEPTH'
 1571 |                                                 J9CLASS_DEPTH(defClass);
      |                                                 ^~~~~~~~~~~~~

$ gcc --version
gcc (Ubuntu 13.2.0-23ubuntu4) 13.2.0

UDATA classDepth = 0;
if (J9_ARE_ANY_BITS_SET(matchFlags, MN_SEARCH_SUPERCLASSES)) {
/* walk superclasses */
J9CLASS_DEPTH(defClass);
}

UDATA classDepth = 0;
if (J9_ARE_ANY_BITS_SET(matchFlags, MN_SEARCH_SUPERCLASSES)) {
/* walk superclasses */
J9CLASS_DEPTH(defClass);
}

@knn-k
Copy link
Contributor Author

knn-k commented Sep 17, 2024

The results of J9CLASS_DEPTH(defClass) are not used at all in these places.
I guess these lines should be changed to classDepth = J9CLASS_DEPTH(defClass), but I am not sure.

@knn-k
Copy link
Contributor Author

knn-k commented Sep 17, 2024

Another build error with GCC 13.2.0: #20171

@knn-k
Copy link
Contributor Author

knn-k commented Sep 17, 2024

The following part is never executed because classDepth is unchanged after initialized by 0 at L.1463.

classDepth -= 1;
currentClass = defClass->superclasses[classDepth];

It is the same for L.1626-1627.

@knn-k
Copy link
Contributor Author

knn-k commented Sep 17, 2024

I opened a draft PR: #20173

@keithc-ca
Copy link
Contributor

The following part is never executed because classDepth is unchanged after initialized by 0 at L.1463.

classDepth -= 1;
currentClass = defClass->superclasses[classDepth];

It is the same for L.1626-1627.

I think that is just a bug. However, it will only affect Java 17. Earlier versions do not use OpenJDK method handles (J9VM_OPT_OPENJDK_METHODHANDLE) by default, and later versions don't have that native method.

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

Successfully merging a pull request may close this issue.

2 participants