diff options
author | Leonard Chan <leonardchan@google.com> | 2019-05-07 03:20:17 +0000 |
---|---|---|
committer | Leonard Chan <leonardchan@google.com> | 2019-05-07 03:20:17 +0000 |
commit | c72aaf62d3f92c0c6d33b4df2253505f6eb22996 (patch) | |
tree | bb29b4896b3792cdef8f5017a40b59625c456f04 /clang/lib/AST | |
parent | da82ce99b7460164ffb841619aadb44f397d2106 (diff) | |
download | bcm5719-llvm-c72aaf62d3f92c0c6d33b4df2253505f6eb22996.tar.gz bcm5719-llvm-c72aaf62d3f92c0c6d33b4df2253505f6eb22996.zip |
Recommit r359859 "[Attribute/Diagnostics] Print macro if definition is an attribute declaration"
Updated with fix for read of uninitialized memory.
llvm-svn: 360109
Diffstat (limited to 'clang/lib/AST')
-rw-r--r-- | clang/lib/AST/ASTContext.cpp | 19 | ||||
-rw-r--r-- | clang/lib/AST/ASTDiagnostic.cpp | 5 | ||||
-rw-r--r-- | clang/lib/AST/ASTStructuralEquivalence.cpp | 7 | ||||
-rw-r--r-- | clang/lib/AST/ItaniumMangle.cpp | 1 | ||||
-rw-r--r-- | clang/lib/AST/Type.cpp | 19 | ||||
-rw-r--r-- | clang/lib/AST/TypePrinter.cpp | 16 |
6 files changed, 66 insertions, 1 deletions
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index d0a790cad4d..63488853759 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -2047,6 +2047,10 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) const { case Type::Paren: return getTypeInfo(cast<ParenType>(T)->getInnerType().getTypePtr()); + case Type::MacroQualified: + return getTypeInfo( + cast<MacroQualifiedType>(T)->getUnderlyingType().getTypePtr()); + case Type::ObjCTypeParam: return getTypeInfo(cast<ObjCTypeParamType>(T)->desugar().getTypePtr()); @@ -3929,7 +3933,7 @@ QualType ASTContext::getAttributedType(attr::Kind attrKind, QualType canon = getCanonicalType(equivalentType); type = new (*this, TypeAlignment) - AttributedType(canon, attrKind, modifiedType, equivalentType); + AttributedType(canon, attrKind, modifiedType, equivalentType); Types.push_back(type); AttributedTypes.InsertNode(type, insertPos); @@ -4210,6 +4214,19 @@ ASTContext::getParenType(QualType InnerType) const { return QualType(T, 0); } +QualType +ASTContext::getMacroQualifiedType(QualType UnderlyingTy, + const IdentifierInfo *MacroII) const { + QualType Canon = UnderlyingTy; + if (!Canon.isCanonical()) + Canon = getCanonicalType(UnderlyingTy); + + auto *newType = new (*this, TypeAlignment) + MacroQualifiedType(UnderlyingTy, Canon, MacroII); + Types.push_back(newType); + return QualType(newType, 0); +} + QualType ASTContext::getDependentNameType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, const IdentifierInfo *Name, diff --git a/clang/lib/AST/ASTDiagnostic.cpp b/clang/lib/AST/ASTDiagnostic.cpp index 61900aa4ac9..15df8658529 100644 --- a/clang/lib/AST/ASTDiagnostic.cpp +++ b/clang/lib/AST/ASTDiagnostic.cpp @@ -41,6 +41,11 @@ static QualType Desugar(ASTContext &Context, QualType QT, bool &ShouldAKA) { QT = PT->desugar(); continue; } + // ... or a macro defined type ... + if (const MacroQualifiedType *MDT = dyn_cast<MacroQualifiedType>(Ty)) { + QT = MDT->desugar(); + continue; + } // ...or a substituted template type parameter ... if (const SubstTemplateTypeParmType *ST = dyn_cast<SubstTemplateTypeParmType>(Ty)) { diff --git a/clang/lib/AST/ASTStructuralEquivalence.cpp b/clang/lib/AST/ASTStructuralEquivalence.cpp index 71bbd824812..567945c16cd 100644 --- a/clang/lib/AST/ASTStructuralEquivalence.cpp +++ b/clang/lib/AST/ASTStructuralEquivalence.cpp @@ -595,6 +595,13 @@ static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context, return false; break; + case Type::MacroQualified: + if (!IsStructurallyEquivalent( + Context, cast<MacroQualifiedType>(T1)->getUnderlyingType(), + cast<MacroQualifiedType>(T2)->getUnderlyingType())) + return false; + break; + case Type::Typedef: if (!IsStructurallyEquivalent(Context, cast<TypedefType>(T1)->getDecl(), cast<TypedefType>(T2)->getDecl())) diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp index 1eb5460dd61..1dba7ccc90a 100644 --- a/clang/lib/AST/ItaniumMangle.cpp +++ b/clang/lib/AST/ItaniumMangle.cpp @@ -1963,6 +1963,7 @@ bool CXXNameMangler::mangleUnresolvedTypeOrSimpleId(QualType Ty, case Type::ObjCTypeParam: case Type::Atomic: case Type::Pipe: + case Type::MacroQualified: llvm_unreachable("type is illegal as a nested name specifier"); case Type::SubstTemplateTypeParmPack: diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp index adffe92f95f..590e534fbdf 100644 --- a/clang/lib/AST/Type.cpp +++ b/clang/lib/AST/Type.cpp @@ -973,6 +973,7 @@ public: SUGARED_TYPE_CLASS(Typedef) SUGARED_TYPE_CLASS(ObjCTypeParam) + SUGARED_TYPE_CLASS(MacroQualified) QualType VisitAdjustedType(const AdjustedType *T) { QualType originalType = recurse(T->getOriginalType()); @@ -1735,6 +1736,10 @@ namespace { return Visit(T->getModifiedType()); } + Type *VisitMacroQualifiedType(const MacroQualifiedType *T) { + return Visit(T->getUnderlyingType()); + } + Type *VisitAdjustedType(const AdjustedType *T) { return Visit(T->getOriginalType()); } @@ -3160,6 +3165,20 @@ QualType TypedefType::desugar() const { return getDecl()->getUnderlyingType(); } +QualType MacroQualifiedType::desugar() const { return getUnderlyingType(); } + +QualType MacroQualifiedType::getModifiedType() const { + // Step over MacroQualifiedTypes from the same macro to find the type + // ultimately qualified by the macro qualifier. + QualType Inner = cast<AttributedType>(getUnderlyingType())->getModifiedType(); + while (auto *InnerMQT = dyn_cast<MacroQualifiedType>(Inner)) { + if (InnerMQT->getMacroIdentifier() != getMacroIdentifier()) + break; + Inner = InnerMQT->getModifiedType(); + } + return Inner; +} + TypeOfExprType::TypeOfExprType(Expr *E, QualType can) : Type(TypeOfExpr, can, E->isTypeDependent(), E->isInstantiationDependent(), diff --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp index 85045324974..13b105bc572 100644 --- a/clang/lib/AST/TypePrinter.cpp +++ b/clang/lib/AST/TypePrinter.cpp @@ -259,6 +259,7 @@ bool TypePrinter::canPrefixQualifiers(const Type *T, case Type::Paren: case Type::PackExpansion: case Type::SubstTemplateTypeParm: + case Type::MacroQualified: CanPrefixQualifiers = false; break; @@ -963,6 +964,21 @@ void TypePrinter::printTypedefBefore(const TypedefType *T, raw_ostream &OS) { printTypeSpec(T->getDecl(), OS); } +void TypePrinter::printMacroQualifiedBefore(const MacroQualifiedType *T, + raw_ostream &OS) { + StringRef MacroName = T->getMacroIdentifier()->getName(); + OS << MacroName << " "; + + // Since this type is meant to print the macro instead of the whole attribute, + // we trim any attributes and go directly to the original modified type. + printBefore(T->getModifiedType(), OS); +} + +void TypePrinter::printMacroQualifiedAfter(const MacroQualifiedType *T, + raw_ostream &OS) { + printAfter(T->getModifiedType(), OS); +} + void TypePrinter::printTypedefAfter(const TypedefType *T, raw_ostream &OS) {} void TypePrinter::printTypeOfExprBefore(const TypeOfExprType *T, |