[cfe-commits] r131065 - in /cfe/trunk: include/clang/AST/Type.h lib/Sema/SemaOverload.cpp test/SemaObjC/gc-attributes.m test/SemaObjCXX/gc-attributes.mm test/SemaObjCXX/overload-gc.mm
Douglas Gregor
dgregor at apple.com
Sat May 7 23:09:53 PDT 2011
Author: dgregor
Date: Sun May 8 01:09:53 2011
New Revision: 131065
URL: http://llvm.org/viewvc/llvm-project?rev=131065&view=rev
Log:
Relax the conversion rules for Objective-C GC qualifiers a
bit by allowing __weak and __strong to be added/dropped as part of
implicit conversions (qualification conversions in C++). A little
history: GCC lets one add/remove/change GC qualifiers just about
anywhere, implicitly. Clang did roughly the same before, but we
recently normalized the semantics of qualifiers across the board to
get a semantics that we could reason about (yay). Unfortunately, this
tightened the screws a bit too much for GC qualifiers, where it's
common to add/remove these qualifiers at will.
Overall, we're still in better shape than we were before: we don't
permit directly changing the GC qualifier (e.g., __weak -> __strong),
so type safety is improved. More importantly, we're internally
consistent in our handling of qualifiers, and the logic that allows
adding/removing GC qualifiers (but not adding/removing address
spaces!) only touches two obvious places.
Fixes <rdar://problem/9402499>.
Added:
cfe/trunk/test/SemaObjC/gc-attributes.m
cfe/trunk/test/SemaObjCXX/gc-attributes.mm
Modified:
cfe/trunk/include/clang/AST/Type.h
cfe/trunk/lib/Sema/SemaOverload.cpp
cfe/trunk/test/SemaObjCXX/overload-gc.mm
Modified: cfe/trunk/include/clang/AST/Type.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=131065&r1=131064&r2=131065&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Sun May 8 01:09:53 2011
@@ -294,9 +294,15 @@
/// Generally this answers the question of whether an object with the other
/// qualifiers can be safely used as an object with these qualifiers.
bool compatiblyIncludes(Qualifiers other) const {
- // Non-CVR qualifiers must match exactly. CVR qualifiers may subset.
- return ((Mask & ~CVRMask) == (other.Mask & ~CVRMask)) &&
- (((Mask & CVRMask) | (other.Mask & CVRMask)) == (Mask & CVRMask));
+ return
+ // Address spaces must match exactly.
+ getAddressSpace() == other.getAddressSpace() &&
+ // ObjC GC qualifiers can match, be added, or be removed, but can't be
+ // changed.
+ (getObjCGCAttr() == other.getObjCGCAttr() ||
+ !hasObjCGCAttr() || !other.hasObjCGCAttr()) &&
+ // CVR qualifiers may subset.
+ (((Mask & CVRMask) | (other.Mask & CVRMask)) == (Mask & CVRMask));
}
/// \brief Determine whether this set of qualifiers is a strict superset of
Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=131065&r1=131064&r2=131065&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Sun May 8 01:09:53 2011
@@ -2197,6 +2197,13 @@
Qualifiers FromQuals = FromType.getQualifiers();
Qualifiers ToQuals = ToType.getQualifiers();
+ // Allow addition/removal of GC attributes but not changing GC attributes.
+ if (FromQuals.getObjCGCAttr() != ToQuals.getObjCGCAttr() &&
+ (!FromQuals.hasObjCGCAttr() || !ToQuals.hasObjCGCAttr())) {
+ FromQuals.removeObjCGCAttr();
+ ToQuals.removeObjCGCAttr();
+ }
+
// -- for every j > 0, if const is in cv 1,j then const is in cv
// 2,j, and similarly for volatile.
if (!CStyle && !ToQuals.compatiblyIncludes(FromQuals))
Added: cfe/trunk/test/SemaObjC/gc-attributes.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/gc-attributes.m?rev=131065&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjC/gc-attributes.m (added)
+++ cfe/trunk/test/SemaObjC/gc-attributes.m Sun May 8 01:09:53 2011
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-gc -fsyntax-only -verify %s
+
+ at interface A
+ at end
+
+void f0(__strong A**); // expected-note{{passing argument to parameter here}}
+
+void test_f0() {
+ A *a;
+ static __weak A *a2;
+ f0(&a);
+ f0(&a2); // expected-warning{{passing 'A *__weak *' to parameter of type 'A *__strong *' discards qualifiers}}
+}
+
+void f1(__weak A**); // expected-note{{passing argument to parameter here}}
+
+void test_f1() {
+ A *a;
+ __strong A *a2;
+ f1(&a);
+ f1(&a2); // expected-warning{{passing 'A *__strong *' to parameter of type 'A *__weak *' discards qualifiers}}
+}
Added: cfe/trunk/test/SemaObjCXX/gc-attributes.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/gc-attributes.mm?rev=131065&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjCXX/gc-attributes.mm (added)
+++ cfe/trunk/test/SemaObjCXX/gc-attributes.mm Sun May 8 01:09:53 2011
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-gc -fsyntax-only -verify %s
+
+ at interface A
+ at end
+
+void f0(__strong A**); // expected-note{{candidate function not viable: 1st argument ('A *__weak *') has __weak lifetime, but parameter has __strong lifetime}}
+
+void test_f0() {
+ A *a;
+ static __weak A *a2;
+ f0(&a);
+ f0(&a2); // expected-error{{no matching function}}
+}
+
+void f1(__weak A**); // expected-note{{candidate function not viable: 1st argument ('A *__strong *') has __strong lifetime, but parameter has __weak lifetime}}
+
+void test_f1() {
+ A *a;
+ __strong A *a2;
+ f1(&a);
+ f1(&a2); // expected-error{{no matching function}}
+}
Modified: cfe/trunk/test/SemaObjCXX/overload-gc.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/overload-gc.mm?rev=131065&r1=131064&r2=131065&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjCXX/overload-gc.mm (original)
+++ cfe/trunk/test/SemaObjCXX/overload-gc.mm Sun May 8 01:09:53 2011
@@ -1,9 +1,9 @@
// RUN: %clang_cc1 -fsyntax-only -triple i386-apple-darwin9 -fobjc-gc -verify %s
-void f0(__weak id *); // expected-note{{candidate function not viable: 1st argument ('id *') has no lifetime, but parameter has __weak lifetime}}
+void f0(__weak id *);
void test_f0(id *x) {
- f0(x); // expected-error{{no matching function for call to 'f0'}}
+ f0(x);
}
@interface A
More information about the cfe-commits
mailing list