Re: p = kmalloc(sizeof(*p), )

Linus Torvalds
2005-09-18T22:25:55Z

On Sun, 18 Sep 2005, Al Viro wrote:
>
> BTW, for some idea of how hard does it actually blow

Well, to be slightly more positive: it's not a very easy feature to do
properly.

The thing about "(cast) { .. }" initializers is that they aren't just
initializers: they really are local objects that can be used any way you
want to. So in the _generic_ case, gcc does exactly the right thing: it
introduces a local object that is filled in with the initializer.

So in the generic case, you could have

x = (cast) { ... }.member + 2;

instead of just a straight assignment.

The problem is just that the generic case is semantically pretty damn far
away from the case we actually want to use, ie the special case of an
assignment. So some generic top-level code has created the generic code,
and now the lower levels of the compiler need to "undo" that generic code,
and see what it actually boils down to. And that's quite hard.

The sane thing to do for good code generation would be to special-case the
assignment of this kind of thing, and just make it very obvious that an
assignment of a (cast) {...} is very different from the generic use of
same. But that would introduce two totally different cases for the thing.

So considering that almost nobody does this (certainly not SpecInt), and
it would probably require re-organizations at many levels, I'm not
surprised it hasn't gotten a lot of attention.

Linus