r184763 - [AST] Introduce a new DecayedType sugar node

Nico Weber thakis at chromium.org
Mon Jun 24 12:40:59 PDT 2013


On Mon, Jun 24, 2013 at 10:51 AM, Reid Kleckner <reid at kleckner.net> wrote:

> Author: rnk
> Date: Mon Jun 24 12:51:48 2013
> New Revision: 184763
>
> URL: http://llvm.org/viewvc/llvm-project?rev=184763&view=rev
> Log:
> [AST] Introduce a new DecayedType sugar node
>
> The goal of this sugar node is to be able to look at an arbitrary
> FunctionType and tell if any of the parameters were decayed from an
> array or function type.  Ultimately this is necessary to implement
> Microsoft's C++ name mangling scheme, which mangles decayed arrays
> differently from normal pointers.
>
> Reviewers: rsmith
>
> Differential Revision: http://llvm-reviews.chandlerc.com/D1014
>
> Modified:
>     cfe/trunk/include/clang/AST/ASTContext.h
>     cfe/trunk/include/clang/AST/Decl.h
>     cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
>     cfe/trunk/include/clang/AST/Type.h
>     cfe/trunk/include/clang/AST/TypeLoc.h
>     cfe/trunk/include/clang/AST/TypeNodes.def
>     cfe/trunk/include/clang/Serialization/ASTBitCodes.h
>     cfe/trunk/lib/AST/ASTContext.cpp
>     cfe/trunk/lib/AST/ASTImporter.cpp
>     cfe/trunk/lib/AST/Decl.cpp
>     cfe/trunk/lib/AST/ItaniumMangle.cpp
>     cfe/trunk/lib/AST/TypePrinter.cpp
>     cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
>     cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
>     cfe/trunk/lib/Sema/SemaExpr.cpp
>     cfe/trunk/lib/Sema/SemaType.cpp
>     cfe/trunk/lib/Sema/TreeTransform.h
>     cfe/trunk/lib/Serialization/ASTReader.cpp
>     cfe/trunk/lib/Serialization/ASTWriter.cpp
>     cfe/trunk/test/Index/print-type.c
>     cfe/trunk/test/Sema/function.c
>     cfe/trunk/test/SemaCXX/function-type-qual.cpp
>     cfe/trunk/tools/libclang/CIndex.cpp
>     cfe/trunk/tools/libclang/RecursiveASTVisitor.h
>
> Modified: cfe/trunk/include/clang/AST/ASTContext.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=184763&r1=184762&r2=184763&view=diff
>
> ==============================================================================
> --- cfe/trunk/include/clang/AST/ASTContext.h (original)
> +++ cfe/trunk/include/clang/AST/ASTContext.h Mon Jun 24 12:51:48 2013
> @@ -82,6 +82,7 @@ class ASTContext : public RefCountedBase
>    mutable llvm::FoldingSet<ExtQuals> ExtQualNodes;
>    mutable llvm::FoldingSet<ComplexType> ComplexTypes;
>    mutable llvm::FoldingSet<PointerType> PointerTypes;
> +  mutable llvm::FoldingSet<DecayedType> DecayedTypes;
>    mutable llvm::FoldingSet<BlockPointerType> BlockPointerTypes;
>    mutable llvm::FoldingSet<LValueReferenceType> LValueReferenceTypes;
>    mutable llvm::FoldingSet<RValueReferenceType> RValueReferenceTypes;
> @@ -889,6 +890,14 @@ public:
>      return CanQualType::CreateUnsafe(getPointerType((QualType) T));
>    }
>
> +  /// \brief Return the uniqued reference to the decayed version of the
> given
> +  /// type.  Can only be called on array and function types which decay to
> +  /// pointer types.
> +  QualType getDecayedType(QualType T) const;
> +  CanQualType getDecayedType(CanQualType T) const {
> +    return CanQualType::CreateUnsafe(getDecayedType((QualType) T));
> +  }
> +
>    /// \brief Return the uniqued reference to the atomic type for the
> specified
>    /// type.
>    QualType getAtomicType(QualType T) const;
>
> Modified: cfe/trunk/include/clang/AST/Decl.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=184763&r1=184762&r2=184763&view=diff
>
> ==============================================================================
> --- cfe/trunk/include/clang/AST/Decl.h (original)
> +++ cfe/trunk/include/clang/AST/Decl.h Mon Jun 24 12:51:48 2013
> @@ -1337,11 +1337,7 @@ public:
>      ParmVarDeclBits.HasInheritedDefaultArg = I;
>    }
>
> -  QualType getOriginalType() const {
> -    if (getTypeSourceInfo())
> -      return getTypeSourceInfo()->getType();
> -    return getType();
> -  }
> +  QualType getOriginalType() const;
>
>    /// \brief Determine whether this parameter is actually a function
>    /// parameter pack.
>
> Modified: cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/RecursiveASTVisitor.h?rev=184763&r1=184762&r2=184763&view=diff
>
> ==============================================================================
> --- cfe/trunk/include/clang/AST/RecursiveASTVisitor.h (original)
> +++ cfe/trunk/include/clang/AST/RecursiveASTVisitor.h Mon Jun 24 12:51:48
> 2013
> @@ -847,6 +847,10 @@ DEF_TRAVERSE_TYPE(MemberPointerType, {
>      TRY_TO(TraverseType(T->getPointeeType()));
>    })
>
> +DEF_TRAVERSE_TYPE(DecayedType, {
> +    TRY_TO(TraverseType(T->getOriginalType()));
> +  })
> +
>  DEF_TRAVERSE_TYPE(ConstantArrayType, {
>      TRY_TO(TraverseType(T->getElementType()));
>    })
> @@ -1053,6 +1057,10 @@ DEF_TRAVERSE_TYPELOC(MemberPointerType,
>      TRY_TO(TraverseTypeLoc(TL.getPointeeLoc()));
>    })
>
> +DEF_TRAVERSE_TYPELOC(DecayedType, {
> +    TRY_TO(TraverseTypeLoc(TL.getOriginalLoc()));
> +  })
> +
>  template<typename Derived>
>  bool
> RecursiveASTVisitor<Derived>::TraverseArrayTypeLocHelper(ArrayTypeLoc TL) {
>    // This isn't available for ArrayType, but is for the ArrayTypeLoc.
>
> Modified: cfe/trunk/include/clang/AST/Type.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=184763&r1=184762&r2=184763&view=diff
>
> ==============================================================================
> --- cfe/trunk/include/clang/AST/Type.h (original)
> +++ cfe/trunk/include/clang/AST/Type.h Mon Jun 24 12:51:48 2013
> @@ -1991,6 +1991,44 @@ public:
>    static bool classof(const Type *T) { return T->getTypeClass() ==
> Pointer; }
>  };
>
> +/// \brief Represents a pointer type decayed from an array or function
> type.
> +class DecayedType : public Type, public llvm::FoldingSetNode {
> +  QualType OriginalType;
> +  QualType DecayedPointer;
> +
> +  DecayedType(QualType OriginalType, QualType DecayedPointer,
> +              QualType CanonicalPtr)
> +      : Type(Decayed, CanonicalPtr, OriginalType->isDependentType(),
> +             OriginalType->isInstantiationDependentType(),
> +             OriginalType->isVariablyModifiedType(),
> +             OriginalType->containsUnexpandedParameterPack()),
> +        OriginalType(OriginalType), DecayedPointer(DecayedPointer) {
> +    assert(isa<PointerType>(DecayedPointer));
> +  }
> +
> +  friend class ASTContext;  // ASTContext creates these.
> +
> +public:
> +  QualType getDecayedType() const { return DecayedPointer; }
> +  QualType getOriginalType() const { return OriginalType; }
> +
> +  QualType getPointeeType() const {
> +    return cast<PointerType>(DecayedPointer)->getPointeeType();
> +  }
> +
> +  bool isSugared() const { return true; }
> +  QualType desugar() const { return DecayedPointer; }
> +
> +  void Profile(llvm::FoldingSetNodeID &ID) {
> +    Profile(ID, OriginalType);
> +  }
> +  static void Profile(llvm::FoldingSetNodeID &ID, QualType OriginalType) {
> +    ID.AddPointer(OriginalType.getAsOpaquePtr());
> +  }
> +
> +  static bool classof(const Type *T) { return T->getTypeClass() ==
> Decayed; }
> +};
> +
>  /// BlockPointerType - pointer to a block type.
>  /// This type is to represent types syntactically represented as
>  /// "void (^)(int)", etc. Pointee is required to always be a function
> type.
>
> Modified: cfe/trunk/include/clang/AST/TypeLoc.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/TypeLoc.h?rev=184763&r1=184762&r2=184763&view=diff
>
> ==============================================================================
> --- cfe/trunk/include/clang/AST/TypeLoc.h (original)
> +++ cfe/trunk/include/clang/AST/TypeLoc.h Mon Jun 24 12:51:48 2013
> @@ -974,6 +974,40 @@ inline TypeLoc TypeLoc::IgnoreParens() c
>    return *this;
>  }
>
> +
> +struct DecayedLocInfo { }; // Nothing.
> +
> +/// \brief Wrapper for source info for pointers decayed from arrays and
> +/// funcitons.
>

Typo "funcitons".


> +class DecayedTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc,
> DecayedTypeLoc,
> +                                              DecayedType,
> DecayedLocInfo> {
> +public:
> +  TypeLoc getOriginalLoc() const {
> +    return getInnerTypeLoc();
> +  }
> +
> +  void initializeLocal(ASTContext &Context, SourceLocation Loc) {
> +    // do nothing
> +  }
> +
> +  QualType getInnerType() const {
> +    // The inner type is the undecayed type, since that's what we have
> source
> +    // location information for.
> +    return getTypePtr()->getOriginalType();
> +  }
> +
> +  SourceRange getLocalSourceRange() const {
> +    return SourceRange();
> +  }
> +
> +  unsigned getLocalDataSize() const {
> +    // sizeof(DecayedLocInfo) is 1, but we don't need its address to be
> unique
> +    // anyway.  TypeLocBuilder can't handle data sizes of 1.
> +    return 0;  // No data.
> +  }
> +};
> +
> +
>  struct PointerLikeLocInfo {
>    SourceLocation StarLoc;
>  };
>
> Modified: cfe/trunk/include/clang/AST/TypeNodes.def
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/TypeNodes.def?rev=184763&r1=184762&r2=184763&view=diff
>
> ==============================================================================
> --- cfe/trunk/include/clang/AST/TypeNodes.def (original)
> +++ cfe/trunk/include/clang/AST/TypeNodes.def Mon Jun 24 12:51:48 2013
> @@ -81,6 +81,7 @@ TYPE(FunctionNoProto, FunctionType)
>  DEPENDENT_TYPE(UnresolvedUsing, Type)
>  NON_CANONICAL_TYPE(Paren, Type)
>  NON_CANONICAL_TYPE(Typedef, Type)
> +NON_CANONICAL_TYPE(Decayed, Type)
>  NON_CANONICAL_UNLESS_DEPENDENT_TYPE(TypeOfExpr, Type)
>  NON_CANONICAL_UNLESS_DEPENDENT_TYPE(TypeOf, Type)
>  NON_CANONICAL_UNLESS_DEPENDENT_TYPE(Decltype, Type)
>
> Modified: cfe/trunk/include/clang/Serialization/ASTBitCodes.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTBitCodes.h?rev=184763&r1=184762&r2=184763&view=diff
>
> ==============================================================================
> --- cfe/trunk/include/clang/Serialization/ASTBitCodes.h (original)
> +++ cfe/trunk/include/clang/Serialization/ASTBitCodes.h Mon Jun 24
> 12:51:48 2013
> @@ -836,7 +836,9 @@ namespace clang {
>        /// \brief A UnaryTransformType record.
>        TYPE_UNARY_TRANSFORM       = 39,
>        /// \brief An AtomicType record.
> -      TYPE_ATOMIC                = 40
> +      TYPE_ATOMIC                = 40,
> +      /// \brief A DecayedType record.
> +      TYPE_DECAYED               = 41
>      };
>
>      /// \brief The type IDs for special types constructed by semantic
>
> Modified: cfe/trunk/lib/AST/ASTContext.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=184763&r1=184762&r2=184763&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/AST/ASTContext.cpp (original)
> +++ cfe/trunk/lib/AST/ASTContext.cpp Mon Jun 24 12:51:48 2013
> @@ -1615,6 +1615,8 @@ ASTContext::getTypeInfoImpl(const Type *
>    }
>    case Type::ObjCObject:
>      return
> getTypeInfo(cast<ObjCObjectType>(T)->getBaseType().getTypePtr());
> +  case Type::Decayed:
> +    return
> getTypeInfo(cast<DecayedType>(T)->getDecayedType().getTypePtr());
>    case Type::ObjCInterface: {
>      const ObjCInterfaceType *ObjCI = cast<ObjCInterfaceType>(T);
>      const ASTRecordLayout &Layout =
> getASTObjCInterfaceLayout(ObjCI->getDecl());
> @@ -2167,6 +2169,45 @@ QualType ASTContext::getPointerType(Qual
>    return QualType(New, 0);
>  }
>
> +QualType ASTContext::getDecayedType(QualType T) const {
> +  assert((T->isArrayType() || T->isFunctionType()) && "T does not decay");
> +
> +  llvm::FoldingSetNodeID ID;
> +  DecayedType::Profile(ID, T);
> +  void *InsertPos = 0;
> +  if (DecayedType *DT = DecayedTypes.FindNodeOrInsertPos(ID, InsertPos))
> +    return QualType(DT, 0);
> +
> +  QualType Decayed;
> +
> +  // C99 6.7.5.3p7:
> +  //   A declaration of a parameter as "array of type" shall be
> +  //   adjusted to "qualified pointer to type", where the type
> +  //   qualifiers (if any) are those specified within the [ and ] of
> +  //   the array type derivation.
> +  if (T->isArrayType())
> +    Decayed = getArrayDecayedType(T);
> +
> +  // C99 6.7.5.3p8:
> +  //   A declaration of a parameter as "function returning type"
> +  //   shall be adjusted to "pointer to function returning type", as
> +  //   in 6.3.2.1.
> +  if (T->isFunctionType())
> +    Decayed = getPointerType(T);
> +
> +  QualType Canonical = getCanonicalType(Decayed);
> +
> +  // Get the new insert position for the node we care about.
> +  DecayedType *NewIP = DecayedTypes.FindNodeOrInsertPos(ID, InsertPos);
> +  assert(NewIP == 0 && "Shouldn't be in the map!"); (void)NewIP;
> +
> +  DecayedType *New =
> +      new (*this, TypeAlignment) DecayedType(T, Decayed, Canonical);
> +  Types.push_back(New);
> +  DecayedTypes.InsertNode(New, InsertPos);
> +  return QualType(New, 0);
> +}
> +
>  /// getBlockPointerType - Return the uniqued reference to the type for
>  /// a pointer to the specified block.
>  QualType ASTContext::getBlockPointerType(QualType T) const {
> @@ -4154,22 +4195,9 @@ const ArrayType *ASTContext::getAsArrayT
>  }
>
>  QualType ASTContext::getAdjustedParameterType(QualType T) const {
> -  // C99 6.7.5.3p7:
> -  //   A declaration of a parameter as "array of type" shall be
> -  //   adjusted to "qualified pointer to type", where the type
> -  //   qualifiers (if any) are those specified within the [ and ] of
> -  //   the array type derivation.
> -  if (T->isArrayType())
> -    return getArrayDecayedType(T);
> -
> -  // C99 6.7.5.3p8:
> -  //   A declaration of a parameter as "function returning type"
> -  //   shall be adjusted to "pointer to function returning type", as
> -  //   in 6.3.2.1.
> -  if (T->isFunctionType())
> -    return getPointerType(T);
> -
> -  return T;
> +  if (T->isArrayType() || T->isFunctionType())
> +    return getDecayedType(T);
> +  return T;
>  }
>
>  QualType ASTContext::getSignatureParameterType(QualType T) const {
>
> Modified: cfe/trunk/lib/AST/ASTImporter.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=184763&r1=184762&r2=184763&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/AST/ASTImporter.cpp (original)
> +++ cfe/trunk/lib/AST/ASTImporter.cpp Mon Jun 24 12:51:48 2013
> @@ -400,6 +400,13 @@ static bool IsStructurallyEquivalent(Str
>        return false;
>      break;
>
> +  case Type::Decayed:
> +    if (!IsStructurallyEquivalent(Context,
> +                                  cast<DecayedType>(T1)->getPointeeType(),
> +
>  cast<DecayedType>(T2)->getPointeeType()))
> +      return false;
> +    break;
> +
>    case Type::Pointer:
>      if (!IsStructurallyEquivalent(Context,
>                                    cast<PointerType>(T1)->getPointeeType(),
>
> Modified: cfe/trunk/lib/AST/Decl.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=184763&r1=184762&r2=184763&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/AST/Decl.cpp (original)
> +++ cfe/trunk/lib/AST/Decl.cpp Mon Jun 24 12:51:48 2013
> @@ -1995,6 +1995,14 @@ ParmVarDecl *ParmVarDecl::Create(ASTCont
>                               S, DefArg);
>  }
>
> +QualType ParmVarDecl::getOriginalType() const {
> +  TypeSourceInfo *TSI = getTypeSourceInfo();
> +  QualType T = TSI ? TSI->getType() : getType();
> +  if (const DecayedType *DT = dyn_cast<DecayedType>(T))
> +    return DT->getOriginalType();
> +  return T;
> +}
> +
>  ParmVarDecl *ParmVarDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
>    void *Mem = AllocateDeserializedDecl(C, ID, sizeof(ParmVarDecl));
>    return new (Mem) ParmVarDecl(ParmVar, 0, SourceLocation(),
> SourceLocation(),
>
> Modified: cfe/trunk/lib/AST/ItaniumMangle.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ItaniumMangle.cpp?rev=184763&r1=184762&r2=184763&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/AST/ItaniumMangle.cpp (original)
> +++ cfe/trunk/lib/AST/ItaniumMangle.cpp Mon Jun 24 12:51:48 2013
> @@ -828,6 +828,7 @@ void CXXNameMangler::mangleUnresolvedPre
>      switch (type->getTypeClass()) {
>      case Type::Builtin:
>      case Type::Complex:
> +    case Type::Decayed:
>      case Type::Pointer:
>      case Type::BlockPointer:
>      case Type::LValueReference:
>
> Modified: cfe/trunk/lib/AST/TypePrinter.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/TypePrinter.cpp?rev=184763&r1=184762&r2=184763&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/AST/TypePrinter.cpp (original)
> +++ cfe/trunk/lib/AST/TypePrinter.cpp Mon Jun 24 12:51:48 2013
> @@ -201,6 +201,7 @@ bool TypePrinter::canPrefixQualifiers(co
>        NeedARCStrongQualifier = true;
>        // Fall through
>
> +    case Type::Decayed:
>      case Type::Pointer:
>      case Type::BlockPointer:
>      case Type::LValueReference:
> @@ -468,6 +469,14 @@ void TypePrinter::printVariableArrayAfte
>    printAfter(T->getElementType(), OS);
>  }
>
> +void TypePrinter::printDecayedBefore(const DecayedType *T, raw_ostream
> &OS) {
> +  // Print as though it's a pointer.
> +  printBefore(T->getDecayedType(), OS);
> +}
> +void TypePrinter::printDecayedAfter(const DecayedType *T, raw_ostream
> &OS) {
> +  printAfter(T->getDecayedType(), OS);
> +}
> +
>  void TypePrinter::printDependentSizedArrayBefore(
>                                                 const
> DependentSizedArrayType *T,
>                                                 raw_ostream &OS) {
>
> Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=184763&r1=184762&r2=184763&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Mon Jun 24 12:51:48 2013
> @@ -2069,6 +2069,10 @@ llvm::DIType CGDebugInfo::CreateTypeNode
>      return CreateType(cast<ComplexType>(Ty));
>    case Type::Pointer:
>      return CreateType(cast<PointerType>(Ty), Unit);
> +  case Type::Decayed:
> +    // Decayed types are just pointers in LLVM and DWARF.
> +    return CreateType(
> +        cast<PointerType>(cast<DecayedType>(Ty)->getDecayedType()), Unit);
>    case Type::BlockPointer:
>      return CreateType(cast<BlockPointerType>(Ty), Unit);
>    case Type::Typedef:
>
> Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=184763&r1=184762&r2=184763&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp Mon Jun 24 12:51:48 2013
> @@ -1273,6 +1273,10 @@ void CodeGenFunction::EmitVariablyModifi
>      case Type::ObjCObjectPointer:
>        llvm_unreachable("type class is never variably-modified!");
>
> +    case Type::Decayed:
> +      type = cast<DecayedType>(ty)->getPointeeType();
> +      break;
> +
>      case Type::Pointer:
>        type = cast<PointerType>(ty)->getPointeeType();
>        break;
>
> Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=184763&r1=184762&r2=184763&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon Jun 24 12:51:48 2013
> @@ -4021,6 +4021,8 @@ bool Sema::GatherArgumentsForCall(Source
>
>  static void DiagnoseCalleeStaticArrayParam(Sema &S, ParmVarDecl *PVD) {
>    TypeLoc TL = PVD->getTypeSourceInfo()->getTypeLoc();
> +  if (DecayedTypeLoc DTL = TL.getAs<DecayedTypeLoc>())
> +    TL = DTL.getOriginalLoc();
>    if (ArrayTypeLoc ATL = TL.getAs<ArrayTypeLoc>())
>      S.Diag(PVD->getLocation(), diag::note_callee_static_array)
>        << ATL.getLocalSourceRange();
>
> Modified: cfe/trunk/lib/Sema/SemaType.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=184763&r1=184762&r2=184763&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaType.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaType.cpp Mon Jun 24 12:51:48 2013
> @@ -2844,10 +2844,6 @@ static TypeSourceInfo *GetFullTypeForDec
>            QualType ArgTy = Param->getType();
>            assert(!ArgTy.isNull() && "Couldn't parse type?");
>
> -          // Adjust the parameter type.
> -          assert((ArgTy == Context.getAdjustedParameterType(ArgTy)) &&
> -                 "Unadjusted type?");
> -
>            // Look for 'void'.  void is allowed only as a single argument
> to a
>            // function with no other parameters (C99 6.7.5.3p10).  We
> record
>            // int(void) as a FunctionProtoType with an empty argument list.
> @@ -3577,6 +3573,9 @@ namespace {
>      void VisitQualifiedTypeLoc(QualifiedTypeLoc TL) {
>        llvm_unreachable("qualified type locs not expected here!");
>      }
> +    void VisitDecayedTypeLoc(DecayedTypeLoc TL) {
> +      llvm_unreachable("decayed type locs not expected here!");
> +    }
>
>      void VisitAttributedTypeLoc(AttributedTypeLoc TL) {
>        fillAttributedTypeLoc(TL, Chunk.getAttrs());
>
> Modified: cfe/trunk/lib/Sema/TreeTransform.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TreeTransform.h?rev=184763&r1=184762&r2=184763&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Sema/TreeTransform.h (original)
> +++ cfe/trunk/lib/Sema/TreeTransform.h Mon Jun 24 12:51:48 2013
> @@ -3586,6 +3586,22 @@ QualType TreeTransform<Derived>::Transfo
>  }
>
>  template<typename Derived>
> +QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
> +                                                      DecayedTypeLoc TL) {
> +  QualType OriginalType = getDerived().TransformType(TLB,
> TL.getOriginalLoc());
> +  if (OriginalType.isNull())
> +    return QualType();
> +
> +  QualType Result = TL.getType();
> +  if (getDerived().AlwaysRebuild() ||
> +      OriginalType != TL.getOriginalLoc().getType())
> +    Result = SemaRef.Context.getDecayedType(OriginalType);
> +  TLB.push<DecayedTypeLoc>(Result);
> +  // Nothing to set for DecayedTypeLoc.
> +  return Result;
> +}
> +
> +template<typename Derived>
>  QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
>                                                        PointerTypeLoc TL) {
>    QualType PointeeType
>
> Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=184763&r1=184762&r2=184763&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
> +++ cfe/trunk/lib/Serialization/ASTReader.cpp Mon Jun 24 12:51:48 2013
> @@ -4531,6 +4531,18 @@ QualType ASTReader::readTypeRecord(unsig
>      return Context.getPointerType(PointeeType);
>    }
>
> +  case TYPE_DECAYED: {
> +    if (Record.size() != 1) {
> +      Error("Incorrect encoding of decayed type");
> +      return QualType();
> +    }
> +    QualType OriginalType = readType(*Loc.F, Record, Idx);
> +    QualType DT = Context.getAdjustedParameterType(OriginalType);
> +    if (!isa<DecayedType>(DT))
> +      Error("Decayed type does not decay");
> +    return DT;
> +  }
> +
>    case TYPE_BLOCK_POINTER: {
>      if (Record.size() != 1) {
>        Error("Incorrect encoding of block pointer type");
> @@ -4977,6 +4989,9 @@ void TypeLocReader::VisitComplexTypeLoc(
>  void TypeLocReader::VisitPointerTypeLoc(PointerTypeLoc TL) {
>    TL.setStarLoc(ReadSourceLocation(Record, Idx));
>  }
> +void TypeLocReader::VisitDecayedTypeLoc(DecayedTypeLoc TL) {
> +  // nothing to do
> +}
>  void TypeLocReader::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) {
>    TL.setCaretLoc(ReadSourceLocation(Record, Idx));
>  }
>
> Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=184763&r1=184762&r2=184763&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
> +++ cfe/trunk/lib/Serialization/ASTWriter.cpp Mon Jun 24 12:51:48 2013
> @@ -108,6 +108,11 @@ void ASTTypeWriter::VisitPointerType(con
>    Code = TYPE_POINTER;
>  }
>
> +void ASTTypeWriter::VisitDecayedType(const DecayedType *T) {
> +  Writer.AddTypeRef(T->getOriginalType(), Record);
> +  Code = TYPE_DECAYED;
> +}
> +
>  void ASTTypeWriter::VisitBlockPointerType(const BlockPointerType *T) {
>    Writer.AddTypeRef(T->getPointeeType(), Record);
>    Code = TYPE_BLOCK_POINTER;
> @@ -447,6 +452,9 @@ void TypeLocWriter::VisitComplexTypeLoc(
>  void TypeLocWriter::VisitPointerTypeLoc(PointerTypeLoc TL) {
>    Writer.AddSourceLocation(TL.getStarLoc(), Record);
>  }
> +void TypeLocWriter::VisitDecayedTypeLoc(DecayedTypeLoc TL) {
> +  // nothing to do
> +}
>  void TypeLocWriter::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) {
>    Writer.AddSourceLocation(TL.getCaretLoc(), Record);
>  }
>
> Modified: cfe/trunk/test/Index/print-type.c
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/print-type.c?rev=184763&r1=184762&r2=184763&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/Index/print-type.c (original)
> +++ cfe/trunk/test/Index/print-type.c Mon Jun 24 12:51:48 2013
> @@ -35,7 +35,7 @@ typedef int __attribute__((vector_size(1
>  // CHECK: DeclRefExpr=p:3:13 [type=int *] [typekind=Pointer] [isPOD=1]
>  // CHECK: DeclRefExpr=z:3:33 [type=FooType] [typekind=Typedef]
> [canonicaltype=int] [canonicaltypekind=Int] [isPOD=1]
>  // CHECK: ArraySubscriptExpr= [type=int] [typekind=Int] [isPOD=1]
> -// CHECK: DeclRefExpr=arr:3:40 [type=int *] [typekind=Pointer] [isPOD=1]
> +// CHECK: UnexposedExpr=arr:3:40 [type=int *] [typekind=Unexposed]
> [canonicaltype=int *] [canonicaltypekind=Pointer] [isPOD=1]
>  // CHECK: IntegerLiteral= [type=int] [typekind=Int] [isPOD=1]
>  // CHECK: TypedefDecl=OtherType:8:16 (Definition) [type=OtherType]
> [typekind=Typedef] [canonicaltype=double] [canonicaltypekind=Double]
> [isPOD=1]
>  // CHECK: TypedefDecl=ArrayType:9:13 (Definition) [type=ArrayType]
> [typekind=Typedef] [canonicaltype=int [5]]
> [canonicaltypekind=ConstantArray] [isPOD=1]
>
> Modified: cfe/trunk/test/Sema/function.c
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/function.c?rev=184763&r1=184762&r2=184763&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/Sema/function.c (original)
> +++ cfe/trunk/test/Sema/function.c Mon Jun 24 12:51:48 2013
> @@ -103,3 +103,13 @@ int func_e(int x) {
>    }
>    return x + 3;
>  }
> +
> +void decays(int a[3][3]);   // expected-note {{passing argument to
> parameter 'a' here}}
> +void no_decay(int (*a)[3]); // expected-note {{passing argument to
> parameter 'a' here}}
> +
> +void t22(int *ptr, int (*array)[3]) {
> +  decays(ptr);   // expected-warning {{incompatible pointer types passing
> 'int *' to parameter of type 'int (*)[3]'}}
> +  no_decay(ptr); // expected-warning {{incompatible pointer types passing
> 'int *' to parameter of type 'int (*)[3]'}}
> +  decays(array);
> +  no_decay(array);
> +}
>
> Modified: cfe/trunk/test/SemaCXX/function-type-qual.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/function-type-qual.cpp?rev=184763&r1=184762&r2=184763&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/SemaCXX/function-type-qual.cpp (original)
> +++ cfe/trunk/test/SemaCXX/function-type-qual.cpp Mon Jun 24 12:51:48 2013
> @@ -29,3 +29,11 @@ cfn C::*mpg;
>
>  // Don't crash!
>  void (PR14171)() const; // expected-error {{non-member function cannot
> have 'const' qualifier}}
> +
> +// Test template instantiation of decayed array types.  Not really
> related to
> +// type quals.
> +template <typename T> void arrayDecay(const T a[]) { }
> +void instantiateArrayDecay() {
> +  int a[1];
> +  arrayDecay(a);
> +}
>
> Modified: cfe/trunk/tools/libclang/CIndex.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=184763&r1=184762&r2=184763&view=diff
>
> ==============================================================================
> --- cfe/trunk/tools/libclang/CIndex.cpp (original)
> +++ cfe/trunk/tools/libclang/CIndex.cpp Mon Jun 24 12:51:48 2013
> @@ -1546,6 +1546,10 @@ bool CursorVisitor::VisitArrayTypeLoc(Ar
>    return false;
>  }
>
> +bool CursorVisitor::VisitDecayedTypeLoc(DecayedTypeLoc TL) {
> +  return Visit(TL.getOriginalLoc());
> +}
> +
>  bool CursorVisitor::VisitTemplateSpecializationTypeLoc(
>
> TemplateSpecializationTypeLoc TL) {
>    // Visit the template name.
>
> Modified: cfe/trunk/tools/libclang/RecursiveASTVisitor.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/RecursiveASTVisitor.h?rev=184763&r1=184762&r2=184763&view=diff
>
> ==============================================================================
> --- cfe/trunk/tools/libclang/RecursiveASTVisitor.h (original)
> +++ cfe/trunk/tools/libclang/RecursiveASTVisitor.h Mon Jun 24 12:51:48 2013
> @@ -786,6 +786,10 @@ DEF_TRAVERSE_TYPE(MemberPointerType, {
>      TRY_TO(TraverseType(T->getPointeeType()));
>    })
>
> +DEF_TRAVERSE_TYPE(DecayedType, {
> +    TRY_TO(TraverseType(T->getOriginalType()));
> +  })
> +
>  DEF_TRAVERSE_TYPE(ConstantArrayType, {
>      TRY_TO(TraverseType(T->getElementType()));
>    })
> @@ -992,6 +996,10 @@ DEF_TRAVERSE_TYPELOC(MemberPointerType,
>      TRY_TO(TraverseTypeLoc(TL.getPointeeLoc()));
>    })
>
> +DEF_TRAVERSE_TYPELOC(DecayedType, {
> +    TRY_TO(TraverseTypeLoc(TL.getOriginalLoc()));
> +  })
> +
>  template<typename Derived>
>  bool
> RecursiveASTVisitor<Derived>::TraverseArrayTypeLocHelper(ArrayTypeLoc TL) {
>    // This isn't available for ArrayType, but is for the ArrayTypeLoc.
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130624/0ae57e8d/attachment.html>


More information about the cfe-commits mailing list