[llvm-bugs] [Bug 47774] New: clang::TypeName::getFullyQualifiedName crashes on certain input

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Oct 8 19:29:13 PDT 2020


https://bugs.llvm.org/show_bug.cgi?id=47774

            Bug ID: 47774
           Summary: clang::TypeName::getFullyQualifiedName crashes on
                    certain input
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: awoolf at fb.com
                CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org,
                    neeilans at live.com, richard-llvm at metafoo.co.uk

In the following code:

template <template <typename T> class C>
struct S {};
template <typename U>
void bar(S<U::template foo>);

TypeName::getFullyQualifiedName() crashes on the type of the ParmVarDecl
S<U::template foo>, whose type is:

TemplateSpecializationType 0x62100004b940 'S<U::template foo>' 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<ParmVarVisitor> {
 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<ASTUnit> ast = buildASTFromCode(
      "template <template <typename T> class C>\nstruct S {};\ntemplate
<typename U>\nvoid bar(S<U::template foo>);",
      "foo.cc");

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

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20201009/64f4a654/attachment-0001.html>


More information about the llvm-bugs mailing list