Add a new builtin to clang with a typeof as a parameter


I am trying to add a new builtin to Clang so I read the following file:


The beginning of this file show some indications about how to define a builtin. However, I’m stuck for defining a generic type for a macro taking a typeof as an argument.

BUILTIN(__builtin_foo, "b?", "n")

How can I define my builtin for a generic type ? (This type can be a structure).

Do you want the type to be a parameter? If yes, you have to modify clang/include/clang/Basic/TokenKinds.def. If you just mean taking any type as an argument, you have to add t to the attribute string and some placeholder for the arguments. The builtins for as_const, forward, move and move_if_noexcept do that, so you can take a look at what they do.

1 Like

Thank you