This is a *work in progress* patch illustrating how an optimization remark that prints out derived function/argument attributes could be implemented.
Such remarks would be useful both for developers and end users to debug programs, either learning that an expected attribute was learned, or an unexpected attribute was learned (for example a pointer never being written to).
This is in preparation for the creation of a RFC, not intending to go in at the moment.
Evidently the following might not be the final interface, but one could imagine something like the following:
$ ./clang foobar.c -g -Rannotations -O3 foobar.c:2:1: remark: derived following attributes for function f: fn_attr("norecurse") fn_attr("nounwind") fn_attr("readonly") arg_attr(0, "nocapture") arg_attr(0, "readonly") [-Rannotations] double f(double* a) { foobar.c: double f(double* a) { return a[0]; }
This diff also includes possible frontend changes to be able to parse the arguments when added to functions
__attribute__(( fn_attr("readonly") )) double g(double* a) { return h(a); }