From 563a03b1338d31c2462def43253a722bc885d384 Mon Sep 17 00:00:00 2001 From: Anders Carlsson Date: Fri, 10 Jul 2009 19:20:26 +0000 Subject: [PATCH] Fix a problem that Eli noticed, and that Doug helped me fix. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@75265 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/Type.h | 11 +++++++++-- lib/AST/ASTContext.cpp | 4 ++-- lib/AST/Type.cpp | 11 +++++++---- lib/CodeGen/CGDebugInfo.cpp | 4 ++-- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/include/clang/AST/Type.h b/include/clang/AST/Type.h index 2beaba637c..39eb1842b3 100644 --- a/include/clang/AST/Type.h +++ b/include/clang/AST/Type.h @@ -1463,11 +1463,18 @@ public: /// DecltypeType (C++0x) class DecltypeType : public Type { Expr *E; - DecltypeType(Expr *E, QualType can = QualType()); + + // FIXME: We could get rid of UnderlyingType if we wanted to: We would have to + // Move getDesugaredType to ASTContext so that it can call getDecltypeForExpr + // from it. + QualType UnderlyingType; + + DecltypeType(Expr *E, QualType underlyingType, QualType can = QualType()); friend class ASTContext; // ASTContext creates these. public: Expr *getUnderlyingExpr() const { return E; } - + QualType getUnderlyingType() const { return UnderlyingType; } + virtual void getAsStringInternal(std::string &InnerString, const PrintingPolicy &Policy) const; diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index de4816c503..2bd1482adc 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -1964,10 +1964,10 @@ static QualType getDecltypeForExpr(const Expr *e, ASTContext &Context) { QualType ASTContext::getDecltypeType(Expr *e) { DecltypeType *dt; if (e->isTypeDependent()) // FIXME: canonicalize the expression - dt = new (*this, 8) DecltypeType(e); + dt = new (*this, 8) DecltypeType(e, DependentTy); else { QualType T = getDecltypeForExpr(e, *this); - dt = new (*this, 8) DecltypeType(e, getCanonicalType(T)); + dt = new (*this, 8) DecltypeType(e, T, getCanonicalType(T)); } Types.push_back(dt); return QualType(dt, 0); diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp index d5dd776b7d..78c3b78977 100644 --- a/lib/AST/Type.cpp +++ b/lib/AST/Type.cpp @@ -124,8 +124,10 @@ QualType Type::getDesugaredType(bool ForDisplay) const { return TOE->getUnderlyingExpr()->getType().getDesugaredType(); if (const TypeOfType *TOT = dyn_cast(this)) return TOT->getUnderlyingType().getDesugaredType(); - if (const DecltypeType *DTT = dyn_cast(this)) - return DTT->getCanonicalTypeInternal(); + if (const DecltypeType *DTT = dyn_cast(this)) { + if (!DTT->getUnderlyingType()->isDependentType()) + return DTT->getUnderlyingType().getDesugaredType(); + } if (const TemplateSpecializationType *Spec = dyn_cast(this)) { if (ForDisplay) @@ -1074,8 +1076,9 @@ TypeOfExprType::TypeOfExprType(Expr *E, QualType can) : Type(TypeOfExpr, can, E->isTypeDependent()), TOExpr(E) { } -DecltypeType::DecltypeType(Expr *E, QualType can) - : Type(Decltype, can, E->isTypeDependent()), E(E) { +DecltypeType::DecltypeType(Expr *E, QualType underlyingType, QualType can) + : Type(Decltype, can, E->isTypeDependent()), E(E), + UnderlyingType(underlyingType) { } TagType::TagType(TypeClass TC, TagDecl *D, QualType can) diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp index cf8e19af32..8fa1e9c920 100644 --- a/lib/CodeGen/CGDebugInfo.cpp +++ b/lib/CodeGen/CGDebugInfo.cpp @@ -792,8 +792,8 @@ llvm::DIType CGDebugInfo::getOrCreateType(QualType Ty, return Slot = getOrCreateType(cast(Ty)->getUnderlyingType(), Unit); case Type::Decltype: - return Slot = getOrCreateType(cast(Ty)->getUnderlyingExpr() - ->getType(), Unit); + return Slot = getOrCreateType(cast(Ty)->getUnderlyingType(), + Unit); } return Slot; -- 2.40.0