This post describes how to add a custom attribute to LLVM and Clang. Why would you want to do such a thing?
- You have semantic information of which the front-end is aware, but the back-end discards in the Intermediate Representation (IR), and an existing attribute can't be used to retain this information. Adding the attribute using the front-end analysis preserves the information into the back-end generated IR.
- You've considered using the GCC/LLVM
annotate
attribute to hold arbitrary strings, but you also need to add a parameter (or more!) to that annotation.
The Clang Internals Manual discusses how to do this, but not with the detail you might like to see. Its description is high-level, and only lists one file that needs to be modified. Tracking down all of the other files that must be changed is left as a frustrating exercise to the reader.