[cfe-dev] [cfe-commits] r100942 - /cfe/trunk/lib/CodeGen/CGObjC.cpp

David Chisnall csdavec at swan.ac.uk
Sat Apr 10 13:03:10 PDT 2010

On 10 Apr 2010, at 20:39, Chris Lattner wrote:

> To me, this is a very similar cousin to "cast of super" which we explicitly disallow.
> The big issue here is that from a language perspective, "super" is not an expression at all.  It is a magic token that is only valid in a message send.  Things like super->ivar *should* be disallowed, as should "id x = super" and many other things that we probably accidentally allow.

Currently, super->ivar is disallowed, so is id x = super.  These are accepted by GCC, although that's probably not sensible.

> I think that the big AST change to model this correctly is really important, because it will fix a number of other problems and cases where Sema probably accidentally accepts invalid code (what about foo(super), passing it as an argument)?  This is not about a single special case, this is about the design always being broken and wanting to fix the root problem.

Sema allows foo(super), but it stops in CodeGen.  This is probably worth fixing, but I'm not entirely convinced by your proposed solution.  

This is accepted by GCC, although it generates a spurious warning about incompatible pointer types.  

> Just "leaving it in" will make clang accept illegal code - weaning the invalid code off their constructs is going to be more difficult in the future than it is now.  Since clang has never accepted this, we just continue rejecting it.

The change doesn't make it accept illegal code, it will make it accept legal code.  The following absolutely should be legal:

[(super) foo];

While you would never write this directly, it is relatively common as a result of macro expansion, when a macro is used to optionally remove message sends.  Consider a macro like this:

#define LOG(x) [(x) log]
#define LOG(x) 

The brackets are in the macro, but when you call it like this, gcc accepts it and clang rejects it:


If you make a message send to super a flag in the AST, then how would you represent [(super) foo] or [((super)) foo] in the AST?  Would they be the same as [super foo]?  How would this effect AST consumers other than CodeGen?  


-- Sent from my PDP-11

More information about the cfe-dev mailing list