Undefined behaviour in hotspot

Volker Simonis volker.simonis at gmail.com
Tue Apr 22 08:41:47 UTC 2014


Hi,

I think the simplest and safest fix would be to make encoding() (and
all the corresponding functions) static functions which take a
Register as argument like:

static int encoding(const RegisterImpl* r) { assert(is_valid(r),
"invalid register"); return (intptr_t)r; }

This wouldn't waste any more memory and it would be fully C++
compliant at the price of a slightly more verbose usage:

2577    void Assembler::push(Register src) {
2578      int encode = prefix_and_encode(RegisterImpl::encoding(src));
2579

And of course this would work with any compiler.

What do you think?

Regards,
Volker


On Mon, Apr 21, 2014 at 8:30 PM, Omair Majid <omajid at redhat.com> wrote:
> * David Chase <david.r.chase at oracle.com> [2014-04-21 13:53]:
>>
>> On 2014-04-21, at 12:17 PM, Omair Majid <omajid at redhat.com> wrote:
>> > I can ping them, but honestly, I wouldn't be surprised at all if the
>> > only response I get is "no". I don't have any official communication
>> > channels with them, so my input is not any different from anyone else's.
>> >
>> > Can you elaborate on what flag/pragma you have in mind? Just something
>> > to play nice with NULL pointers?
>>
>> Not just null pointers.  Also optimizations that pretend that integer overflow
>> doesn't happen (i.e., optimizations that change program behavior when it
>> does) also need to be disabled.
>
> My knowledge of C/C++ is fairly limited, so please bear with me. There
> are a few relevant options already listed in 'man gcc':
>
> -Wstrict-overflow=n
>            This option is only active when -fstrict-overflow is active.
>            It warns about cases where the compiler optimizes based on
>            the assumption that signed overflow does not occur
>
> -fwrapv
>            This option instructs the compiler to assume that signed
>            arithmetic overflow of addition, subtraction and
>            multiplication wraps around using twos-complement
>            representation.
>
> Do you mean others?
>
> Thanks,
> Omair
>
> --
> PGP Key: 66484681 (http://pgp.mit.edu/)
> Fingerprint = F072 555B 0A17 3957 4E95  0056 F286 F14F 6648 4681


More information about the hotspot-dev mailing list