[cfe-commits] r134522 - in /cfe/trunk: include/clang/Basic/Attr.td include/clang/Basic/DiagnosticSemaKinds.td include/clang/Sema/AttributeList.h lib/Sema/AttributeList.cpp lib/Sema/SemaDeclAttr.cpp lib/Sema/SemaType.cpp test/SemaObjC/arc-unavailable-for-weakref.m
Fariborz Jahanian
fjahanian at apple.com
Wed Jul 6 12:24:06 PDT 2011
Author: fjahanian
Date: Wed Jul 6 14:24:05 2011
New Revision: 134522
URL: http://llvm.org/viewvc/llvm-project?rev=134522&view=rev
Log:
objc-arc: Support objc_arc_weak_unavailable on those
classes which are incompatible with weak references.
// rdar://9693477
Added:
cfe/trunk/test/SemaObjC/arc-unavailable-for-weakref.m
Modified:
cfe/trunk/include/clang/Basic/Attr.td
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Sema/AttributeList.h
cfe/trunk/lib/Sema/AttributeList.cpp
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/lib/Sema/SemaType.cpp
Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=134522&r1=134521&r2=134522&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Wed Jul 6 14:24:05 2011
@@ -484,6 +484,10 @@
let Args = [StringArgument<"Message">];
}
+def ArcWeakrefUnavailable : InheritableAttr {
+ let Spellings = ["objc_arc_weak_reference_unavailable"];
+}
+
def Unused : InheritableAttr {
let Spellings = ["unused"];
}
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=134522&r1=134521&r2=134522&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Jul 6 14:24:05 2011
@@ -357,6 +357,8 @@
"cannot declare class extension for %0 after class implementation">;
def note_implementation_declared : Note<
"class implementation is declared here">;
+def note_class_declared : Note<
+ "class is declared here">;
def warn_dup_category_def : Warning<
"duplicate definition of category %1 on interface %0">;
def err_conflicting_super_class : Error<"conflicting super class name %0">;
@@ -2568,6 +2570,8 @@
// ARC-mode diagnostics.
def err_arc_weak_no_runtime : Error<
"the current deployment target does not support automated __weak references">;
+def err_arc_unsupported_weak_class : Error<
+ "class is incompatible with __weak references">;
def err_arc_illegal_explicit_message : Error<
"ARC forbids explicit message send of %0">;
def err_arc_unused_init_message : Error<
Modified: cfe/trunk/include/clang/Sema/AttributeList.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/AttributeList.h?rev=134522&r1=134521&r2=134522&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/AttributeList.h (original)
+++ cfe/trunk/include/clang/Sema/AttributeList.h Wed Jul 6 14:24:05 2011
@@ -243,6 +243,7 @@
AT_weak,
AT_weak_import,
AT_weakref,
+ AT_arc_weakref_unavailable,
IgnoredAttribute,
UnknownAttribute
};
Modified: cfe/trunk/lib/Sema/AttributeList.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/AttributeList.cpp?rev=134522&r1=134521&r2=134522&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/AttributeList.cpp (original)
+++ cfe/trunk/lib/Sema/AttributeList.cpp Wed Jul 6 14:24:05 2011
@@ -107,6 +107,7 @@
return llvm::StringSwitch<AttributeList::Kind>(AttrName)
.Case("weak", AT_weak)
.Case("weakref", AT_weakref)
+ .Case("objc_arc_weak_reference_unavailable", AT_arc_weakref_unavailable)
.Case("pure", AT_pure)
.Case("mode", AT_mode)
.Case("used", AT_used)
Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=134522&r1=134521&r2=134522&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Wed Jul 6 14:24:05 2011
@@ -1091,6 +1091,18 @@
D->addAttr(::new (S.Context) UnavailableAttr(Attr.getLoc(), S.Context, Str));
}
+static void handleArcWeakrefUnavailableAttr(Sema &S, Decl *D,
+ const AttributeList &Attr) {
+ unsigned NumArgs = Attr.getNumArgs();
+ if (NumArgs > 0) {
+ S.Diag(Attr.getLoc(), diag::err_attribute_too_many_arguments) << 0;
+ return;
+ }
+
+ D->addAttr(::new (S.Context) ArcWeakrefUnavailableAttr(
+ Attr.getLoc(), S.Context));
+}
+
static void handleAvailabilityAttr(Sema &S, Decl *D,
const AttributeList &Attr) {
IdentifierInfo *Platform = Attr.getParameterName();
@@ -3011,6 +3023,9 @@
case AttributeList::AT_MsStruct: handleMsStructAttr (S, D, Attr); break;
case AttributeList::AT_section: handleSectionAttr (S, D, Attr); break;
case AttributeList::AT_unavailable: handleUnavailableAttr (S, D, Attr); break;
+ case AttributeList::AT_arc_weakref_unavailable:
+ handleArcWeakrefUnavailableAttr (S, D, Attr);
+ break;
case AttributeList::AT_unused: handleUnusedAttr (S, D, Attr); break;
case AttributeList::AT_used: handleUsedAttr (S, D, Attr); break;
case AttributeList::AT_visibility: handleVisibilityAttr (S, D, Attr); break;
Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=134522&r1=134521&r2=134522&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Wed Jul 6 14:24:05 2011
@@ -3207,7 +3207,30 @@
attr.setInvalid();
return true;
}
-
+
+ // Forbid __weak for class objects marked as
+ // objc_arc_weak_reference_unavailable
+ if (lifetime == Qualifiers::OCL_Weak) {
+ QualType T = type;
+ if (T->isReferenceType()) {
+ T = T->getAs<ReferenceType>()->getPointeeType();
+ }
+ while (const PointerType *ptr = T->getAs<PointerType>())
+ T = ptr->getPointeeType();
+ if (const ObjCObjectPointerType *ObjT = T->getAs<ObjCObjectPointerType>()) {
+ ObjCInterfaceDecl *Class = ObjT->getInterfaceDecl();
+ while (Class) {
+ if (Class->hasAttr<ArcWeakrefUnavailableAttr>()) {
+ S.Diag(attr.getLoc(), diag::err_arc_unsupported_weak_class);
+ S.Diag(ObjT->getInterfaceDecl()->getLocation(),
+ diag::note_class_declared);
+ break;
+ }
+ Class = Class->getSuperClass();
+ }
+ }
+ }
+
return true;
}
Added: cfe/trunk/test/SemaObjC/arc-unavailable-for-weakref.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/arc-unavailable-for-weakref.m?rev=134522&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjC/arc-unavailable-for-weakref.m (added)
+++ cfe/trunk/test/SemaObjC/arc-unavailable-for-weakref.m Wed Jul 6 14:24:05 2011
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-nonfragile-abi -fobjc-runtime-has-weak -fsyntax-only -fobjc-arc -verify %s
+// rdar://9693477
+
+__attribute__((objc_arc_weak_reference_unavailable))
+ at interface NSOptOut1072 // expected-note {{class is declared here}}
+ at end
+
+ at interface sub : NSOptOut1072 @end // expected-note 2 {{class is declared here}}
+
+int main() {
+ __weak sub *w2; // expected-error {{class is incompatible with __weak references}}
+
+ __weak NSOptOut1072 *ns1; // expected-error {{class is incompatible with __weak references}}
+
+ id obj;
+
+ ns1 = (__weak sub *)obj; // expected-error {{class is incompatible with __weak references}}
+}
More information about the cfe-commits
mailing list