[cfe-dev] bug in the Rewriter

Nuno Lopes nunoplopes at sapo.pt
Wed Sep 24 11:47:00 PDT 2008


Hi,

Today I've tracked down a bug in the Rewriter, but I'm not sure how to fix 
it. I'll try to explain what's happening.
The problem happens when running the analyzer and when it flags an error in 
a token that starts with a char that needs escaping.
e.g.:
char *arg_free=NULL, **arg_excp=&arg_free;

gets translated to:
<tr><td class="num"></td><td class="line"><div id="EndPath" class="msg" 
style="margin-left:32ex">warning: Value stored to 'arg_excp' during its 
initialization is never read</div></td></tr>
<tr><td class="num" id="LN596">596</td><td class="line">        <span 
class='keyword'>char</span> *arg_free=<span class='macro'>NULL<span 
class='expansion'>( ( void * ) 0 )</span></span>, **arg_excp=&span 
class="mrange">&arg_free</span>;</td></tr>

note that the '&' char is escaped in the wrong place. This is because 
ReplaceText() searches for the offset with AfterInserts=false, which is 
wrong because we may have several replacements at the same original offset 
(as in this case). Turning it to true fixes the problem.

But wait, that would be too easy :) Then there's one objc rewrite test that 
starts failing. Why? because it rewrites both the AST tree and the output 
several times and the new tree nodes keep the original offsets. So the objc 
rewriter really wants to search for the offsets with AfterInserts=false.

e.g.:
    while (mapTable->capacity) {

1st it is translated to:
    while (((struct NSConcreteMapTableValueEnumerator_IMPL 
*)self)->mapTable->capacity) {

and then to:
    while (((struct NSConcreteMapTableValueEnumerator_IMPL *)self)->((struct 
NSConcreteMapTable_IMPL *)((struct NSConcreteMapTableValueEnumerator_IMPL 
*)self)->mapTable)->capacity) {

instead of
    while (((struct NSConcreteMapTable_IMPL *)((struct 
NSConcreteMapTableValueEnumerator_IMPL *)self)->mapTable)->capacity) {


Anyone with a better insight than me can please either fix the problem or 
give me some clue on how to fix it?

Thanks,
Nuno 




More information about the cfe-dev mailing list