llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.81k stars 11.91k forks source link

RecursiveASTVisitor does not visit implicit parameters of implicit functions #17646

Open llvmbot opened 11 years ago

llvmbot commented 11 years ago
Bugzilla Link 17272
Version trunk
OS All
Attachments Testcase
Reporter LLVM Bugzilla Contributor
CC @zygoloid,@steveire

Extended Description

Run the attached testcase with:

clang++ -Xclang -load -Xclang ./test-plugin.so -Xclang -add-plugin -Xclang test -o code test.cpp

As you can see from the test-plugin output, the VarParmDecl node for D::f::c is visited twice, while the VarParmDecl node for D::f::c (which is also referenced later in a DeclRefExpr) is never visited. I've also attached the AST dump output, which shows the missing node.

llvmbot commented 11 years ago

I've done a little research, and it seems that this is a little different from bug 16182. In this case, the implicitly instantiated function DOES have TypeSourceInfo, but its TypeLoc is the same for D::f and D::f. I can't tell if this is correct or not. I can work around this issue by ensuring that the first branch (ie. TraverseTypeLoc(TSI->getTypeLoc())) is not taken when D->getTemplateSpecializationKind() == TSK_ImplicitInstantiation, and adding " || || getDerived().shouldVisitTemplateInstantiations()" to the second branch test. I'm not too sure whether the shouldVisit checks for the second branch are necessary because -- correct me if I'm wrong -- if shouldVisit returned false, we wouldn't have traversed an implicit FunctionDecl in the first place?