diff options
| author | Fariborz Jahanian <fjahanian@apple.com> | 2009-06-02 18:32:00 +0000 |
|---|---|---|
| committer | Fariborz Jahanian <fjahanian@apple.com> | 2009-06-02 18:32:00 +0000 |
| commit | 6ab4375f87aef663a0f36c438eafa97059ff02a5 (patch) | |
| tree | 517bc0fd3639c407d962baa62313e8cf09f81a21 /clang/lib/AST | |
| parent | 5bd914d0aefa7153b54922a1ebe8c087d39f781d (diff) | |
| download | bcm5719-llvm-6ab4375f87aef663a0f36c438eafa97059ff02a5.tar.gz bcm5719-llvm-6ab4375f87aef663a0f36c438eafa97059ff02a5.zip | |
Issue diagnostics on __weak attribute mismatch.
Fixes an error recovery issue which caused a crash.
llvm-svn: 72733
Diffstat (limited to 'clang/lib/AST')
| -rw-r--r-- | clang/lib/AST/ASTContext.cpp | 37 |
1 files changed, 28 insertions, 9 deletions
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index 29bca29f230..017d09d265a 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -2785,7 +2785,7 @@ QualType::GCAttrTypes ASTContext::getObjCGCAttrKind(const QualType &Ty) const { } // Non-pointers have none gc'able attribute regardless of the attribute // set on them. - else if (!isObjCObjectPointerType(Ty) && !Ty->isPointerType()) + else if (!Ty->isPointerType() && !isObjCObjectPointerType(Ty)) return QualType::GCNone; } return GCAttrs; @@ -3033,26 +3033,45 @@ QualType ASTContext::mergeTypes(QualType LHS, QualType RHS) { if (RHSClass == Type::ExtQual) { QualType::GCAttrTypes GCAttr = RHSCan.getObjCGCAttr(); if (GCAttr != QualType::GCNone) { + // __weak attribute must appear on both declarations. + // FIXME. __strong attribue is redundant if other decl is an objective-c + // object pointer (or decorated with __strong attribute). We can't issue + // diagnostic on __strong mismatch becuase 'id' may not be + // available but only with its canonical type at this point. Will + // visit this when 'id' becomes a concrete type. + if (GCAttr == QualType::Weak && LHSCan.getObjCGCAttr() != GCAttr) + return QualType(); + RHS = QualType(cast<ExtQualType>(RHS.getDesugaredType())->getBaseType(), RHS.getCVRQualifiers()); QualType Result = mergeTypes(LHS, RHS); - if (Result.getObjCGCAttr() == QualType::GCNone) - Result = getObjCGCQualType(Result, GCAttr); - else if (Result.getObjCGCAttr() != GCAttr) - Result = QualType(); + if (!Result.isNull()) { + if (Result.getObjCGCAttr() == QualType::GCNone) + Result = getObjCGCQualType(Result, GCAttr); + else if (Result.getObjCGCAttr() != GCAttr) + Result = QualType(); + } return Result; } } if (LHSClass == Type::ExtQual) { QualType::GCAttrTypes GCAttr = LHSCan.getObjCGCAttr(); if (GCAttr != QualType::GCNone) { + QualType::GCAttrTypes GCRHSAttr = RHSCan.getObjCGCAttr(); + // __weak attribute must appear on both declarations. __strong + // attribue is redundant if other decl is an objective-c object pointer. + // See above FIXME comment. + if (GCAttr == QualType::Weak && GCRHSAttr != GCAttr) + return QualType(); LHS = QualType(cast<ExtQualType>(LHS.getDesugaredType())->getBaseType(), LHS.getCVRQualifiers()); QualType Result = mergeTypes(LHS, RHS); - if (Result.getObjCGCAttr() == QualType::GCNone) - Result = getObjCGCQualType(Result, GCAttr); - else if (Result.getObjCGCAttr() != GCAttr) - Result = QualType(); + if (!Result.isNull()) { + if (Result.getObjCGCAttr() == QualType::GCNone) + Result = getObjCGCQualType(Result, GCAttr); + else if (Result.getObjCGCAttr() != GCAttr) + Result = QualType(); + } return Result; } } |

