[cfe-dev] hasAncestor matching nothing

Farzad Sadeghi via cfe-dev cfe-dev at lists.llvm.org
Fri Nov 25 00:24:24 PST 2016


for the source code below:
short int test16(int a, int b)
{
	short int sum;
	short unsigned int sumus;
	sum = a + b;
	sumus = a + b;

	return sum;
}
with AST:
|-FunctionDecl 0x4e52920 <line:821:1, line:829:1> line:821:11 test16
'short (int, int)'
| |-ParmVarDecl 0x4e527d8 <col:18, col:22> col:22 used a 'int'
| |-ParmVarDecl 0x4e52848 <col:25, col:29> col:29 used b 'int'
| `-CompoundStmt 0x4e52d60 <line:822:1, line:829:1>
|   |-DeclStmt 0x4e52a48 <line:823:2, col:15>
|   | `-VarDecl 0x4e529e8 <col:2, col:12> col:12 used sum 'short'
|   |-DeclStmt 0x4e52ad0 <line:824:2, col:26>
|   | `-VarDecl 0x4e52a70 <col:2, col:21> col:21 used sumus 'unsigned short'
|   |-BinaryOperator 0x4e52bd0 <line:825:2, col:12> 'short' '='
|   | |-DeclRefExpr 0x4e52ae8 <col:2> 'short' lvalue Var 0x4e529e8 'sum' 'short'
|   | `-ImplicitCastExpr 0x4e52bb8 <col:8, col:12> 'short' <IntegralCast>
|   |   `-BinaryOperator 0x4e52b90 <col:8, col:12> 'int' '+'
|   |     |-ImplicitCastExpr 0x4e52b60 <col:8> 'int' <LValueToRValue>
|   |     | `-DeclRefExpr 0x4e52b10 <col:8> 'int' lvalue ParmVar
0x4e527d8 'a' 'int'
|   |     `-ImplicitCastExpr 0x4e52b78 <col:12> 'int' <LValueToRValue>
|   |       `-DeclRefExpr 0x4e52b38 <col:12> 'int' lvalue ParmVar
0x4e52848 'b' 'int'
|   |-BinaryOperator 0x4e52ce0 <line:826:2, col:14> 'unsigned short' '='
|   | |-DeclRefExpr 0x4e52bf8 <col:2> 'unsigned short' lvalue Var
0x4e52a70 'sumus' 'unsigned short'
|   | `-ImplicitCastExpr 0x4e52cc8 <col:10, col:14> 'unsigned short'
<IntegralCast>
|   |   `-BinaryOperator 0x4e52ca0 <col:10, col:14> 'int' '+'
|   |     |-ImplicitCastExpr 0x4e52c70 <col:10> 'int' <LValueToRValue>
|   |     | `-DeclRefExpr 0x4e52c20 <col:10> 'int' lvalue ParmVar
0x4e527d8 'a' 'int'
|   |     `-ImplicitCastExpr 0x4e52c88 <col:14> 'int' <LValueToRValue>
|   |       `-DeclRefExpr 0x4e52c48 <col:14> 'int' lvalue ParmVar
0x4e52848 'b' 'int'
|   `-ReturnStmt 0x4e52d48 <line:828:2, col:9>
|     `-ImplicitCastExpr 0x4e52d30 <col:9> 'short' <LValueToRValue>
|       `-DeclRefExpr 0x4e52d08 <col:9> 'short' lvalue Var 0x4e529e8
'sum' 'short'
when i run the below matcher on clang-query:
match declRefExpr(hasAncestor(declRefExpr()))
i get no matches, while in the AST it clearly says that there are such
nodes. so I was wondering what could be causing this.

-- 
Farzad Sadeghi



More information about the cfe-dev mailing list