Source-to-source code transformation tools built on LLVM LibTooling

Hello everyone,

I am working on a project where I need to generate syntactically different but semantically equivalent C code variants.
My current pipeline already uses compilation and code obfuscation techniques.

However, I am specifically interested in source-to-source transformations (C → transformed C), ideally built on Clang LibTooling.

Before developing my own tool, I would like to know:

Are there existing open-source tools, libraries, or research projects that perform source-to-source transformations using LLVM LibTooling?

I am particularly looking for tools that can:

  • transform code while preserving semantics,

  • rewrite syntax structures (loops, conditionals, expressions, etc.),

  • introduce safe refactorings or controlled mutations,

  • generate multiple different code variants automatically.

Any of the following would be helpful:

  • links to existing tools or libraries,

  • academic projects built on LibTooling doing source-to-source code variant generation,

Even partial tools or research prototypes would be useful.

Thanks in advance for any pointers or recommendations!

Best regards,
Markus

Hi, you can check out clang-tidy tool which has some checks that do code transformations. In particular, modernize-loop-convert transforms index-based loops to range-based.
clang-tidy checks source code can be found in llvm-project/clang-tools-extra/clang-tidy at main · llvm/llvm-project · GitHub, files are named after check name minus it’s category. So implementation of modernize-loop-convert would be in file named llvm-project/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.h at main · llvm/llvm-project · GitHub.

You can also check out transformers library Clang Transformer Tutorial — Clang 22.0.0git documentation, some clang-tidy checks use it.