<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - RefactoringTool does not rewrite sources in another directory"
   href="http://llvm.org/bugs/show_bug.cgi?id=22385">22385</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>RefactoringTool does not rewrite sources in another directory
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>3.6
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>libclang
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>tim.besard@elis.ugent.be
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>klimek@google.com, llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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
remove-cstr-calls:
../../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*)
../../lib/Support/Unix/Signals.inc:422:15
#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
../../tools/clang/lib/Tooling/Core/Replacement.cpp:73:28
#10 0x7fc86b351a3e
clang::tooling::applyAllReplacements(std::set<clang::tooling::Replacement,
std::less<clang::tooling::Replacement>,
std::allocator<clang::tooling::Replacement> > const&, clang::Rewriter&)
../../tools/clang/lib/Tooling/Core/Replacement.cpp:234:16
#11 0x7fc86b567898
clang::tooling::RefactoringTool::runAndSave(clang::tooling::FrontendActionFactory*)
../../tools/clang/lib/Tooling/Refactoring.cpp:48:8
#12 0x404eed main
../../tools/clang/tools/extra/remove-cstr-calls/RemoveCStrCalls.cpp:236:10
#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.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>