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

Rafael·Stahl via cfe-dev cfe-dev at lists.llvm.org
Tue Nov 6 00:07:06 PST 2018


Also note that once the parent map has been built, it will not update 
even if the AST changes. Do you maybe call getParents before finalizing 
the AST?

This was an issue for me when using the ASTImporter (Analyzer+CrossTU). 
See https://reviews.llvm.org/D46940

In that review Richard also brought up that it might be better to move 
getParents from the ASTContext to libTooling.

-Rafael


On 05.11.18 17:59, Kevin Choi via cfe-dev wrote:
>
> 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
>>
>
>
> _______________________________________________
> 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/20181106/a1d387f6/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 5449 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20181106/a1d387f6/attachment.bin>


More information about the cfe-dev mailing list