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

David Blaikie via cfe-dev cfe-dev at lists.llvm.org
Tue Oct 23 10:21:57 PDT 2018


I believe the parent map that powers getParents is not populated by default
(it's not used by Clang proper - so it doesn't want to pay that cost) - not
sure where/when/how you call to populate it - but hopefully that gives you
some hints for what to look for.

On Tue, Oct 23, 2018 at 3:49 AM Kevin Choi via cfe-dev <
cfe-dev at lists.llvm.org> wrote:

> 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
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20181023/644a3822/attachment.html>


More information about the cfe-dev mailing list