RefactoringTool - set output file path?

I’m working on a clang tool that instruments source code. However, I can’t seem to find any option to set the output file path, i.e. my tool will always modify the original file, which is not what I want.

Was this a deliberate decision, or am I just missing something?

I’m working on a clang tool that instruments source code. However, I can’t seem to find any option to set the output file path, i.e. my tool will always modify the original file, which is not what I want.

Was this a deliberate decision, or am I just missing something?

If you’re using a refactoring tool, and you chose to call the function to rewrite the original files, that’s a deliberate decision. Otherwise, you can write out the modified files in whatever way you want.
If you’re asking whether there’s library support for writing files to a different directory: no there isn’t. Usually what people want to do is to write the diffs / changes out, instead of the modified files, in that case…

Cheers,
/Manuel

I'm working on a clang tool that instruments source code.

Do you need to instrument the /source code/ in particular? The usual
approach with other instrumentation (sanitizers, code coverage, etc) is
just to instrument the resulting binary (by instrumenting the LLVM IR
generated by the frontend - usually during IR generation in the frontend
(Clang, most often)) rather than mutating the source (or generating a
mutated copy of the source) & then compiling that.

The refactoring tools are really focussed on the scenario of refactoring -
where you actually want to modify the original source. (not that they can't
be used for other things, just that they might not be the best tool for the
job)

Otherwise, you can write out the modified files in whatever way you want.

I cannot find any way to do that, nor the RefactoringTool, nor the Rewriter classes seem to expose any functionality at all to write the modified files anywhere else. How should I go about this (without modifying clang itself)?

Usually what people want to do is to write the diffs / changes out, instead of the modified files, in that case…

I need to specifically write out the modified files.

Do you need to instrument the /source code/ in particular?

Unfortunately, I do, because I work in an environment where we cannot compile using clang, only GCC. The reasons for this are… interesting, at best, but unfortunately this is what I have to work. I agree with you though, IR-level instrumentation is obviously a much better idea… one that’s not feasible in my situation.

Otherwise, you can write out the modified files in whatever way you want.

I cannot find any way to do that, nor the RefactoringTool, nor the Rewriter classes seem to expose any functionality at all to write the modified files anywhere else. How should I go about this (without modifying clang itself)?

Look at
http://reviews.llvm.org/diffusion/L/browse/clang-tools-extra/trunk/clang-rename/tool/ClangRename.cpp;233488$143
The Rewriter basically does everything in-memory. In the end, you can take the buffer, and write it to whereever you like (in clang-rename’s example it writes optionally to stdout)

Thank you very much for your help, that’s indeed what I was looking for!