|
|
Subscribe / Log in / New account

Footguns

Footguns

Posted Jul 11, 2021 16:00 UTC (Sun) by Wol (subscriber, #4433)
In reply to: Footguns by khim
Parent article: Rust for Linux redux

> Yet clang would happily turn it into a function which returns false if you give it some variable which is not initialized.

> This goes so far beyond the abilities of someone to reason about the program it's not funny.

This is the problem with tri-value logic. Look at how SQL handles NULL, for example. By definition, " NULL || !NULL = NULL ".

Although " b || !b " should translate into " known or not known " which one would expect to be true, depending on your definition of "not known", or NULL, or uninitialised ...

Cheers,
Wol


to post comments

Footguns

Posted Jul 11, 2021 16:10 UTC (Sun) by khim (subscriber, #9252) [Link]

> Although " b || !b " should translate into " known or not known " which one would expect to be true, depending on your definition of "not known", or NULL, or uninitialised ...

It's C, not SQL. And valid int doesn't have a value which can lead to this three-way logic (float does, BTW, I wouldn't be much surprised to see the exact same example with floats: (f == 0.0) || (f != 0.0) can be false in a program without any UB).

They had to specifically add said trilogic to the code and introduce special “poison” (the name is telling, isn't it?) value to the set of “normal” int values to achieve that effect.

This doesn't look like a “mere accident” to me, more like an act of sabotage.

P.S. GCC does such optimizations a bit differently. Instead of treating undefined value as special “poison” value with trilogic it just assigns arbitrary value to it and then does the usual constant propagation and other such optimizations. This produces almost the same speedup without making user angry.


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds