[cfe-dev] Attempting to get type from typedef struct causes crash
Stuart Thomson via cfe-dev
cfe-dev at lists.llvm.org
Wed Sep 26 08:28:42 PDT 2018
Hi,
I am trying to write a custom clang-tidy check (I want to check for the use of CAdapt<>) but have been struggling with the following issue: I am trying to make an AST matcher which checks the string representation of the type of a VarDecl - but when it runs on certain code it crashes and I can't figure out why. The issue seems to be some interaction between QualType::getAsString() and typedef struct variables, (there may be other code which crashes it but this is what I have been able to find). The issue can be reproduced with the following custom clang-tidy check (apologies if there is a more sensible way to make a minimal repro than a clang-tidy check):
//-----------------------------------------------------------
#include "CrashingCheck.h"
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
using namespace clang::ast_matchers;
namespace clang {
namespace tidy {
namespace misc {
namespace {
AST_MATCHER(VarDecl, isMatch) {
Node.getTypeSourceInfo()->getType().getAsString();
return false;
}
}
void CrashingCheck::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher(varDecl(isMatch()).bind("varDecl"), this);
}
void CrashingCheck::check(const MatchFinder::MatchResult &Result) {}
}}}
//-----------------------------------------------------------
Which crashes when run on:
//-----------------------------------------------------------
typedef struct foo{} foo;
int main(){
foo f;
return 0;
}
//-----------------------------------------------------------
Is there some restriction on when it is OK to use getAsString() that I am not understanding? Also, if there is a better way to write something like this then do let me know, I'm pretty new to this.
Thanks,
Stuart
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20180926/dd5dc5f6/attachment.html>
More information about the cfe-dev
mailing list