For __weak/__strong/etc. ownership attributes, don't macro expand them in diagnostics.

llvm-svn: 140711
This commit is contained in:
Argyrios Kyrtzidis 2011-09-28 18:35:06 +00:00
parent c0f53df8ff
commit 83c337d600
1 changed files with 11 additions and 7 deletions

View File

@ -3142,15 +3142,18 @@ static bool handleObjCOwnershipTypeAttr(TypeProcessingState &state,
return false; return false;
Sema &S = state.getSema(); Sema &S = state.getSema();
SourceLocation AttrLoc = attr.getLoc();
if (AttrLoc.isMacroID())
AttrLoc = S.getSourceManager().getImmediateExpansionRange(AttrLoc).first;
if (type.getQualifiers().getObjCLifetime()) { if (type.getQualifiers().getObjCLifetime()) {
S.Diag(attr.getLoc(), diag::err_attr_objc_ownership_redundant) S.Diag(AttrLoc, diag::err_attr_objc_ownership_redundant)
<< type; << type;
return true; return true;
} }
if (!attr.getParameterName()) { if (!attr.getParameterName()) {
S.Diag(attr.getLoc(), diag::err_attribute_argument_n_not_string) S.Diag(AttrLoc, diag::err_attribute_argument_n_not_string)
<< "objc_ownership" << 1; << "objc_ownership" << 1;
attr.setInvalid(); attr.setInvalid();
return true; return true;
@ -3166,7 +3169,7 @@ static bool handleObjCOwnershipTypeAttr(TypeProcessingState &state,
else if (attr.getParameterName()->isStr("autoreleasing")) else if (attr.getParameterName()->isStr("autoreleasing"))
lifetime = Qualifiers::OCL_Autoreleasing; lifetime = Qualifiers::OCL_Autoreleasing;
else { else {
S.Diag(attr.getLoc(), diag::warn_attribute_type_not_supported) S.Diag(AttrLoc, diag::warn_attribute_type_not_supported)
<< "objc_ownership" << attr.getParameterName(); << "objc_ownership" << attr.getParameterName();
attr.setInvalid(); attr.setInvalid();
return true; return true;
@ -3184,7 +3187,7 @@ static bool handleObjCOwnershipTypeAttr(TypeProcessingState &state,
// If we have a valid source location for the attribute, use an // If we have a valid source location for the attribute, use an
// AttributedType instead. // AttributedType instead.
if (attr.getLoc().isValid()) if (AttrLoc.isValid())
type = S.Context.getAttributedType(AttributedType::attr_objc_ownership, type = S.Context.getAttributedType(AttributedType::attr_objc_ownership,
origType, type); origType, type);
@ -3195,10 +3198,11 @@ static bool handleObjCOwnershipTypeAttr(TypeProcessingState &state,
// Actually, delay this until we know what we're parsing. // Actually, delay this until we know what we're parsing.
if (S.DelayedDiagnostics.shouldDelayDiagnostics()) { if (S.DelayedDiagnostics.shouldDelayDiagnostics()) {
S.DelayedDiagnostics.add( S.DelayedDiagnostics.add(
sema::DelayedDiagnostic::makeForbiddenType(attr.getLoc(), sema::DelayedDiagnostic::makeForbiddenType(
S.getSourceManager().getExpansionLoc(AttrLoc),
diag::err_arc_weak_no_runtime, type, /*ignored*/ 0)); diag::err_arc_weak_no_runtime, type, /*ignored*/ 0));
} else { } else {
S.Diag(attr.getLoc(), diag::err_arc_weak_no_runtime); S.Diag(AttrLoc, diag::err_arc_weak_no_runtime);
} }
attr.setInvalid(); attr.setInvalid();
@ -3214,7 +3218,7 @@ static bool handleObjCOwnershipTypeAttr(TypeProcessingState &state,
if (const ObjCObjectPointerType *ObjT = T->getAs<ObjCObjectPointerType>()) { if (const ObjCObjectPointerType *ObjT = T->getAs<ObjCObjectPointerType>()) {
ObjCInterfaceDecl *Class = ObjT->getInterfaceDecl(); ObjCInterfaceDecl *Class = ObjT->getInterfaceDecl();
if (Class->isArcWeakrefUnavailable()) { if (Class->isArcWeakrefUnavailable()) {
S.Diag(attr.getLoc(), diag::err_arc_unsupported_weak_class); S.Diag(AttrLoc, diag::err_arc_unsupported_weak_class);
S.Diag(ObjT->getInterfaceDecl()->getLocation(), S.Diag(ObjT->getInterfaceDecl()->getLocation(),
diag::note_class_declared); diag::note_class_declared);
} }