lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


To further emphasize your point: since subtracting unrelated pointers
is Undefined Behavior, even on such a hypothetical architecture,
compilers would still be allowed to perform this optimization. The
comment that "the subsequent checks are ISO C and ensure a correct
result" is wrong. If isinstack is ever called where o and base are
unrelated, the entire execution is undefined.

Joseph C. Sible


On Mon, Feb 22, 2021 at 12:45 AM Andrew Gierth
<andrew@tao11.riddles.org.uk> wrote:
>
> >>>>> "Yongheng" == Yongheng Chen <changochen1@gmail.com> writes:
>
>  >> that condition looks a lot like "base + o - base == o" to me.
>
>  Yongheng> I think you are correct. Then this check seems useless in
>  Yongheng> normal situation?
>
> The check seems like a misguided attempt to make up for the potential
> undefined behavior of the prior pointer subtraction. i.e. it supposes
> that on some hypothetical architecture (perhaps a segmented one), the
> subtraction of two unrelated pointers might produce a value that when
> added back to "base" does not recreate the original value.
>
> (In fact, just performing the subtraction in cases like that is
> undefined behavior, so there is no guarantee at all about what happens.)
>
> --
> Andrew.