[cfe-dev] Clang-Rename usage multiple files

Johan Fänge johanfange at gmail.com
Sat Mar 21 12:31:01 PDT 2015


I saw this mail from December and decided to give it a try. Short
investigation below.

Best Regards

Johan Fänge

----------

It does indeed work on the given example after some tweaking, but
breaks down on something slightly more complex.

I added another file:

~/test $ cat foo2.c
#include "foo.h"

int fox (int x, int y, int zz)
{
    return foo(x,x) + foo(y,y) - zz;
}

... and used this invocation: clang-rename foo2.c foo.c main.c
-offset=46 -new-name=sum200 -pn -pl

As you can see below, it also tries to rename zz in foo2.c (which is
at offset 46). What's worse: it overwrites the code following it,
including the parenthesis after the argument list and the comma in the
statement below.



~/test $ clang-rename foo2.c foo.c main.c -offset=46 -new-name=sum200 -pn -pl
clang-rename: could not find symbol at :1:1 (offset 46).
clang-rename: found name: fooclang-rename: renamed at: foo2.c:3:28
clang-rename: renamed at: foo2.c:5:34
clang-rename: renamed at: ./foo.h:1:12
clang-rename: renamed at: foo2.c:5:12
clang-rename: renamed at: foo2.c:5:23
clang-rename: renamed at: foo.c:1:5
clang-rename: renamed at: ./foo.h:1:12
clang-rename: renamed at: main.c:4:12
#include "foo.h"

int fox (int x, int y, int sum200
{
    return sum200(x,x) + sum200(y,y) - sum200
}
int sum200 (int x, int y)
{
    return x + y;
}
#include "foo.h"
int main (void)
{
    return sum200(1, 1);
}


Another example:

~/test $ cat foo2.c
#include "foo.h"

int fox (int x, int y, int zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz)
{
    return foo(x,x) + foo(y,y) - zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz;
}

~/test $ clang-rename foo2.c foo.c main.c -offset=46 -new-name=sum200 -pn -pl
clang-rename: could not find symbol at :1:1 (offset 46).
clang-rename: found name: fooclang-rename: renamed at: foo2.c:3:28
clang-rename: renamed at: foo2.c:5:34
clang-rename: renamed at: ./foo.h:1:12
clang-rename: renamed at: foo2.c:5:12
clang-rename: renamed at: foo2.c:5:23
clang-rename: renamed at: foo.c:1:5
clang-rename: renamed at: ./foo.h:1:12
clang-rename: renamed at: main.c:4:12
#include "foo.h"

int fox (int x, int y, int sum200zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz)
{
    return sum200(x,x) + sum200(y,y) - sum200zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz;
}
int sum200 (int x, int y)
{
    return x + y;
}
#include "foo.h"
int main (void)
{
    return sum200(1, 1);
}


--------

Your command invocation only includes main.c, try adding foo.c as well.

-M

>* On Dec 9, 2014, at 2:27 PM, Dan Walmsley <dan at walms.co.uk <http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev>> wrote:
*> >* Hello,
*> >*     I have managed to compile clang-rename and to get it to
rename some symbols.
*> >* I have simple example I cant get to work correctly if anyone can
help me out it would be greatly appreciated.
*> >* 3 files:
*> >* [foo.c]
*>* int foo (int x, int y)
*>* {
*>*     return x + y;
*>* }
*> >* [foo.h]
*>* extern int foo (int x, int y);
*> >* [main.c]
*>* #include "foo.h"
*>* int main (void)
*>* {
*>*     return foo(1, 1);
*>* }
*> >* [compile_commands.json]
*>* [
*>* {
*>*   "directory": "c:\\ClangRenameTest\\",
*>*   "command": "clang main.c",
*>*   "file": "main.c"
*>* },
*>* {
*>*   "directory": "c:\\ClangRenameTest\\",
*>*   "command": "clang foo.c",
*>*   "file": "foo.c"
*>* }
*>* ]
*> >* I run clang-rename with the following arguments:
*> >* "clang-rename main.c -offset=50 -i -new-name=sum -pl"
*> >* All the instances of foo are renamed to sum except in foo.c.
*> >* Can anyone help me how to get clang-rename to work for foo.c also?
*> >* Any advice is greatly appreciated.
*> >* Dan*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150321/14187a7d/attachment.html>


More information about the cfe-dev mailing list