summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2011-11-04 20:37:24 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2011-11-04 20:37:24 +0000
commitd979df9e185bc5f727934a583dc376f8ab7ad1d1 (patch)
tree9a404653d1e47b77795ce9e87c138c69c6623afb /clang/lib/Sema
parentc2a8401ad2b69cab258695643b3911af3ccba3c8 (diff)
downloadbcm5719-llvm-d979df9e185bc5f727934a583dc376f8ab7ad1d1.tar.gz
bcm5719-llvm-d979df9e185bc5f727934a583dc376f8ab7ad1d1.zip
In ARC, when applying an ownership to a non-objc pointer, instead of ignoring it
create an attributed type with same type as the original type. We effectively retain the source info that an ownership attribute was present but the attribute is ignored by not modifying the type that it was applied to. llvm-svn: 143736
Diffstat (limited to 'clang/lib/Sema')
-rw-r--r--clang/lib/Sema/SemaType.cpp34
1 files changed, 31 insertions, 3 deletions
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 09d47e8e179..219a9e8a308 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -3258,8 +3258,21 @@ static void HandleAddressSpaceTypeAttribute(QualType &Type,
static bool handleObjCOwnershipTypeAttr(TypeProcessingState &state,
AttributeList &attr,
QualType &type) {
- if (!type->isObjCRetainableType() && !type->isDependentType())
- return false;
+ bool NonObjCPointer = false;
+
+ if (!type->isDependentType()) {
+ if (const PointerType *ptr = type->getAs<PointerType>()) {
+ QualType pointee = ptr->getPointeeType();
+ if (pointee->isObjCRetainableType() || pointee->isPointerType())
+ return false;
+ // It is important not to lose the source info that there was an attribute
+ // applied to non-objc pointer. We will create an attributed type but
+ // its type will be the same as the original type.
+ NonObjCPointer = true;
+ } else if (!type->isObjCRetainableType()) {
+ return false;
+ }
+ }
Sema &S = state.getSema();
SourceLocation AttrLoc = attr.getLoc();
@@ -3300,10 +3313,25 @@ static bool handleObjCOwnershipTypeAttr(TypeProcessingState &state,
if (!S.getLangOptions().ObjCAutoRefCount)
return true;
+ if (NonObjCPointer) {
+ StringRef name = attr.getName()->getName();
+ switch (lifetime) {
+ case Qualifiers::OCL_None:
+ case Qualifiers::OCL_ExplicitNone:
+ break;
+ case Qualifiers::OCL_Strong: name = "__strong"; break;
+ case Qualifiers::OCL_Weak: name = "__weak"; break;
+ case Qualifiers::OCL_Autoreleasing: name = "__autoreleasing"; break;
+ }
+ S.Diag(AttrLoc, diag::warn_objc_object_attribute_wrong_type)
+ << name << type;
+ }
+
Qualifiers qs;
qs.setObjCLifetime(lifetime);
QualType origType = type;
- type = S.Context.getQualifiedType(type, qs);
+ if (!NonObjCPointer)
+ type = S.Context.getQualifiedType(type, qs);
// If we have a valid source location for the attribute, use an
// AttributedType instead.
OpenPOWER on IntegriCloud