<div dir="ltr">Okay so the solution was this:<br><font face="courier new, monospace"><br>DeclContext *DC = /*function's decl*/->getDeclContext();</font><div><font face="courier new, monospace">while (DC) {</font></div><div><font face="courier new, monospace"> DC = DC->getPrimaryContext();</font></div><div><font face="courier new, monospace"> for (const Decl *D : DC->decls()) {</font></div><div><font face="courier new, monospace"> const VarDecl *NonLocalVar = dyn_cast<VarDecl>(D);<br> if (!NonLocalVar)</font></div><div><font face="courier new, monospace"> continue;</font></div><div><font face="courier new, monospace"> // whatever</font></div><div><font face="courier new, monospace"> }</font></div><div><font face="courier new, monospace"> DC = DC->getParent();</font></div><div><font face="courier new, monospace">}</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="arial, sans-serif">Thanks for chipping in!</font></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, 21 Jul 2019 at 22:10, Kristóf Umann <<a href="mailto:dkszelethus@gmail.com">dkszelethus@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, 21 Jul 2019 at 20:58, Miklos Vajna <<a href="mailto:vmiklos@vmiklos.hu" target="_blank">vmiklos@vmiklos.hu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi Kristóf,<br>
<br>
On Sun, Jul 21, 2019 at 12:42:34PM +0200, Kristóf Umann via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>> wrote:<br>
> I'm trying to implement a primitive reaching definitions algorithm for C++,<br>
> but am struggling a bit.<br>
<br>
Is this about finding unused data members and functions where the<br>
compiler can't detect them as that requires CTU analysis?<br></blockquote><div><br></div><div>No, not really, I'm trying to find reaching definitions to variables (for example when they caused a division by zero error) to teach the analyzer that certain parts of the program are important, and make it emit bug reports that explain control flow around them better.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
If so, you might want to look at<br>
<<a href="https://cgit.freedesktop.org/libreoffice/core/tree/compilerplugins/clang/unusedmethods.cxx" rel="noreferrer" target="_blank">https://cgit.freedesktop.org/libreoffice/core/tree/compilerplugins/clang/unusedmethods.cxx</a>>,<br>
and other unused* files in the same directory, which use the clang AST<br>
to find unused code; though they don't use AST matchers.<br></blockquote><div><br></div><div>I took a look and I think this isn't what I'm looking for specifically, but thanks for the suggestion! :)</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Regards,<br>
<br>
Miklos<br>
</blockquote></div></div>
</blockquote></div>