diff options
author | Leonard Chan <leonardchan@google.com> | 2019-05-02 20:38:14 +0000 |
---|---|---|
committer | Leonard Chan <leonardchan@google.com> | 2019-05-02 20:38:14 +0000 |
commit | fae4e4715c9bc8ceb9b3714d5c08813363890b7f (patch) | |
tree | 8994356a0cce2feee0f0cd07cc2ebc180c7fe81c /lib/AST/Type.cpp | |
parent | c1150d547616902e07d68c5b51f466bac8ff1883 (diff) |
[Attribute/Diagnostics] Print macro if definition is an attribute declaration
If an address_space attribute is defined in a macro, print the macro instead
when diagnosing a warning or error for incompatible pointers with different
address_spaces.
We allow this for all attributes (not just address_space), and for multiple
attributes declared in the same macro.
Differential Revision: https://reviews.llvm.org/D51329
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@359826 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/Type.cpp')
-rw-r--r-- | lib/AST/Type.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp index adffe92f95..590e534fbd 100644 --- a/lib/AST/Type.cpp +++ b/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(), |