<div dir="ltr"><p dir="ltr" style="font-family:arial,sans-serif;font-size:13px">> There is a helper like getDefiningDecl which will get the second vardecl if you've already parsed it.</p><p style="font-family:arial,sans-serif;font-size:13px">Can you be more specific please? I can't find this helper method in any class.</p><p style="font-family:arial,sans-serif;font-size:13px"><br></p><p style="font-family:arial,sans-serif;font-size:13px">> A redeclaration chain contains all redeclarations, that's the idea, it is a circular singly-linked list.<br>> You should be able to traverse the chain with getFirstDecl(), getMostRecentDecl() and friends from Redeclarable.h.</p><div style="font-family:arial,sans-serif;font-size:13px">I am able to traverse the chain, but if I traverse it inside VisitVarDecl() or TraverseVarDecl(), upon the first VarDecl, the list only contains itself, and uopn the second VarDecl, the list contains both.</div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">The code I used to test is this:</div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style><div style><font face="courier new, monospace"><span class="" style="white-space:pre">      </span>void printSourceRange(SourceRange r) {</font></div><div style><font face="courier new, monospace"><span class="" style="white-space:pre">              </span>llvm::outs()</font></div><div style><font face="courier new, monospace"><span class="" style="white-space:pre">                        </span><< r.getBegin().printToString(ci.getSourceManager())</font></div><div style><font face="courier new, monospace"><span class="" style="white-space:pre">                  </span><< "---"</font></div><div style><font face="courier new, monospace"><span class="" style="white-space:pre">                    </span><< r.getEnd().printToString(ci.getSourceManager());</font></div><div style><font face="courier new, monospace"><span class="" style="white-space:pre">   </span>}</font></div><div style><font face="courier new, monospace"><br></font></div><div style><font face="courier new, monospace"><span class="" style="white-space:pre">   </span>bool TraverseVarDecl(VarDecl *d) {</font></div><div style><font face="courier new, monospace"><span class="" style="white-space:pre">          </span>llvm::outs() << "VarDecl " << d->getName() << " @";</font></div><div style><font face="courier new, monospace"><span class="" style="white-space:pre">                </span>printSourceRange(d->getSourceRange());</font></div><div style><font face="courier new, monospace"><span class="" style="white-space:pre">           </span>llvm::outs() << "\n";</font></div><div style><font face="courier new, monospace"><span class="" style="white-space:pre">               </span>llvm::outs() << "first decl @";</font></div><div style><font face="courier new, monospace"><span class="" style="white-space:pre">             </span>printSourceRange(d->getFirstDecl()->getSourceRange());</font></div><div style><font face="courier new, monospace"><span class="" style="white-space:pre">                </span>llvm::outs() << "\n";</font></div><div style><font face="courier new, monospace"><span class="" style="white-space:pre">               </span>llvm::outs() << "most recent decl @";</font></div><div style><font face="courier new, monospace"><span class="" style="white-space:pre">               </span>printSourceRange(d->getMostRecentDecl()->getSourceRange());</font></div><div style><font face="courier new, monospace"><span class="" style="white-space:pre">           </span>llvm::outs() << "\n";</font></div><div style><font face="courier new, monospace"><span class="" style="white-space:pre">               </span>for(auto r: d->redecls()) {</font></div><div style><font face="courier new, monospace"><span class="" style="white-space:pre">                      </span>llvm::outs() << "redecl " << d->getName() << " @";</font></div><div style><font face="courier new, monospace"><span class="" style="white-space:pre">                 </span>printSourceRange(r->getSourceRange());</font></div><div style><font face="courier new, monospace"><span class="" style="white-space:pre">                   </span>llvm::outs() << "\n";</font></div><div style><font face="courier new, monospace"><span class="" style="white-space:pre">               </span>}</font></div><div style><font face="courier new, monospace"><span class="" style="white-space:pre">           </span>return true;</font></div><div style><span style="font-family:'courier new',monospace;white-space:pre">   </span><span style="font-family:'courier new',monospace">}</span></div><div style><span style="font-family:'courier new',monospace"><br></span></div>Output looks like this:</div><div style><br></div><div style><div><font face="courier new, monospace">VarDecl poop @foo.cpp:2:2---foo.cpp:2:13</font></div><div><font face="courier new, monospace">first decl @foo.cpp:2:2---foo.cpp:2:13</font></div><div><font face="courier new, monospace">most recent decl @foo.cpp:2:2---foo.cpp:2:13</font></div><div><font face="courier new, monospace">redecl poop @foo.cpp:2:2---foo.cpp:2:13</font></div><div><font face="courier new, monospace"><br></font></div><div><div><font face="courier new, monospace">VarDecl poop @foo.cpp:5:1---foo.cpp:5:17</font></div><div><font face="courier new, monospace">first decl @foo.cpp:2:2---foo.cpp:2:13</font></div><div><font face="courier new, monospace">most recent decl @foo.cpp:5:1---foo.cpp:5:17</font></div><div><font face="courier new, monospace">redecl poop @foo.cpp:5:1---foo.cpp:5:17</font></div><div><font face="courier new, monospace">redecl poop @foo.cpp:2:2---foo.cpp:2:13</font></div></div><div><br></div><div>As you can see, the only reference to the VarDecl at foo.cpp:5:1 i get is upon the second call of TraverseVarDecl, and I want to get it at the first call.</div><div><br></div><div>Am I misunderstanding something, or doing something wrong? It looks like the two VarDecls have two different lists of redeclarations, which do not correspond.</div><div><br></div><div>Thanks.</div></div></div>