News for hackers. Stuff that matters.
Re:GCC 13 Supports New C2x Features, Including Nullptr, Enha... by kazinator on Monday May 15, 2023 @06:51PM (#35955580)
Hardware memory tagging schemes carefully avoid breaking common C idioms.

What breaks are

- truly dubious programs which use pointers in ways they really shouldn't, and are almost certainly just bugs; like use-after-free. When a pointer with an out-of-date tag is passed to the library, that is pretty much a confirmed use-after-free, which is not a legitimate idiom of non-maximally-portable C, like assuming that all pointers are the same size.

- C programs which manipulate the pointer representation: e.g. run-times for dynamic languages that put their own tags in pointers. These can easily work around tagging. (I've dealt with this on Android recently, quite easily. For the affected objects, I strip the tag away, and work with the untagged pointers. When it's time to pass the pointer back to Android's library, I put the tag back. All other code works as before.

Re:GCC 13 Supports New C2x Features, Including Nullptr, Enha... by pjmlp on Tuesday May 16, 2023 @01:05AM (#35957919)
Yeah, but all of that falls off ISO C defined semantics.
Re:GCC 13 Supports New C2x Features, Including Nullptr, Enha... by mananaysiempre on Tuesday May 16, 2023 @08:03AM (#35960630)
Incidentally, AFAICT C23 now allows stashing log2 alignof(max_align_t) bits in pointers in a portable (if awkward) manner: for example, for a char pointer p, the lowest such bit can be retrieved with memalignment(p)<2 and masked off with p-(memalignment(p)<2).

(C++’s std::aligned would be less awkward, but, well, memalignment() is what we get.)

You still can’t portably store pointers and integers (or doubles) in the same place and distinguish them, though.