This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Centralize desugaring of decltype-like types in ClangASTContext
ClosedPublic

Authored by labath on Dec 12 2019, 2:55 AM.

Details

Summary

These types were handled in some places, but not others. This resulted
in (for example) not being able to display members of structs whose
types were defined using these constructs.

Using getLocallyUnqualifiedSingleStepDesugaredType for these types is
not fully equivalent, as it will only desugar them if the types are not
instantiation-dependent, whereas previously we did that unconditionally.

It's not clear to me which behavior is correct here, but the test suite
does not seem to care either way.

Event Timeline

labath created this revision.Dec 12 2019, 2:55 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 12 2019, 2:55 AM
teemperor accepted this revision.EditedDec 13 2019, 3:46 PM

The change LGTM but the test could just be a unit test instead of doing the whole compile->start->attach->expr command cycle.

You can just add this to the TestClangASTContext.cpp to test the (nested) desugaring and the three types you covered (and one of the switch statements).

static QualType makeConstInt(clang::ASTContext &ctxt) {
  QualType result(ctxt.IntTy);
  result.addConst();
  return result;
}

TEST_F(TestClangASTContext, TestGetTypeClassDeclType) {
  clang::ASTContext &ctxt = *m_ast->getASTContext();
  auto *nullptr_expr = new (ctxt) CXXNullPtrLiteralExpr(ctxt.NullPtrTy, SourceLocation());
  QualType t = ctxt.getDecltypeType(nullptr_expr, makeConstInt(ctxt));
  EXPECT_EQ(lldb::eTypeClassBuiltin, m_ast->GetTypeClass(t.getAsOpaquePtr()));
}

TEST_F(TestClangASTContext, TestGetTypeClassTypeOf) {
  clang::ASTContext &ctxt = *m_ast->getASTContext();
  QualType t = ctxt.getTypeOfType(makeConstInt(ctxt));
  EXPECT_EQ(lldb::eTypeClassBuiltin, m_ast->GetTypeClass(t.getAsOpaquePtr()));
}

TEST_F(TestClangASTContext, TestGetTypeClassTypeOfExpr) {
  clang::ASTContext &ctxt = *m_ast->getASTContext();
  auto *nullptr_expr = new (ctxt) CXXNullPtrLiteralExpr(ctxt.NullPtrTy, SourceLocation());
  QualType t = ctxt.getTypeOfExprType(nullptr_expr);
  EXPECT_EQ(lldb::eTypeClassBuiltin, m_ast->GetTypeClass(t.getAsOpaquePtr()));
}

TEST_F(TestClangASTContext, TestGetTypeClassNested) {
  clang::ASTContext &ctxt = *m_ast->getASTContext();
  QualType t_base = ctxt.getTypeOfType(makeConstInt(ctxt));
  QualType t = ctxt.getTypeOfType(t_base);
  EXPECT_EQ(lldb::eTypeClassBuiltin, m_ast->GetTypeClass(t.getAsOpaquePtr()));
}
This revision is now accepted and ready to land.Dec 13 2019, 3:46 PM

The unit test sounds like a good idea. I'll do that instead.

This revision was automatically updated to reflect the committed changes.