Commit ea2805a0 authored by Pavel Labath's avatar Pavel Labath
Browse files

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

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.

Reviewers: teemperor, shafik

Subscribers: lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D71405
parent f8495017
Loading
Loading
Loading
Loading
+12 −74
Original line number Diff line number Diff line
@@ -2499,9 +2499,12 @@ RemoveWrappingTypes(QualType type, ArrayRef<clang::Type::TypeClass> mask = {}) {
      type = cast<clang::AtomicType>(type)->getValueType();
      break;
    case clang::Type::Auto:
    case clang::Type::Decltype:
    case clang::Type::Elaborated:
    case clang::Type::Paren:
    case clang::Type::Typedef:
    case clang::Type::TypeOf:
    case clang::Type::TypeOfExpr:
      type = type->getLocallyUnqualifiedSingleStepDesugaredType();
      break;
    default:
@@ -3765,11 +3768,6 @@ ClangASTContext::GetTypeInfo(lldb::opaque_compiler_type_t type,
    return eTypeHasChildren | eTypeIsVector;
  case clang::Type::DependentTemplateSpecialization:
    return eTypeIsTemplate;
  case clang::Type::Decltype:
    return CompilerType(this, llvm::cast<clang::DecltypeType>(qual_type)
                                  ->getUnderlyingType()
                                  .getAsOpaquePtr())
        .GetTypeInfo(pointee_or_element_clang_type);

  case clang::Type::Enum:
    if (pointee_or_element_clang_type)
@@ -3837,17 +3835,6 @@ ClangASTContext::GetTypeInfo(lldb::opaque_compiler_type_t type,
                                  ->getUnderlyingType()
                                  .getAsOpaquePtr())
               .GetTypeInfo(pointee_or_element_clang_type);
  case clang::Type::TypeOfExpr:
    return CompilerType(this, llvm::cast<clang::TypeOfExprType>(qual_type)
                                  ->getUnderlyingExpr()
                                  ->getType()
                                  .getAsOpaquePtr())
        .GetTypeInfo(pointee_or_element_clang_type);
  case clang::Type::TypeOf:
    return CompilerType(this, llvm::cast<clang::TypeOfType>(qual_type)
                                  ->getUnderlyingType()
                                  .getAsOpaquePtr())
        .GetTypeInfo(pointee_or_element_clang_type);
  case clang::Type::UnresolvedUsing:
    return 0;

@@ -3966,8 +3953,11 @@ ClangASTContext::GetTypeClass(lldb::opaque_compiler_type_t type) {
  switch (qual_type->getTypeClass()) {
  case clang::Type::Atomic:
  case clang::Type::Auto:
  case clang::Type::Decltype:
  case clang::Type::Elaborated:
  case clang::Type::Paren:
  case clang::Type::TypeOf:
  case clang::Type::TypeOfExpr:
    llvm_unreachable("Handled in RemoveWrappingTypes!");
  case clang::Type::UnaryTransform:
    break;
@@ -4049,22 +4039,6 @@ ClangASTContext::GetTypeClass(lldb::opaque_compiler_type_t type) {
  case clang::Type::PackExpansion:
    break;

  case clang::Type::TypeOfExpr:
    return CompilerType(this, llvm::cast<clang::TypeOfExprType>(qual_type)
                                  ->getUnderlyingExpr()
                                  ->getType()
                                  .getAsOpaquePtr())
        .GetTypeClass();
  case clang::Type::TypeOf:
    return CompilerType(this, llvm::cast<clang::TypeOfType>(qual_type)
                                  ->getUnderlyingType()
                                  .getAsOpaquePtr())
        .GetTypeClass();
  case clang::Type::Decltype:
    return CompilerType(this, llvm::cast<clang::TypeOfType>(qual_type)
                                  ->getUnderlyingType()
                                  .getAsOpaquePtr())
        .GetTypeClass();
  case clang::Type::TemplateSpecialization:
    break;
  case clang::Type::DeducedTemplateSpecialization:
@@ -4678,9 +4652,12 @@ lldb::Encoding ClangASTContext::GetEncoding(lldb::opaque_compiler_type_t type,
  switch (qual_type->getTypeClass()) {
  case clang::Type::Atomic:
  case clang::Type::Auto:
  case clang::Type::Decltype:
  case clang::Type::Elaborated:
  case clang::Type::Paren:
  case clang::Type::Typedef:
  case clang::Type::TypeOf:
  case clang::Type::TypeOfExpr:
    llvm_unreachable("Handled in RemoveWrappingTypes!");

  case clang::Type::UnaryTransform:
@@ -4888,22 +4865,6 @@ lldb::Encoding ClangASTContext::GetEncoding(lldb::opaque_compiler_type_t type,
    break;
  case clang::Type::Enum:
    return lldb::eEncodingSint;
  case clang::Type::TypeOfExpr:
    return CompilerType(this, llvm::cast<clang::TypeOfExprType>(qual_type)
                                  ->getUnderlyingExpr()
                                  ->getType()
                                  .getAsOpaquePtr())
        .GetEncoding(count);
  case clang::Type::TypeOf:
    return CompilerType(this, llvm::cast<clang::TypeOfType>(qual_type)
                                  ->getUnderlyingType()
                                  .getAsOpaquePtr())
        .GetEncoding(count);
  case clang::Type::Decltype:
    return CompilerType(this, llvm::cast<clang::DecltypeType>(qual_type)
                                  ->getUnderlyingType()
                                  .getAsOpaquePtr())
        .GetEncoding(count);
  case clang::Type::DependentSizedArray:
  case clang::Type::DependentSizedExtVector:
  case clang::Type::UnresolvedUsing:
@@ -4947,9 +4908,12 @@ lldb::Format ClangASTContext::GetFormat(lldb::opaque_compiler_type_t type) {
  switch (qual_type->getTypeClass()) {
  case clang::Type::Atomic:
  case clang::Type::Auto:
  case clang::Type::Decltype:
  case clang::Type::Elaborated:
  case clang::Type::Paren:
  case clang::Type::Typedef:
  case clang::Type::TypeOf:
  case clang::Type::TypeOfExpr:
    llvm_unreachable("Handled in RemoveWrappingTypes!");
  case clang::Type::UnaryTransform:
    break;
@@ -5043,22 +5007,6 @@ lldb::Format ClangASTContext::GetFormat(lldb::opaque_compiler_type_t type) {
    break;
  case clang::Type::Enum:
    return lldb::eFormatEnum;
  case clang::Type::TypeOfExpr:
    return CompilerType(this, llvm::cast<clang::TypeOfExprType>(qual_type)
                                  ->getUnderlyingExpr()
                                  ->getType()
                                  .getAsOpaquePtr())
        .GetFormat();
  case clang::Type::TypeOf:
    return CompilerType(this, llvm::cast<clang::TypeOfType>(qual_type)
                                  ->getUnderlyingType()
                                  .getAsOpaquePtr())
        .GetFormat();
  case clang::Type::Decltype:
    return CompilerType(this, llvm::cast<clang::DecltypeType>(qual_type)
                                  ->getUnderlyingType()
                                  .getAsOpaquePtr())
        .GetFormat();
  case clang::Type::DependentSizedArray:
  case clang::Type::DependentSizedExtVector:
  case clang::Type::UnresolvedUsing:
@@ -5930,16 +5878,6 @@ uint32_t ClangASTContext::GetNumPointeeChildren(clang::QualType type) {
    return 0; // When we function pointers, they have no children...
  case clang::Type::UnresolvedUsing:
    return 0;
  case clang::Type::TypeOfExpr:
    return GetNumPointeeChildren(llvm::cast<clang::TypeOfExprType>(qual_type)
                                     ->getUnderlyingExpr()
                                     ->getType());
  case clang::Type::TypeOf:
    return GetNumPointeeChildren(
        llvm::cast<clang::TypeOfType>(qual_type)->getUnderlyingType());
  case clang::Type::Decltype:
    return GetNumPointeeChildren(
        llvm::cast<clang::DecltypeType>(qual_type)->getUnderlyingType());
  case clang::Type::Record:
    return 0;
  case clang::Type::Enum:
+36 −4
Original line number Diff line number Diff line
@@ -6,15 +6,14 @@
//
//===----------------------------------------------------------------------===//

#include "gtest/gtest.h"

#include "clang/AST/DeclCXX.h"

#include "lldb/Host/FileSystem.h"
#include "lldb/Host/HostInfo.h"
#include "lldb/Symbol/ClangASTContext.h"
#include "lldb/Symbol/ClangUtil.h"
#include "lldb/Symbol/Declaration.h"
#include "clang/AST/DeclCXX.h"
#include "clang/AST/ExprCXX.h"
#include "gtest/gtest.h"

using namespace clang;
using namespace lldb;
@@ -447,3 +446,36 @@ TEST_F(TestClangASTContext, TemplateArguments) {
    EXPECT_EQ(int_type, result->type);
  }
}

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()));
}