CXX11 attribute spelling and LateParsed=1

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

CXX11 attribute spelling and LateParsed=1

Eric Fiselier via cfe-dev
Hi,

I'm new to Clang hacking. Recently -prior to addition of a new attribute-, I tried adding a C++11 spelling of the DiagnoseIf attribute in the file
`tools/clang/include/clang/Basic/Attr.td':

  let Spellings = [GNU<"diagnose_if">,
                   CXX11<"", "diagnose_if", 201603>];

but the parser complains if the expression contains references to
function arguments, even if `LateParsed = 1' is specified, i.e. this
works

  int foo(int arg) __attribute__((diagnose_if(arg == 0, "text",
"warning")));

but this will not:

  [[diagnose_if(arg == 0, "text", "warning")]] int foo(int arg);


Am I missing something? Any help will be much appreciated.

Regards.

--
Javier López
2.2.B.08 ARCOS lab, Computer Architecture Group
University Carlos III of Madrid
e-mail: [hidden email]
_______________________________________________
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: CXX11 attribute spelling and LateParsed=1

Eric Fiselier via cfe-dev
On 6 October 2017 at 07:36, Javier López Gómez via cfe-dev <[hidden email]> wrote:
Hi,

I'm new to Clang hacking. Recently -prior to addition of a new attribute-, I tried adding a C++11 spelling of the DiagnoseIf attribute in the file
`tools/clang/include/clang/Basic/Attr.td':

  let Spellings = [GNU<"diagnose_if">,
                   CXX11<"", "diagnose_if", 201603>];

but the parser complains if the expression contains references to
function arguments, even if `LateParsed = 1' is specified, i.e. this
works

  int foo(int arg) __attribute__((diagnose_if(arg == 0, "text",
"warning")));

but this will not:

  [[diagnose_if(arg == 0, "text", "warning")]] int foo(int arg);


Am I missing something? Any help will be much appreciated.

There is nowhere that a C++11-syntax attribute can be written where it appertains to the function entity and the function parameter names are in scope. The two locations where attributes can be applied to a name introduced by a declarator are:

  [[here]] int f [[and_here]] (int x);

... and neither of them follows the "x" parameter's declaration. After some discussion with Aaron, we think the best way forward is to recast such attributes as attributes on the function *type* (that perhaps don't change the canonical type, but do affect how the function declarator is interpreted as forming a function in some way). That'd mean you'd put the attributes:

  int f(int x) [[here]];

... which conveniently is a place where the function parameters are in scope. The downside is that we don't have parsing support for attributes that appertain to function types yet. That would need to be added.

_______________________________________________
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: CXX11 attribute spelling and LateParsed=1

Eric Fiselier via cfe-dev


On Mon, Oct 9, 2017 at 7:47 PM, Richard Smith via cfe-dev <[hidden email]> wrote:
On 6 October 2017 at 07:36, Javier López Gómez via cfe-dev <[hidden email]> wrote:
Hi,

I'm new to Clang hacking. Recently -prior to addition of a new attribute-, I tried adding a C++11 spelling of the DiagnoseIf attribute in the file
`tools/clang/include/clang/Basic/Attr.td':

  let Spellings = [GNU<"diagnose_if">,
                   CXX11<"", "diagnose_if", 201603>];

but the parser complains if the expression contains references to
function arguments, even if `LateParsed = 1' is specified, i.e. this
works

  int foo(int arg) __attribute__((diagnose_if(arg == 0, "text",
"warning")));

but this will not:

  [[diagnose_if(arg == 0, "text", "warning")]] int foo(int arg);


Am I missing something? Any help will be much appreciated.

There is nowhere that a C++11-syntax attribute can be written where it appertains to the function entity and the function parameter names are in scope. The two locations where attributes can be applied to a name introduced by a declarator are:

  [[here]] int f [[and_here]] (int x);

... and neither of them follows the "x" parameter's declaration. After some discussion with Aaron, we think the best way forward is to recast such attributes as attributes on the function *type* (that perhaps don't change the canonical type, but do affect how the function declarator is interpreted as forming a function in some way). That'd mean you'd put the attributes:

  int f(int x) [[here]];

... which conveniently is a place where the function parameters are in scope. The downside is that we don't have parsing support for attributes that appertain to function types yet. That would need to be added.

I've been working on a fix for this; But if you want to hack on this, I'm happy to yield.
 

_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: CXX11 attribute spelling and LateParsed=1

Eric Fiselier via cfe-dev
El mar, 10-10-2017 a las 22:48 -0600, Eric Fiselier escribió:


On Mon, Oct 9, 2017 at 7:47 PM, Richard Smith via cfe-dev <[hidden email]> wrote:
On 6 October 2017 at 07:36, Javier López Gómez via cfe-dev <[hidden email]> wrote:
Hi,

I'm new to Clang hacking. Recently -prior to addition of a new attribute-, I tried adding a C++11 spelling of the DiagnoseIf attribute in the file
`tools/clang/include/clang/Basic/Attr.td':

  let Spellings = [GNU<"diagnose_if">,
                   CXX11<"", "diagnose_if", 201603>];

but the parser complains if the expression contains references to
function arguments, even if `LateParsed = 1' is specified, i.e. this
works

  int foo(int arg) __attribute__((diagnose_if(arg == 0, "text",
"warning")));

but this will not:

  [[diagnose_if(arg == 0, "text", "warning")]] int foo(int arg);


Am I missing something? Any help will be much appreciated.

There is nowhere that a C++11-syntax attribute can be written where it appertains to the function entity and the function parameter names are in scope. The two locations where attributes can be applied to a name introduced by a declarator are:

  [[here]] int f [[and_here]] (int x);

... and neither of them follows the "x" parameter's declaration. After some discussion with Aaron, we think the best way forward is to recast such attributes as attributes on the function *type* (that perhaps don't change the canonical type, but do affect how the function declarator is interpreted as forming a function in some way). That'd mean you'd put the attributes:

  int f(int x) [[here]];

... which conveniently is a place where the function parameters are in scope. The downside is that we don't have parsing support for attributes that appertain to function types yet. That would need to be added.


I've been working on a fix for this; But if you want to hack on this, I'm happy to yield.

Yes, I will be working on this for the next days. Thanks.
 

_______________________________________________
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