[cfe-commits] r173708 - Forbid the use of objects in unions in Objective-C++ ARC. Fixes
Jordan Rose
jordan_rose at apple.com
Mon Jan 28 11:12:50 PST 2013
I find the new warning text much more confusing…it makes it sound like a different type would be allowed. (Yes, I know __unsafe_unretained would work. That still doesn't help.)
> struct S {
> - A* a; // expected-error {{ARC forbids Objective-C objects in structs or unions}}
> + A* a; // expected-error {{ARC forbids Objective-C objects of type 'A *__strong' in struct}}
> };
On Jan 28, 2013, at 11:08 , Douglas Gregor <dgregor at apple.com> wrote:
> Author: dgregor
> Date: Mon Jan 28 13:08:09 2013
> New Revision: 173708
>
> URL: http://llvm.org/viewvc/llvm-project?rev=173708&view=rev
> Log:
> Forbid the use of objects in unions in Objective-C++ ARC. Fixes
> <rdar://problem/13098104>.
>
> Modified:
> cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> cfe/trunk/lib/Sema/SemaDecl.cpp
> cfe/trunk/test/ARCMT/checking.m
> cfe/trunk/test/SemaObjC/arc-decls.m
>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=173708&r1=173707&r2=173708&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Jan 28 13:08:09 2013
> @@ -3696,8 +3696,9 @@ def err_arc_mismatched_cast : Error<
> " to %3 is disallowed with ARC">;
> def err_arc_nolifetime_behavior : Error<
> "explicit ownership qualifier on cast result has no effect">;
> -def err_arc_objc_object_in_struct : Error<
> - "ARC forbids %select{Objective-C objects|blocks}0 in structs or unions">;
> +def err_arc_objc_object_in_tag : Error<
> + "ARC forbids %select{Objective-C objects|blocks}0 of type %1 in "
> + "%select{struct|interface|union|<<ERROR>>|enum}2">;
> def err_arc_objc_property_default_assign_on_object : Error<
> "ARC forbids synthesizing a property of an Objective-C object "
> "with unspecified ownership or storage attribute">;
>
> Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=173708&r1=173707&r2=173708&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Jan 28 13:08:09 2013
> @@ -10498,44 +10498,42 @@ void Sema::ActOnFields(Scope* S,
> << FixItHint::CreateInsertion(FD->getLocation(), "*");
> QualType T = Context.getObjCObjectPointerType(FD->getType());
> FD->setType(T);
> - } else if (!getLangOpts().CPlusPlus) {
> - if (getLangOpts().ObjCAutoRefCount && Record && !ARCErrReported) {
> - // It's an error in ARC if a field has lifetime.
> - // We don't want to report this in a system header, though,
> - // so we just make the field unavailable.
> - // FIXME: that's really not sufficient; we need to make the type
> - // itself invalid to, say, initialize or copy.
> - QualType T = FD->getType();
> - Qualifiers::ObjCLifetime lifetime = T.getObjCLifetime();
> - if (lifetime && lifetime != Qualifiers::OCL_ExplicitNone) {
> - SourceLocation loc = FD->getLocation();
> - if (getSourceManager().isInSystemHeader(loc)) {
> - if (!FD->hasAttr<UnavailableAttr>()) {
> - FD->addAttr(new (Context) UnavailableAttr(loc, Context,
> - "this system field has retaining ownership"));
> - }
> - } else {
> - Diag(FD->getLocation(), diag::err_arc_objc_object_in_struct)
> - << T->isBlockPointerType();
> + } else if (getLangOpts().ObjCAutoRefCount && Record && !ARCErrReported &&
> + (!getLangOpts().CPlusPlus || Record->isUnion())) {
> + // It's an error in ARC if a field has lifetime.
> + // We don't want to report this in a system header, though,
> + // so we just make the field unavailable.
> + // FIXME: that's really not sufficient; we need to make the type
> + // itself invalid to, say, initialize or copy.
> + QualType T = FD->getType();
> + Qualifiers::ObjCLifetime lifetime = T.getObjCLifetime();
> + if (lifetime && lifetime != Qualifiers::OCL_ExplicitNone) {
> + SourceLocation loc = FD->getLocation();
> + if (getSourceManager().isInSystemHeader(loc)) {
> + if (!FD->hasAttr<UnavailableAttr>()) {
> + FD->addAttr(new (Context) UnavailableAttr(loc, Context,
> + "this system field has retaining ownership"));
> }
> - ARCErrReported = true;
> + } else {
> + Diag(FD->getLocation(), diag::err_arc_objc_object_in_tag)
> + << T->isBlockPointerType() << T << Record->getTagKind();
> }
> + ARCErrReported = true;
> }
> - else if (getLangOpts().ObjC1 &&
> + } else if (getLangOpts().ObjC1 &&
> getLangOpts().getGC() != LangOptions::NonGC &&
> Record && !Record->hasObjectMember()) {
> - if (FD->getType()->isObjCObjectPointerType() ||
> - FD->getType().isObjCGCStrong())
> + if (FD->getType()->isObjCObjectPointerType() ||
> + FD->getType().isObjCGCStrong())
> + Record->setHasObjectMember(true);
> + else if (Context.getAsArrayType(FD->getType())) {
> + QualType BaseType = Context.getBaseElementType(FD->getType());
> + if (BaseType->isRecordType() &&
> + BaseType->getAs<RecordType>()->getDecl()->hasObjectMember())
> Record->setHasObjectMember(true);
> - else if (Context.getAsArrayType(FD->getType())) {
> - QualType BaseType = Context.getBaseElementType(FD->getType());
> - if (BaseType->isRecordType() &&
> - BaseType->getAs<RecordType>()->getDecl()->hasObjectMember())
> - Record->setHasObjectMember(true);
> - else if (BaseType->isObjCObjectPointerType() ||
> - BaseType.isObjCGCStrong())
> - Record->setHasObjectMember(true);
> - }
> + else if (BaseType->isObjCObjectPointerType() ||
> + BaseType.isObjCGCStrong())
> + Record->setHasObjectMember(true);
> }
> }
> if (Record && FD->getType().isVolatileQualified())
>
> Modified: cfe/trunk/test/ARCMT/checking.m
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/checking.m?rev=173708&r1=173707&r2=173708&view=diff
> ==============================================================================
> --- cfe/trunk/test/ARCMT/checking.m (original)
> +++ cfe/trunk/test/ARCMT/checking.m Mon Jan 28 13:08:09 2013
> @@ -117,7 +117,7 @@ void test1(A *a, BOOL b, struct UnsafeS
> }
>
> struct S {
> - A* a; // expected-error {{ARC forbids Objective-C objects in structs or unions}}
> + A* a; // expected-error {{ARC forbids Objective-C objects of type 'A *__strong' in struct}}
> };
>
> @interface B
>
> Modified: cfe/trunk/test/SemaObjC/arc-decls.m
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/arc-decls.m?rev=173708&r1=173707&r2=173708&view=diff
> ==============================================================================
> --- cfe/trunk/test/SemaObjC/arc-decls.m (original)
> +++ cfe/trunk/test/SemaObjC/arc-decls.m Mon Jan 28 13:08:09 2013
> @@ -3,17 +3,17 @@
> // rdar://8843524
>
> struct A {
> - id x; // expected-error {{ARC forbids Objective-C objects in structs or unions}}
> + id x; // expected-error {{ARC forbids Objective-C objects of type '__strong id' in struct}}
> };
>
> union u {
> - id u; // expected-error {{ARC forbids Objective-C objects in structs or unions}}
> + id u; // expected-error {{ARC forbids Objective-C objects of type '__strong id' in union}}
> };
>
> @interface I {
> struct A a;
> struct B {
> - id y[10][20]; // expected-error {{ARC forbids Objective-C objects in structs or unions}}
> + id y[10][20]; // expected-error {{ARC forbids Objective-C objects}}
> id z;
> } b;
>
> @@ -23,7 +23,7 @@ union u {
>
> // rdar://10260525
> struct r10260525 {
> - id (^block) (); // expected-error {{ARC forbids blocks in structs or unions}}
> + id (^block) (); // expected-error {{ARC forbids blocks of type 'id (^__strong)()' in struct}}
> };
>
> struct S {
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130128/a9a5b162/attachment.html>
More information about the cfe-commits
mailing list