[cfe-dev] -rewrite-objc and typeof (Was: -rewrite-objc, C and blocks)

Pierre Habouzit madcoder at madism.org
Fri Oct 1 13:42:06 PDT 2010


While I'm at it, the objc rewriter tries hard to rewrite typeof() for a
reason that eludes me.  Given that typeof() is often used inside macros,
and that rewriting inside macros may not work (that I can understand
;p), this is really painful.

So could someone explain why the RewriteObjC::RewriteTypeOfDecl()
function is needed at all so that I can work on a fix or at least a
relaxed rule (for example, I assume that the problem arises if the
type of the expression inside typeof really is some block type or some
variable with a __block storage ? or something block related at least,
so probably the fix is to check if the type is something of that kind,
right ?)

The use case is code using stuff like:

    #define shared_write(p, v)  ({ typeof(v) __v = (v); \
				   access_once(p) = __v; wmc(); __v; })

clang -rewrite-objc yields tons of warnings like:

    thr-job.c:198:5: warning: rewriting sub-expression within a macro (may not be correct)
	shared_write(self_g.bot_, new_bot);
	^
    [...]
    ../lib-common/core-atomic-x86.h:80:32: note: instantiated from:
    #define shared_write(p, v)  ({ typeof(v) __v = (v); \
				   ^

Given that in the previous code self_g.bot is an unsigned, I really fail
to see why clang believes it has to rewrite the typeof() expression at
all.
-- 
·O·  Pierre Habouzit
··O                                                madcoder at debian.org
OOO                                                http://www.madism.org



More information about the cfe-dev mailing list