[jdk19] RFR: 8288759: GCC 12 fails to compile signature.cpp due to -Wstringop-overread

Aleksey Shipilev shade at openjdk.org
Mon Jul 4 11:50:30 UTC 2022


On Sat, 25 Jun 2022 08:33:22 GMT, Kim Barrett <kbarrett at openjdk.org> wrote:

>> 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:
>
> src/hotspot/share/runtime/signature.cpp line 328:
> 
>> 326: 
>> 327: PRAGMA_DIAG_PUSH
>> 328: PRAGMA_STRINGOP_OVERREAD_IGNORED
> 
> Don't make this change.  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.  As a proof of concept, adding
> 
> if (end >= limit) return limit;
> 
> after the while loop makes the warning go away.  I have no idea what the correct thing to do for this might be.  Returning limit might be wrong; I just used that to verify this issue is the source of the warning.

You're right, this is a legit warning. I see other code in `signature.cpp` that handles `JVM_SIGNATURE_ARRAY` scans and checks whether we ended up scanning the string completely. We should do the same here. Let me see...

-------------

PR: https://git.openjdk.org/jdk19/pull/49


More information about the hotspot-dev mailing list