[cfe-dev] Attributes on statements and expressions
Trevor Harmon
Trevor.W.Harmon at nasa.gov
Fri Apr 23 15:59:08 PDT 2010
Hello Clangers,
Some time ago, there was talk of extending Clang to allow attributes
on statements and expressions [1]. By relaxing the restrictions on
where attributes can be placed, users would be able to attach
arbitrary info to the AST, which would then be transferred to the LLVM
IR (presumably as LLVM 2.7 metadata [2]). Clients of the AST or the
LLVM IR could then use this information to do whatever they want.
The clients would typically be static analysis tools such as:
* Design-by-contract checkers (to declare pre-, post-, and loop
invariants)
* Defect finders like Clang's own Static Analyzer (to eliminate false
positives)
* WCET analyzers (to define loop bounds)
I would like to begin work on a patch that implements this feature in
Clang. The first order of business is to decide how the attributes
would look in the user source code. One approach is to retain the
existing GCC __attribute__ syntax and simply allow the __attribute__
token to appear on statements and expressions. (Currently it is only
allowed on variable, type, and function declarations.) For example:
void myFunc(...) {
__attribute__((loopbound(50))
while (...) {
...
}
}
Any comments or questions on this? I'd also appreciate any tips on how
to get started, as well as admonitions of obstacles I might encounter.
Thanks,
Trevor
[1] http://lists.cs.uiuc.edu/pipermail/cfe-dev/2007-November/000473.html
[2] http://blog.llvm.org/2010/04/extensible-metadata-in-llvm-ir.html
More information about the cfe-dev
mailing list