bug in the Rewriter

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=&amp;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 :slight_smile: 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

Possibly the same bug as http://llvm.org/bugs/show_bug.cgi?id=2386?

-Eli

Ah yes, thanks. I somehow missed that bug report..
At least one can find a simple solution in my previous e-mail (that breaks the obj rewriter though..).

Nuno

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.

note that the '&' char is escaped in the wrong place.

Possibly the same bug as 2386 – erraneous html with -emit-html?

Ah yes, thanks. I somehow missed that bug report..
At least one can find a simple solution in my previous e-mail (that breaks
the obj rewriter though..).

Hey Nuno,

I'll take a look at this sometime this week...

snaroff

I think it is a “low-level” bug in the Rewriter itself (not the ObjC rewriter in Driver).