On Tue, 17 May 2022 12:38:55 GMT, Yasumasa Suenaga <ysuen...@openjdk.org> wrote:
>> src/hotspot/share/classfile/classFileParser.cpp line 5970: >> >>> 5968: PRAGMA_STRINGOP_OVERFLOW_IGNORED >>> 5969: _cp->symbol_at_put(hidden_index, _class_name); >>> 5970: PRAGMA_DIAG_POP >> >> I don't understand these warning suppressions for symbol_at_put (here and >> elsewhere). I don't see any stringops here. What is the compiler >> complaining about? (There's no mention of classfile stuff in the review >> cover message.) > > Like the others, it is caused by `Array::at_put()`. > > > In file included from > /home/ysuenaga/github-forked/jdk/src/hotspot/share/oops/annotations.hpp:28, > from > /home/ysuenaga/github-forked/jdk/src/hotspot/share/oops/instanceKlass.hpp:29, > from > /home/ysuenaga/github-forked/jdk/src/hotspot/share/classfile/javaClasses.hpp:30, > from > /home/ysuenaga/github-forked/jdk/src/hotspot/share/precompiled/precompiled.hpp:35: > In member function 'void Array<T>::at_put(int, const T&) [with T = unsigned > char]', > inlined from 'void ConstantPool::tag_at_put(int, jbyte)' at > /home/ysuenaga/github-forked/jdk/src/hotspot/share/oops/constantPool.hpp:126:64, > inlined from 'void ConstantPool::symbol_at_put(int, Symbol*)' at > /home/ysuenaga/github-forked/jdk/src/hotspot/share/oops/constantPool.hpp:362:15, > inlined from 'void > ClassFileParser::mangle_hidden_class_name(InstanceKlass*)' at > /home/ysuenaga/github-forked/jdk/src/hotspot/share/classfile/classFileParser.cpp:5966:21: `Array<T>::_data` is a pseudo flexible array member. "Pseudo" because C++ doesn't have flexible array members. The compiler is completely justified in complaining about the apparently out-of-bounds accesses. There is a "well-known" (though moderately ugly) approach to doing flexible array members in C++. Something like this: T* data() { return reinterpret_cast<T*>( reinterpret_cast<char*>(this) + data_offset()); } where `data_offset()` is new and private: static size_t data_offset() { return offset_of(Array, _data); } Use `data()` everywhere instead of using `_data` directly. There are other places in HotSpot that use this kind of approach. ------------- PR: https://git.openjdk.java.net/jdk/pull/8646