You say overflow is undefined. I say it’s defined. As a bonus CPUs say I’m right. The world needs a language that just does what the CPU does. If you don’t want that, don’t program in C.
Conversation
C isn't defined as that language, and you're not in a position where you get to define the language. In the real world, C is deployed with various safety features taking advantage of many things being undefined and reducing portability / compatibility with those wouldn't be good.
2
5
This Tweet was deleted by the Tweet author. Learn more
The Linux kernel chooses to use a superset of standard C. It doesn't ignore the rules that it isn't disabling via those switches but rather is actively tested with ASan and UBSan, with people working to address the cases that are not permitted, usually by fixing the kernel bugs.
2
1
You’re still hung up on a false choice between a well defined spec and instrumentation/tools that alter behavior while giving you something good in return. A defined behavior for C wouldn’t stop those tools from existing.
1
The defined behavior can be trapping, which makes more sense in 2019 with software safety / security / robustness as such important issues. Hardware can and is being designed to make it efficient to catch these issues too. It can also just permit safety without using 'undefined'.
2
1
That definition would make lots of real systems stop working, so that’s clearly the wrong direction for the spec. A good spec respects its customers.
1
2
This Tweet was deleted by the Tweet author. Learn more
It does exist. Existing hardware has lots of safety features in hardware that are being actively used to catch these kinds of issues. More of those features are shipping over time. Intel CET and ARM MTE (which is like the existing SPARC ADI) are major examples of new features.
1
1
There is nothing about Intel CET that requires UB from the language; as I said, the compiler/spec don't have to reveal how function calls work. In my C spec, a load/store would be said to either load/store or trap, depending on how the runtime/CPU did things. So ARM MTE is OK.
1
So, it's okay to trap when indexing from one object to another and then dereferencing, or when constructing a non-derived pointer to an object in any other way and dereferencing it? That's what memory tagging will cause, since it aims to have the tags not match in those cases.
For example, the baseline for malloc is to set random tags for each allocation, along with adjusting them to avoid matching values for adjacent allocations. The compiler can do the same for stack frames (or even variables). Only properly derived pointers will actually work.
1
Show replies
No. Language says that there is no such thing as an object - it's all integer-addressed bytes. Language further acknowledges that virtual memory and trap-on-access exists. It's simple: you just write a spec of reality instead of playing silly games.
1
Okay, so you don't want SPARC ADI and ARM MTE to be used as designed in a standards compliant C implementation which the current C standard permits. It's not playing games. Having at least a weak approximation of memory safety like tagging and various other features is important.
1
1
Show replies

