Statement attributes and TemplateDependent = 1

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Statement attributes and TemplateDependent = 1

Eric Fiselier via cfe-dev
Hi,

I have defined a new attribute (whose subject is the null statement) in
Clang as follows

def MyAttr : StmtAttr {
  let Spellings = [CXX11<"", "my_attr", 201603>];
  let Args = [ExprArgument<"Cond">];
//  let Subjects = [NullStmt];
  let TemplateDependent = 1;
  let Documentation = [Undocumented];
}

Currently, it is correctly parsed and added to the AST.  In fact, the
intended behavior of that attribute also works -as long as it is part
of the body of a non-templated function-.

However, instantiation of the ExprArgument fails for a function
template even if TemplateDependent was set, e.g.

template<typename _T> void foo(_T a) {
  [[my_attr(a > 0)]];
}

generates this (AttributedStmt subtree only).  Please note the `_T'
instead of 'int':'int'.

| | | |-AttributedStmt 0xccb5cc0 <line:12:3, col:20>
| | | | |-MyAttr 0xccb5ca8 <col:5, col:17>
| | | | | `-BinaryOperator 0xccb5c70 <col:12, col:16> '<dependent
type>' '>'
| | | | |   |-DeclRefExpr 0xccb5a70 <col:12> '_T' lvalue ParmVar
0xccb56c0 'a' '_T'
| | | | |   `-IntegerLiteral 0xccb5a98 <col:16> 'int' 0
| | | | `-NullStmt 0xccb5c98 <col:20>

Additionally, I have noted that GNU-style attributes whose subject is a
Funtion -and that contain a ExprArgument-, e.g. `diagnose_if', are
correctly instantiated.

I would appreciate any help or suggestion on where to start looking.
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Statement attributes and TemplateDependent = 1

Eric Fiselier via cfe-dev
On Fri, Oct 20, 2017 at 7:26 AM, Javier López via cfe-dev
<[hidden email]> wrote:

> Hi,
>
> I have defined a new attribute (whose subject is the null statement) in
> Clang as follows
>
> def MyAttr : StmtAttr {
>   let Spellings = [CXX11<"", "my_attr", 201603>];
>   let Args = [ExprArgument<"Cond">];
> //  let Subjects = [NullStmt];
>   let TemplateDependent = 1;
>   let Documentation = [Undocumented];
> }
>
> Currently, it is correctly parsed and added to the AST.  In fact, the
> intended behavior of that attribute also works -as long as it is part
> of the body of a non-templated function-.
>
> However, instantiation of the ExprArgument fails for a function
> template even if TemplateDependent was set, e.g.
>
> template<typename _T> void foo(_T a) {
>   [[my_attr(a > 0)]];
> }
>
> generates this (AttributedStmt subtree only).  Please note the `_T'
> instead of 'int':'int'.
>
> | | | |-AttributedStmt 0xccb5cc0 <line:12:3, col:20>
> | | | | |-MyAttr 0xccb5ca8 <col:5, col:17>
> | | | | | `-BinaryOperator 0xccb5c70 <col:12, col:16> '<dependent
> type>' '>'
> | | | | |   |-DeclRefExpr 0xccb5a70 <col:12> '_T' lvalue ParmVar
> 0xccb56c0 'a' '_T'
> | | | | |   `-IntegerLiteral 0xccb5a98 <col:16> 'int' 0
> | | | | `-NullStmt 0xccb5c98 <col:20>
>
> Additionally, I have noted that GNU-style attributes whose subject is a
> Funtion -and that contain a ExprArgument-, e.g. `diagnose_if', are
> correctly instantiated.
>
> I would appreciate any help or suggestion on where to start looking.

We have never had an attributed statement for which template
dependency matters, so I suspect the issue is that we don't
instantiate statement attributes properly when instantiating
templates. I would guess this means
TemplateInstantiator::TransformAttributedStmt() would be a good place
to start looking.

~Aaron

> _______________________________________________
> cfe-dev mailing list
> [hidden email]
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev