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

Kevin Choi via cfe-dev cfe-dev at lists.llvm.org
Mon Nov 5 08:59:49 PST 2018


I did some digging and it looks like it builds the "Map" on demand, 
storing it in ASTContext (PointerParents, OtherParents). I thought it 
might be a buggy implementation of ParentMapASTVisitor, so I tried 
writing my own ASTVisitor. However, after doing so, both my own and 
ParentMapASTVisitor reported the TranslationUnitDecl traversing only one 
user-defined FunctionDecl and not all of them (there are 4 in my test). 
The root cause appears to be TUDecl missing some of the function decls. 
I think all that needs to repro this is calling 
"getContext().getParents<Stmt>(*E)" inside 
CodeGenFunction::EmitArraySubscriptExpr(). DAE know if there is any 
specific reason why I can't getParents from CGExpr.cpp?

Best,

Kevin


On 2018-10-23 1:21 PM, David Blaikie wrote:
> 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 <mailto: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 <mailto: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/20181105/fee62111/attachment.html>


More information about the cfe-dev mailing list