Parameters of Custom Attribute are not included in AST

Hi everyone,

I included a C++11 attribute in clang, however I cannot see its integer parameters in the AST.

Example:

int main(){

int i = 0;

int j=1;

[[own::myattr(1,2,3)]]

int a = i + j;
return 0;

}

AST output is:

clang++ test.cpp -std=c++11 -Xclang -ast-dump -fsyntax-only

TranslationUnitDecl 0x894a230 <>
|-TypedefDecl 0x894a770 <> implicit __int128_t ‘__int128’
|-TypedefDecl 0x894a7d0 <> implicit __uint128_t ‘unsigned __int128’
|-TypedefDecl 0x894ab90 <> implicit __builtin_va_list ‘__va_list_tag [1]’
-FunctionDecl 0x894ac30 <hello.cpp:3:1, line:10:1> line:3:5 main 'int (void)'* *-CompoundStmt 0x898e668 <line:4:1, line:10:1>
|-DeclStmt 0x894adb8 <line:5:5, col:14>
| -VarDecl 0x894ad40 <col:5, col:13> col:9 used i 'int' cinit* *| -IntegerLiteral 0x894ad98 col:13 ‘int’ 0
|-DeclStmt 0x894ae58 <line:6:5, col:14>
| -VarDecl 0x894ade0 <col:5, col:13> col:9 used j 'int' cinit* *| -IntegerLiteral 0x894ae38 col:13 ‘int’ 1
|-DeclStmt 0x898e610 <line:8:5, col:18>
| -VarDecl 0x894aee0 <col:5, col:16> col:10 a 'int':'int' cinit* *| |-BinaryOperator 0x898e528 <col:14, col:16> 'int' '+'* *| | |-ImplicitCastExpr 0x898e4f8 <col:14> 'int' <LValueToRValue>* *| | | -DeclRefExpr 0x898e4a8 col:14 ‘int’ lvalue Var 0x894ad40 ‘i’ ‘int’
| | -ImplicitCastExpr 0x898e510 <col:16> 'int' <LValueToRValue>* *| | -DeclRefExpr 0x898e4d0 col:16 ‘int’ lvalue Var 0x894ade0 ‘j’ ‘int’
_| *-OWNMyattrAttr 0x894af40 <line:7:7, col:20>//**__**missing**_ _**parameters 1,2,3**_ *-ReturnStmt 0x898e648 <line:9:5, col:12>
`-IntegerLiteral 0x898e628 col:12 ‘int’ 0

I modified include/clang/Basic/Attr.td like this:

//own::attr

def OWNAttr : Attr {
let Spellings = [CXX11<“own”, “attr”>];
let Args = [VariadicUnsignedArgument<“Args”>];

let Documentation = [Undocumented];
}

Any help?

Regards,
Luis.

Hi everyone,

I included a C++11 attribute in clang, however I cannot see its integer
parameters in the AST.

Example:

int main(){

int i = 0;
int j=1;
[[own::myattr(1,2,3)]]
int a = i + j;
return 0;

}

AST output is:

clang++ test.cpp -std=c++11 -Xclang -ast-dump -fsyntax-only

TranslationUnitDecl 0x894a230 <<invalid sloc>> <invalid sloc>
>-TypedefDecl 0x894a770 <<invalid sloc>> <invalid sloc> implicit __int128_t
'__int128'
>-TypedefDecl 0x894a7d0 <<invalid sloc>> <invalid sloc> implicit __uint128_t
'unsigned __int128'
>-TypedefDecl 0x894ab90 <<invalid sloc>> <invalid sloc> implicit
__builtin_va_list '__va_list_tag [1]'
`-FunctionDecl 0x894ac30 <hello.cpp:3:1, line:10:1> line:3:5 main 'int
(void)'
  `-CompoundStmt 0x898e668 <line:4:1, line:10:1>
    >-DeclStmt 0x894adb8 <line:5:5, col:14>
    > `-VarDecl 0x894ad40 <col:5, col:13> col:9 used i 'int' cinit
    > `-IntegerLiteral 0x894ad98 <col:13> 'int' 0
    >-DeclStmt 0x894ae58 <line:6:5, col:14>
    > `-VarDecl 0x894ade0 <col:5, col:13> col:9 used j 'int' cinit
    > `-IntegerLiteral 0x894ae38 <col:13> 'int' 1
    >-DeclStmt 0x898e610 <line:8:5, col:18>
    > `-VarDecl 0x894aee0 <col:5, col:16> col:10 a 'int':'int' cinit
    > >-BinaryOperator 0x898e528 <col:14, col:16> 'int' '+'
    > > >-ImplicitCastExpr 0x898e4f8 <col:14> 'int' <LValueToRValue>
    > > > `-DeclRefExpr 0x898e4a8 <col:14> 'int' lvalue Var 0x894ad40 'i'
'int'
    > > `-ImplicitCastExpr 0x898e510 <col:16> 'int' <LValueToRValue>
    > > `-DeclRefExpr 0x898e4d0 <col:16> 'int' lvalue Var 0x894ade0 'j'
'int'
    > `-OWNMyattrAttr 0x894af40 <line:7:7, col:20>//missing parameters
1,2,3
    `-ReturnStmt 0x898e648 <line:9:5, col:12>
      `-IntegerLiteral 0x898e628 <col:12> 'int' 0

I modified include/clang/Basic/Attr.td like this:

//own::attr
def OWNAttr : Attr {
  let Spellings = [CXX11<"own", "attr">];
  let Args = [VariadicUnsignedArgument<"Args">];
  let Documentation = [Undocumented];
}

Any help?

When you rerun the table generators for attributes, you should get an
AttrDump.inc file generated that has a switch statement for attr::Kind
enumerators. What does the case look like for your OWNAttr object? It
should look something like:

case attr::NonNull: {
  const NonNullAttr *SA = cast<NonNullAttr>(A);
  for (const auto &Val : SA->args())
    OS << " " << Val;
  break;
}

(This is an example of another attribute using
VariadicUnsignedArgument for its Args.)

~Aaron