RFR: 8263718: unused-result warning happens at os_linux.cpp

Stefan Karlsson stefank at openjdk.java.net
Wed Mar 17 10:20:49 UTC 2021


On Wed, 17 Mar 2021 09:26:33 GMT, Yasumasa Suenaga <ysuenaga at openjdk.org> wrote:

>> I tried to build OpenJDK with g++-10.2.1_pre1-r3 on Alpine Linux 3.13.2, but I saw following warning:
>> 
>> 
>>   668 | alloca(((pid ^ counter++) & 7) * 128);
>>       | ^
>> cc1plus: all warnings being treated as errors
>
>> First I have to wonder whether that alloca actually serves any useful
>> purpose in this day and age? I wonder what was used to measure the
>> performance difference... I'll see what I can find out.
> 
> I also thought we can remove it, but I could not find any reason to do so.
> 
>> But second, will doing:
>> 
>> void* padding = alloca(...);
>> 
>> not suffice to suppress the warning, or will the compiler then complain
>> about "padding" being unused?
>> 
>> The pragma no doubt works, but is a bit ugly. :)
> 
> Yes, the warning was gone with `void* padding =`, but I don't want to do so because GCC has [-Wunused-variable](https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html). GCC might report the warning in future.

Isn't the standard way to silence these kind of problem to cast the result to (void):
(void)alloca(((pid ^ counter++) & 7) * 128);

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

PR: https://git.openjdk.java.net/jdk/pull/3042


More information about the hotspot-dev mailing list