I have questions about function parameter attributes. I'm trying to use
attributes to indicate parameters that are used to pass values back out
of functions and then analyze how they are used. I tried something like
this:
void foo(int *a __attribute__((user("out"))));
By itself, this works (in GCC 4.3, used for all tests discussed here):
in GIMPLE, call sites for foo refer to a FUNCTION_DECL node that has a
PARM_DECL for a with the the user "out" attribute.
But if a function definition is visible, this changes. With this:
void foo(int *a) {}
at all sites, the FUNCTION_DECL's PARM_DECL has no attributes.
I tried various tests, with multiple declarations and having definitions
or not, and the results seem to be:
- If there is a definition present, parameter attributes are taken from
the definition.
- If there is no definition in the file, parameter attributes are taken
from the first declaration.
I'd appreciate any help someone can give me with:
Q1: Is this behavior intended?
Q2: When there is a definition and a declaration, does GCC keep around
both sets of attributes? If so, where are they found?
Q3: If not, what's the best way to represent this information with
attributes? The same way as nonnull?
--
Dave Mandelin
Mozilla Platform Engineer