Hi David and everyone,

I am playing around with the GCC attribute system, and what I would like
to achieve is something like this:

```c
void foo ( int * [[new_attr]] ptr );
void bar (int * [[new_attr]] ptr )
{
    // function with a definition
}
```

Now, this is working well from the attribute system point of view, but a
weird thing is happening.
When the attribute handler is called by GCC, the DECL_CONTEXT on the
parm_decl tree is not initialized.
I guess this is due to the fact that the attribute are handled very
early in the production of the IR (correct me if I'm wrong).
So what I did is that I stored the parm_decl tree within a
auto_vec<tree> to be able to handle it later, when my code is ran, i.e.,
at the same time than the static analyzer.
Hence, quite late in the GIMPLE pipeline, at least after most of the
optimization have been executed.

Thing is, when I later use the tree stored in the vector, things are
working well with the parm_decl trees linked to function with a
definition (function bar in my previous example) and their DECL_CONTEXT
is properly set to the FUNCTION_DECL corresponding to the expected function.
But not with functions without definition (function foo in my previous
example).
In this specific case, the DECL_CONTEXT of the previously stored
parm_decl is still a NULL_TREE, even after the analyzer is ran.
Any idea why?
Could it be because of the fact that parameters names are not mandatory
for undefined function?

I could (and probably will) get the attribute out of the parameter
declaration, but thing is, I do believe it is easier to read and
understand the purpose of the attribute when it is directly on the
parameter rather that on the function type itself, where you have to
specify the index of the considered attribute (kind of like it is done
with fd_arg* attributes or nonnull attribute).
But still, I don't understand why the parm_decl trees handled during the
handling of the attributes are not properly initialized on function
without body the same way they are with functions with body.

I'd be glad to have any insights to dig that in and understand it.

Thank you for your time,

Pierrick

Reply via email to