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

8329826: GCC 12 reports some compiler error when building jdk8 #479

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion hotspot/make/linux/makefiles/adlc.make
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ CXXFLAGS += -DASSERT

# CFLAGS_WARN holds compiler options to suppress/enable warnings.
# Compiler warnings are treated as errors
CFLAGS_WARN = $(WARNINGS_ARE_ERRORS)
CFLAGS_WARN = $(WARNINGS_ARE_ERRORS) -Wno-register
Copy link

@mirabilos mirabilos Apr 16, 2024

Choose a reason for hiding this comment

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

that’s probably okay to ignore

CFLAGS += $(CFLAGS_WARN)

OBJECTNAMES = \
Expand Down
19 changes: 12 additions & 7 deletions hotspot/src/share/vm/opto/type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2552,13 +2552,18 @@ TypeOopPtr::TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, bool xk, ciObject* o, int o
} else if (klass() == ciEnv::current()->Class_klass() &&
_offset >= InstanceMirrorKlass::offset_of_static_fields()) {
// Static fields
assert(o != NULL, "must be constant");
ciInstanceKlass* k = o->as_instance()->java_lang_Class_klass()->as_instance_klass();
ciField* field = k->get_field_by_offset(_offset, true);
assert(field != NULL, "missing field");
BasicType basic_elem_type = field->layout_type();
_is_ptr_to_narrowoop = UseCompressedOops && (basic_elem_type == T_OBJECT ||
basic_elem_type == T_ARRAY);
ciField* field = NULL;
if (o != NULL) {
ciInstanceKlass* k = o->as_instance()->java_lang_Class_klass()->as_instance_klass();
field = k->get_field_by_offset(_offset, true);
}
Copy link

@mirabilos mirabilos Apr 16, 2024

Choose a reason for hiding this comment

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

This is useless papering over, not a fix, and not even good because it makes the code less legible at no gain.

Better to convert the two asserts to actual checks which abort the control flow of the function if triggered.

Copy link
Contributor

Choose a reason for hiding this comment

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

(disclaimer: I am not a reviewer)
This proposed change doesn't really handle the case where o == NULL, although it makes the compiler happy. I propose something like:

assert(o != NULL, "must be constant");
if (o != NULL) {
    ciInstanceKlass* k = o->as_instance()->java_lang_Class_klass()->as_instance_klass();
    ciField* field = k->get_field_by_offset(_offset, true);
    assert(field != NULL, "missing field");
    BasicType basic_elem_type = field->layout_type();
    _is_ptr_to_narrowoop = UseCompressedOops && (basic_elem_type == T_OBJECT ||
                                                 basic_elem_type == T_ARRAY);
 } else {
    _is_ptr_to_narrowoop = (?? I am not familiar enough with this code to put a suggestion here)
}

Choose a reason for hiding this comment

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

No, don’t assert and if something. (The compiler may delete one of these two under Undefined Behaviour rules.)

I’ve not looked at the callers, but returning an error or throwing an exception if o == NULL would be best. Do not rely on assert.

Copy link
Author

Choose a reason for hiding this comment

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

if (field != NULL) {
BasicType basic_elem_type = field->layout_type();
_is_ptr_to_narrowoop = UseCompressedOops && is_reference_type(basic_elem_type);
} else {
// unsafe access
_is_ptr_to_narrowoop = UseCompressedOops;
}
} else {
// Instance fields which contains a compressed oop references.
field = ik->get_field_by_offset(_offset, false);
Expand Down