Question

In a program using libtooling, is there a way to make some types recognized as "built-in type" ? For example, I'd like to make int16_t, uint32_t etc. recognized as canonical built-in types rather than it's typedef to short, unsigned etc.

Was it helpful?

Solution

If you have a look at ".../llvm/tools/clang/include/clang/AST/BuiltinTypes.def", then that would declare the builtin types like int and long long. It's not entirely straight forward tho'. You will need to modify quite a bit of code, for example there are portions of type definitions in ".../llvm/tools/clang/lib/Sema/Sema.cpp" and ".../llvm/tools/clang/lib/AST/Type.cpp". If you grep for Int128 (good choice as clang itself doesn't use that [much] in itself, as opposed to for example size_t), you will see that it turns up in a lot of places. You'd have to cover all (or at least most) of those places with additional code to introduce new types of your own making.

I would say that it's probably much easier to do something like clang -include cstdint myprog.cpp. In other words, make sure that the #include <cstdint> [or your own version of the same kind of file] is done behind the scenes in the compiler - you could add this to your driver in your own code too.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top