[LLVMbugs] [Bug 22385] New: RefactoringTool does not rewrite sources in another directory

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu Jan 29 06:09:57 PST 2015


            Bug ID: 22385
           Summary: RefactoringTool does not rewrite sources in another
           Product: clang
           Version: 3.6
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: libclang
          Assignee: unassignedclangbugs at nondot.org
          Reporter: tim.besard at elis.ugent.be
                CC: klimek at google.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified

If I use the RefactoringTool to match and rewrite files which reside in a
subdirectory, matching works fine, but Rewriting fails because the sources are
not found anymore (the directory component is stripped off).

For example, demonstrating using remove-cstr-calls from clang-tools-extra, if I
have a file main.cpp in /tmp/test/src, and an accompanying
compile_database.json (in the same directory) looking as follows:
        "command": "g++ -c -o main.o main.cpp",
        "directory": "/tmp/test/src",
        "file": "/tmp/test/src/main.cpp"
(this compile database is generated using Bear)

If I now call the tooling binary from /tmp/test using `remove-cstr-calls src
src/main.cpp`, I get:

fatal error: cannot open file 'main.cpp': No such file or directory
../../tools/clang/include/clang/Rewrite/Core/RewriteRope.h:203: void
clang::RewriteRope::erase(unsigned int, unsigned int): Assertion
`Offset+NumBytes <= size() && "Invalid region to erase!"' failed.
#0 0x7fc86c9a9c48 llvm::sys::PrintStackTrace(_IO_FILE*)
#1 0x7fc86c9ab24b SignalHandler(int) ../../lib/Support/Unix/Signals.inc:198:28
#2 0x7fc86a7b4b20 __restore_rt (/usr/lib/libc.so.6+0x33b20)
#3 0x7fc86a7b4a97 __GI_raise (/usr/lib/libc.so.6+0x33a97)
#4 0x7fc86a7b5e6a __GI_abort (/usr/lib/libc.so.6+0x34e6a)
#5 0x7fc86a7ad8bd __assert_fail_base (/usr/lib/libc.so.6+0x2c8bd)
#6 0x7fc86a7ad972 (/usr/lib/libc.so.6+0x2c972)
#7 0x7fc86798f7ce (bin/../lib/../lib/libclangRewrite.so+0x87ce)
#8 0x7fc867990788 clang::Rewriter::ReplaceText(clang::SourceLocation, unsigned
int, llvm::StringRef) ../../tools/clang/lib/Rewrite/Rewriter.cpp:311:3
#9 0x7fc86b35105d clang::tooling::Replacement::apply(clang::Rewriter&) const
#10 0x7fc86b351a3e
std::allocator<clang::tooling::Replacement> > const&, clang::Rewriter&)
#11 0x7fc86b567898
#12 0x404eed main
#13 0x7fc86a7a1040 __libc_start_main (/usr/lib/libc.so.6+0x20040)
#14 0x402f78 _start (bin/remove-cstr-calls+0x402f78)
Aborted (core dumped)

If I call the binary from /tmp/test/src (the directory where main.cpp resides)
using `remove-cstr-calls . main.cpp`, everything works fine and the file is
properly rewritten.

I'm using LLVM/Clang from the 3.6 branch, at revision 227398.

You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20150129/f976deb8/attachment.html>

More information about the llvm-bugs mailing list