[cfe-dev] ASTContext::getParents returning empty list

Kevin Choi via cfe-dev cfe-dev at lists.llvm.org
Tue Oct 23 03:49:21 PDT 2018


Hi clang developers,

I wasn't sure if this was the relevant channel to ask this, and I 
apologize if so.

I've hit a puzzle with an out-of-tree build based on 6.0.0 and was 
wondering if anyone could share their wisdom on it.
ASTContext::getParents seems to be returning an empty list in a 
particular case:
   Run on ArraySubscriptExpr node looking for Stmt parents.

I have four ArraySubscriptExprs in my AST dump, the faulty one being:

|-FunctionDecl 0x6190f58 <line:33:1, line:35:1> line:33:5 used fib 'int 
(int)'$
| |-ParmVarDecl 0x6190ec8 <col:9, col:13> col:13 used n 'int'$
| `-CompoundStmt 0x61915d8 <col:16, line:35:1>$
|   `-ReturnStmt 0x6191518 <line:34:3, col:13>$
|     `-ImplicitCastExpr 0x6191460 <col:10, col:13> 'int' <LValueToRValue>$
|       `-ArraySubscriptExpr 0x6191390 <col:10, col:13> 'int' lvalue$
|         |-ImplicitCastExpr 0x6191220 <col:10> 'int *' 
<ArrayToPointerDecay>$
|         | `-DeclRefExpr 0x6191080 <col:10> 'int [16]' lvalue Var 
0x618c780 'b' 'int [16]'$
|         `-ImplicitCastExpr 0x61912d8 <col:12> 'int' <LValueToRValue>$
|           `-DeclRefExpr 0x6191150 <col:12> 'int' lvalue ParmVar 
0x6190ec8 'n' 'int'$

In this case, getParents returns empty list even though ImplicitCastExpr 
is clearly a parent and is a Stmt. My modification simply calls "const 
auto Parents = getContext().getParents<Stmt>(ERef);" in 
EmitArraySubscriptExpr. Has anyone run into a similar problem before?

Best,

Kevin




More information about the cfe-dev mailing list