[Vm-dev] [OpenSmalltalk/opensmalltalk-vm] Undefined evaluation order in C generated code (in primitiveSetOrHasIdentityHash) (#596)

Nicolas Cellier notifications at github.com
Fri Sep 17 11:14:13 UTC 2021


currently, primitiveSetOrHasIdentityHash generates this code:

    ((((hash = (hash >> 3))) & (identityHashHalfWordMask())) == hash))

This effectively generates a warning:

> ../../../src/spur64.cog/gcc3x-cointerp.c:35911:16: warning: unsequenced modification and access to 'hash' [-Wunsequenced]
>                  && ((((hash = (hash >> 3))) & (identityHashHalfWordMask())) == hash))) {
>                              ^        

Indeed, C does not guaranty any evaluation order for this kind of expression, so we can expect undefined (incorrect) behaviour, depending on compiler's choice.

Though, in Smalltalk, evaluation order is well defined for the slang source expression:

    ((hash := objectMemory integerValueOf: hash) bitAnd: objectMemory maxIdentityHash) = hash

Either we consider that it is a bug of CCodeGenerator.
Or we consider that it's a limitation of slang that VM programmer should be aware of and should care of.

In all case, we must pay attention to this kind of warning at C compilation time.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/596
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/vm-dev/attachments/20210917/f5aac2a1/attachment.html>


More information about the Vm-dev mailing list