llvm / llvm-project

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

clang::TypeName::getFullyQualifiedName crashes on certain input #47118

Open llvmbot opened 4 years ago

llvmbot commented 4 years ago
Bugzilla Link 47774
Version trunk
OS All
Reporter LLVM Bugzilla Contributor
CC @zygoloid

Extended Description

In the following code:

template <template class C> struct S {}; template void bar(S);

TypeName::getFullyQualifiedName() crashes on the type of the ParmVarDecl S, whose type is:

TemplateSpecializationType 0x62100004b940 'S' dependent S `-TemplateArgument template U::template foo

Fully contained code with the crash is below:

include "clang/AST/QualTypeNames.h"

include "clang/AST/RecursiveASTVisitor.h"

include "clang/Frontend/ASTUnit.h"

include "clang/Tooling/Tooling.h"

using namespace clang; using namespace tooling;

class ParmVarVisitor : public RecursiveASTVisitor { public: bool VisitParmVarDecl(ParmVarDecl* pv) { const auto& context = pv->getASTContext(); auto type = pv->getType(); PrintingPolicy pp{LangOptions{}}; TypeName::getFullyQualifiedName(type, context, pp);

return true;

} };

int main() { std::unique_ptr ast = buildASTFromCode( "template <template class C>\nstruct S {};\ntemplate \nvoid bar(S);", "foo.cc");

auto* TU = ast->getASTContext().getTranslationUnitDecl(); TU->dump(); llvm::errs() << "\n"; ParmVarVisitor{}.TraverseDecl(TU); return 0; }

llvmbot commented 1 year ago

@llvm/issue-subscribers-clang-frontend

llvmbot commented 1 year ago

@llvm/issue-subscribers-c-1