Open Quuxplusone opened 12 years ago
Bugzilla Link | PR13618 |
Status | NEW |
Importance | P normal |
Reported by | Sergejs (sergejs.belajevs@gmail.com) |
Reported on | 2012-08-16 09:29:48 -0700 |
Last modified on | 2012-08-17 16:28:17 -0700 |
Version | trunk |
Hardware | PC Windows NT |
CC | klimek@google.com, llvm-bugs@lists.llvm.org, philipjcraig@gmail.com, richard-llvm@metafoo.co.uk |
Fixed by commit(s) | |
Attachments | |
Blocks | |
Blocked by | |
See also |
Here's a version of your visitor that can traverse the anonymous union:
class MyVisitor : public clang::RecursiveASTVisitor<MyVisitor>
{
typedef RecursiveASTVisitor<MyVisitor> VisitorBase;
public:
MyVisitor() {}
bool VisitTypeOfExprType(clang::TypeOfExprType* t)
{
printf("Visiting typeof expr type!\n");
return true;
}
bool TraverseCompoundLiteralExpr(CompoundLiteralExpr *E) {
VisitorBase::TraverseCompoundLiteralExpr(E);
TraverseTypeLoc(E->getTypeSourceInfo()->getTypeLoc());
return true;
}
bool VisitRecordType(RecordType *T) {
RecordDecl *D = T->getDecl();
if (!D->getIdentifier())
TraverseDecl(D);
return true;
}
};
The CompoundLiteralExpr change would be straight forward to add to RAV.
I'm not sure about the RecordType change though. There's two problems.
First, I don't know whether getIdentifier() is the correct test. I expected
isAnonymousStructOrUnion() to be a better test but it didn't work.
Second, this changes results in the 2nd anonymous union being traversed twice.
This is because the declaration of 'a' is parsed into a DeclStmt containing
both a RecordDecl and a VarDecl (and there is a RecordType as part of the
VarDecl), whereas I would have expected only the VarDecl.
Thanks, this workaround seems to work, all tests from different projects pass now!
Sergejs
> The CompoundLiteralExpr change would be straight forward to add to RAV.
I agree, fixed in r162133.
> I'm not sure about the RecordType change though.
Right, that change is not correct (for instance, a named type can be defined in
a compound literal in C). I *think* we want two changes here:
* Avoid repeatedly visiting the decl-specifier-seq when visiting a DeclStmt, and
* Visit the TagDecl when we visit a TagTypeLoc where isDefinition() returns
true.