Commit Graph

199 Commits

Author SHA1 Message Date
John McCall 4124c4924d Teach the ARC compiler to not require __bridge casts when
passing/receiving CF objects at +0 to/from Objective-C methods
or audited C functions.

llvm-svn: 142219
2011-10-17 18:40:02 +00:00
Douglas Gregor f1404d7d49 Under ARC, merge the bit corresponding to the ns_returns_retained
attribute from the first declaration to later declarations. Fixes
<rdar://problem/10142572>.

llvm-svn: 141957
2011-10-14 15:55:40 +00:00
Richard Smith 9ca5c42582 Update all tests other than Driver/std.cpp to use -std=c++11 rather than
-std=c++0x. Patch by Ahmed Charles!

llvm-svn: 141900
2011-10-13 22:29:44 +00:00
Douglas Gregor bcc9539323 Don't complain about qualified property or ivar access when the
qualifier itself is invalid. Crasher noticed by Fariborz.

llvm-svn: 141544
2011-10-10 16:09:49 +00:00
Douglas Gregor 12340e5b18 Diagnose attempts to qualify the name of an instance variable or
property in an Objective-C++ member access expression. Fixes PR9759.

llvm-svn: 141522
2011-10-09 23:22:49 +00:00
Fariborz Jahanian 13d3f86577 objc++: some minor cleanup and a test case
for atomic setters which requires assignment operator.

llvm-svn: 141415
2011-10-07 21:08:14 +00:00
Fariborz Jahanian 565ed7a4c1 objc++: For atomic properties of c++ class objec typet, appropriate
operator= is called. Issue a warning for non-trivial case until
runtime support is provided. // rdar://6137845

llvm-svn: 141302
2011-10-06 18:38:18 +00:00
John McCall 9b0a7cea0f Make -fobjc-nonfragile-abi the -cc1 default, since it's the
increasingly prevailing case to the point that new features
like ARC don't even support the fragile ABI anymore.

This required a little bit of reshuffling with exceptions
because a check was assuming that ObjCNonFragileABI was
only being set in ObjC mode, and that's actually a bit
obnoxious to do.

Most, though, it involved a perl script to translate a ton
of test cases.

Mostly no functionality change for driver users, although
there are corner cases with disabling language-specific
exceptions that we should handle more correctly now.

llvm-svn: 140957
2011-10-02 01:16:38 +00:00
Fariborz Jahanian 600ba208ab objc++ arc: Diagnose block pointer type mismatch when
some arguments types are ns_consumed and some otherwise
matching types are not. This fixes the objc++ side only *auch*.
// rdar://10187884

llvm-svn: 140717
2011-09-28 20:22:05 +00:00
Douglas Gregor eaed8d57dd Remove the egregious hack that made Objective-C++ ARC work with older
versions of libc++. Newer versions of libc++ know how to deal with ARC
properly. Fixes <rdar://problem/10062179>.

llvm-svn: 140651
2011-09-27 22:48:19 +00:00
Fariborz Jahanian 11ee283e2a objc - redeclaration of property in extension class
must match property type declaration in its
primary class. // rdar://10142679

llvm-svn: 140438
2011-09-24 00:56:59 +00:00
John McCall fa6f5d6ab8 Don't assert when diagnosing a missing cast of an unknown-anytype
message send to an unknown method.

rdar://problem/9416370, redux.

llvm-svn: 138893
2011-08-31 20:57:36 +00:00
Fariborz Jahanian 371376010f objc - fix a bug exposed by my recent decl context
changes. // rdar://10015110

llvm-svn: 138594
2011-08-25 22:26:53 +00:00
Douglas Gregor a4f2b430e0 Objective-C++ ARC: When performing template argument deduction for a
lifetime-qualified template parameter, ensure that the deduced
template argument is a lifetime type. Fixes <rdar://problem/9828157>.

llvm-svn: 136078
2011-07-26 14:53:44 +00:00
Fariborz Jahanian a644f9cb73 arc-objc++: Issue an arc specific diagnostic when overload resolution
fails because of lifetime differences of parameter and argument type.
// rdar://9790531

llvm-svn: 135593
2011-07-20 17:14:09 +00:00
Fariborz Jahanian 17585e7940 objc++: Some level of covariance is allowed in ObjC properties.
Make it also available in ObjC++ propeties. Use common code for
objc and objc++ so they don't diverge. // rdar://9740328

llvm-svn: 135050
2011-07-13 17:55:01 +00:00
Fariborz Jahanian c87c8799ec revert fix for // rdar://9740328
llvm-svn: 135010
2011-07-12 23:20:13 +00:00
Fariborz Jahanian c0f6af2103 objc++: Some level of covariance is allowed in ObjC properties.
Make it also available in ObjC++ propeties. // rdar://9740328

llvm-svn: 135001
2011-07-12 22:05:16 +00:00
Douglas Gregor 7e6bfb4a0d In ARC mode, consider Objective-C lifetime types (object pointers and
block pointers) that don't have any qualification to be POD types. We
were previously considering them to be non-POD types, because this was
convenient in C++ for is_pod-like traits. However, we now end up
inferring lifetime in such cases (template arguments infer __strong),
so it is not necessary.

Moreover, we want rvalues of object type (which have their lifetime
stripped) to be PODs to allow, e.g., va_arg(arglist, id) to function
properly. Fixes <rdar://problem/9758798>.

llvm-svn: 134993
2011-07-12 17:28:52 +00:00
Fariborz Jahanian f2913401fc objc++-arc: more diagnosis of converting a weak-unavailable
object to a __weak object type. // rdar://9732636

llvm-svn: 134706
2011-07-08 17:41:42 +00:00
Fariborz Jahanian 7fcce6829d objc++-arc: diagnose assignment/cast of a weak-unavailable
object to a __weak object/type. // rdar://9732636.
One item is yet todo.

llvm-svn: 134655
2011-07-07 23:04:17 +00:00
John McCall 24fc0decfe Change the driver's logic about Objective-C runtimes: abstract out a
structure to hold inferred information, then propagate each invididual
bit down to -cc1.  Separate the bits of "supports weak" and "has a native
ARC runtime";  make the latter a CodeGenOption.

The tool chain is still driving this decision, because it's the place that
has the required deployment target information on Darwin, but at least it's
better-factored now.

llvm-svn: 134453
2011-07-06 00:26:06 +00:00
Argyrios Kyrtzidis 8e25253e14 -Fix mistake in ASTContext::getInnerObjCOwnership noticed by Doug
-Remove unnecessary 'return'.
-Remove unnecessary 'if' check (llvm_unreachable make sure attrStr will be non-null)
-Add a test of transferring ownership to a reference cast type.

llvm-svn: 134285
2011-07-01 23:01:46 +00:00
Argyrios Kyrtzidis ea57a9be17 Fix assertion hit in inferARCWriteback.
llvm-svn: 134276
2011-07-01 22:23:03 +00:00
Argyrios Kyrtzidis 7192a3b841 [ARC] When casting from a pointer to an objective-c object with known ownership, if the
cast type has no ownership specified, implicitly "transfer" the ownership of the cast'ed type
to the cast type:

id x;
(NSString**)&x; // Casting as (__strong NSString**).

llvm-svn: 134275
2011-07-01 22:22:59 +00:00
Argyrios Kyrtzidis 7451d1cd00 [ARC] When casting from a pointer to an objective-c object with known ownership, if the
cast type has no ownership specified, implicitly "transfer" the ownership of the cast'ed type
to the cast type:

id x;
static_cast<NSString**>(&x); // Casting as (__strong NSString**).

This currently only works for C++ named casts, C casts to follow.

llvm-svn: 134273
2011-07-01 22:22:50 +00:00
Argyrios Kyrtzidis 774506918c Introduce Declarator::ObjCCatchContext, this will result in correct error for 'auto' in obj-c catch.
llvm-svn: 134271
2011-07-01 22:22:40 +00:00
John McCall 63f844494d ARC writeback isn't supposed to apply to local indirect pointers,
only to pointers to locals.  But it should work inside blocks, too.

llvm-svn: 133969
2011-06-27 23:59:58 +00:00
Argyrios Kyrtzidis cff00d9c12 Rename objc_lifetime -> objc_ownership, and modify diagnostics to talk about 'ownership', not 'lifetime'.
rdar://9477613.

llvm-svn: 133779
2011-06-24 00:08:59 +00:00
Fariborz Jahanian 08e17b506e Improve on warning when objc pointer is used in
c++ catch in fragile abi - per Eli's request.

llvm-svn: 133760
2011-06-23 21:17:59 +00:00
Fariborz Jahanian 831f0fc2e0 Support for catching objc pointer objects in c++ catch-statement
in fragile abi mode and some other cleanups. // rdar://8940528

llvm-svn: 133747
2011-06-23 19:00:08 +00:00
Douglas Gregor d7357a9b8e Objective-C++ ARC: eliminate the utterly unjustified loophole that
silently dropped ownership qualifiers that were being applied to
ownership-qualified, substituted type that was *not* a substituted
template type parameter. We now provide a diagnostic in such cases,
and recover by dropping the added qualifiers.

Document this behavior in the ARC specification.

llvm-svn: 133309
2011-06-17 23:16:24 +00:00
Douglas Gregor e46db90c9a Objective-ARC++: infer template type arguments of
ownership-unqualified retainable object type as __strong. This allows
us to write, e.g.,

  std::vector<id>

and we'll infer that the vector's element types have __strong
ownership semantics, which is far nicer than requiring:

  std::vector<__strong id>

Note that we allow one to override the ownership qualifier of a
substituted template type parameter, e.g., given

  template<typename T>
  struct X {
    typedef __weak T type;
  };

X<id> is treated the same as X<__strong id>. At instantiation type,
the __weak in "__weak T" overrides the (inferred or specified)
__strong on the template argument type, so that we can still provide
metaprogramming transformations.

This is part of <rdar://problem/9595486>.

llvm-svn: 133303
2011-06-17 22:11:49 +00:00
Richard Trieu fc51bc1cea Put the new warning from revision 133196 on NULL arithmetic behind the flag -Wnull-arthimetic and set to DefaultIgnore. A few edge cases need to be worked out before this can be set to default.
llvm-svn: 133287
2011-06-17 20:35:48 +00:00
Richard Trieu 701fb36b95 Add a new warning when a NULL constant is used in arithmetic operations. The warning will fire on cases such as:
int x = 1 + NULL;

llvm-svn: 133196
2011-06-16 21:36:56 +00:00
Douglas Gregor 3e85c9c561 Allow comparison between block pointers and NULL pointer
constants. Fixes PR10145.

llvm-svn: 133179
2011-06-16 18:52:05 +00:00
John McCall 31168b077c Automatic Reference Counting.
Language-design credit goes to a lot of people, but I particularly want
to single out Blaine Garst and Patrick Beard for their contributions.

Compiler implementation credit goes to Argyrios, Doug, Fariborz, and myself,
in no particular order.

llvm-svn: 133103
2011-06-15 23:02:42 +00:00
Douglas Gregor c9224d6714 Eliminate the -f[no]objc-infer-related-result-type flags; there's no
reason to allow the user to control these semantics through a flag.

llvm-svn: 132919
2011-06-13 16:42:53 +00:00
Douglas Gregor 53cad081e3 Extra test for related result type inference
llvm-svn: 132874
2011-06-11 04:42:58 +00:00
Douglas Gregor 2720dc656b Fix order of operands for the warning about incompatible Objective-C
pointer assignment in C++. This was a longstanding problem spotted by
Jordy Rose.

llvm-svn: 132873
2011-06-11 04:42:12 +00:00
Douglas Gregor 33823727c8 Implement Objective-C Related Result Type semantics.
Related result types apply Cocoa conventions to the type of message
sends and property accesses to Objective-C methods that are known to
always return objects whose type is the same as the type of the
receiving class (or a subclass thereof), such as +alloc and
-init. This tightens up static type safety for Objective-C, so that we
now diagnose mistakes like this:

t.m:4:10: warning: incompatible pointer types initializing 'NSSet *'
with an
      expression of type 'NSArray *' [-Wincompatible-pointer-types]
  NSSet *array = [[NSArray alloc] init];
         ^       ~~~~~~~~~~~~~~~~~~~~~~
/System/Library/Frameworks/Foundation.framework/Headers/NSObject.h:72:1:
note: 
      instance method 'init' is assumed to return an instance of its
      receiver
      type ('NSArray *')
- (id)init;
^

It also means that we get decent type inference when writing code in
Objective-C++0x:

  auto array = [[NSMutableArray alloc] initWithObjects:@"one",  @"two",nil];
  //    ^ now infers NSMutableArray* rather than id

llvm-svn: 132868
2011-06-11 01:09:30 +00:00
Douglas Gregor 7f139d8103 Allow block returns in C++ with the form
return <expression> ;

in blocks with a 'void' result type, so long as <expression> has type
'void'. This follows the rules for C++ functions.

llvm-svn: 132658
2011-06-05 05:14:41 +00:00
Douglas Gregor 39e9fa938c Implement comparisons between nullptr and Objective-C object
pointers. Fixes PR10052.

llvm-svn: 132397
2011-06-01 15:12:24 +00:00
Douglas Gregor f30053d18d 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>.

llvm-svn: 131065
2011-05-08 06:09:53 +00:00
Douglas Gregor b578fbe0f2 When checking for a prior declaration of the name of a namespace, skip
any names that aren't in the appropriate identifier namespaces. Fixes
an embarrassing bug where we give a redefinition error due to an
Objective-C category (<rdar://problem/9388207>).

llvm-svn: 131036
2011-05-06 23:28:47 +00:00
Douglas Gregor 713dab5695 Add triple in the hope of unbreaking the bubuildbot
llvm-svn: 130280
2011-04-27 03:24:57 +00:00
Douglas Gregor 30ee16f5dd When comparing Objective-C pointers during overload resolution to
determine which is a better conversion to "void*", be sure to perform
the comparison using the safe-for-id
ASTContext::canAssignObjCInterfaces() rather than the asserts-with-id
ASTContext::canAssignObjCInterfaces().

Fixes <rdar://problem/9327203>.

llvm-svn: 130259
2011-04-27 00:01:52 +00:00
Douglas Gregor aec2584760 When computing Objective-C pointer conversions in C++, retain
the qualifiers (e.g., GC qualifiers) on the type we're converting
from, rather than just blindly adopting the qualifiers of the type
we're converting to or dropping qualifiers altogether. 

As an added bonus, properly diagnose GC qualifier mismatches to
eliminate a crash in the overload resolution failure diagnostics.

llvm-svn: 130255
2011-04-26 23:16:46 +00:00
John McCall d44f4d741c Diagnose C++ abstract parameters for Objective-C methods.
llvm-svn: 130045
2011-04-23 02:46:06 +00:00
Douglas Gregor 28d1282a0f Improve test case from prior commit ever so slightly
llvm-svn: 129866
2011-04-20 18:20:33 +00:00