Commit Graph

917 Commits

Author SHA1 Message Date
Douglas Gregor dc9166c8e1 Keep track of all declarations of an Objective-C class (both forward
declarations and definitions) as ObjCInterfaceDecls within the same
redeclaration chain. This new representation matches what we do for
C/C++ variables/functions/classes/templates/etc., and makes it
possible to answer the query "where are all of the declarations of
this class?"

llvm-svn: 146679
2011-12-15 20:29:51 +00:00
Fariborz Jahanian 9e49b6a6ff objc: do not auto synthesize properties declared in
protocols; with a warning. // rdar://10567333

llvm-svn: 146626
2011-12-15 01:03:18 +00:00
Douglas Gregor 95715f9ecf In debugger support mode, if we have a top-level message send
expression with an unknown result type, assume that the result type is
'id'. Fixes <rdar://problem/10400663>.

llvm-svn: 146622
2011-12-15 00:53:32 +00:00
Richard Trieu 553b2b2e5d Modify how the -verify flag works. Currently, the verification string and
diagnostic message are compared.  If either is a substring of the other, then
no error is given.  This gives rise to an unexpected case:

  // expect-error{{candidate function has different number of parameters}}

will match the following error messages from Clang:

  candidate function has different number of parameters (expected 1 but has 2)
  candidate function has different number of parameters

It will also match these other error messages:

  candidate function
  function has different number of parameters
  number of parameters

This patch will change so that the verification string must be a substring of
the diagnostic message before accepting.  Also, all the failing tests from this
change have been corrected.  Some stats from this cleanup:

87 - removed extra spaces around verification strings
70 - wording updates to diagnostics
40 - extra leading or trailing characters (typos, unmatched parens or quotes)
35 - diagnostic level was included (error:, warning:, or note:)
18 - flag name put in the warning (-Wprotocol)

llvm-svn: 146619
2011-12-15 00:38:15 +00:00
Fariborz Jahanian c17c86b56c objc: diagnose duplicate declaration of methods
in classes. // rdar://10535349

llvm-svn: 146504
2011-12-13 19:40:34 +00:00
Fariborz Jahanian b989e6e50a objc-arc: better diagnostic when block is declared
inside a struct/union.

llvm-svn: 146444
2011-12-12 23:17:04 +00:00
Fariborz Jahanian e283346d0b objc-arc: diagnose synthesis of a 'weak unavailable' property.
// rdar://10535245

llvm-svn: 146272
2011-12-09 19:55:11 +00:00
Fariborz Jahanian 6bdeb14d5d objc: issue deprecated/unavailable diagnostic when
methods with these attributes are sent to receivers
of 'id' type too. // rdar://10459930

llvm-svn: 145999
2011-12-07 00:30:00 +00:00
Erik Verbruggen c6c8d9356d Extend warnings for missing '@end'.
Fixes PR2709.

llvm-svn: 145928
2011-12-06 09:25:23 +00:00
Fariborz Jahanian 56f326e7f2 objc: put out more coherent warning when method definition
attributes don't match its declaration. // rdar://10529259.

llvm-svn: 145872
2011-12-06 00:02:41 +00:00
Douglas Gregor 11bb308457 When typo-correction an Objective-C superclass name, don't
typo-correct to ourselves.

llvm-svn: 145583
2011-12-01 15:37:53 +00:00
Douglas Gregor d8fb1e30eb When sending a message to a receiver that has "unknown any" type,
force the unknown any type to "id" so that the message send can be
completed without requiring a case. Fixes <rdar://problem/10506646>.

llvm-svn: 145552
2011-12-01 01:37:36 +00:00
Ted Kremenek 764d63ad94 Specially whitelist the selector 'addOperationWithBlock:' for the retain-cycle checking in -Warc-retain-cycles. This commonly
is hit by users using NSOperationQueue.  Fixes <rdar://problem/10465721>.

llvm-svn: 145548
2011-12-01 00:59:21 +00:00
Fariborz Jahanian a45495a9f2 objc: warn if NSObject attribute appears other than in a typedef.
// rdar://10453342

llvm-svn: 145358
2011-11-29 01:48:40 +00:00
Fariborz Jahanian 22b405c7aa objc: turn warning for property type mismatch in
primary and its continuation class into error.
// rdar://10142679

llvm-svn: 145255
2011-11-28 18:38:27 +00:00
Douglas Gregor 4123a86fae Use Sema::RequireCompleteType to check for the completeness of
Objective-C classes. This has two purposes: to consistently provide
"forward declaration here" notes when we hit an incomplete type, and
to give LLDB a chance to complete the type.

RequireCompleteType bits from Sean Callanan!

llvm-svn: 144573
2011-11-14 22:10:01 +00:00
Argyrios Kyrtzidis 95dfc12cd6 Don't crash when a duplicate interface/protocol is inside an extern "C" context.
llvm-svn: 144508
2011-11-13 22:08:30 +00:00
Argyrios Kyrtzidis 3a8de5b560 Don't crash on invalid objc code.
llvm-svn: 144150
2011-11-09 00:22:48 +00:00
Fariborz Jahanian 557fc9a99d objc: Don't crash on missing @interface decl.
// rdar://10415026

llvm-svn: 144143
2011-11-08 22:51:27 +00:00
Fariborz Jahanian b1ac0813a6 objc-arc: 'readonly' property of retainable object
type is strong by default too. // rdar://10410903

llvm-svn: 144118
2011-11-08 20:58:53 +00:00
John McCall cfef546d40 There are some crazy cases that LookupMethodInReceiverType
doesn't duplicate, but they all surface as implicit
properties.  It's also a useful optimization to not
duplicate the implicit getter lookup.  So, trust the
getter lookup that was already done in these cases.

llvm-svn: 144031
2011-11-07 22:49:50 +00:00
Argyrios Kyrtzidis fed29142ba When applying ARC __weak to a non-objc pointer, do not give error that
__weak is unsupported by the deployment target, since it is going to be
ignored anyway.

Makes it easier for incremental migration from GC.

llvm-svn: 143975
2011-11-07 18:40:21 +00:00
Fariborz Jahanian 37c6417949 objc: fixed enum type is supported in objc mode.
Fixes a bug where enumerator type is not this
fixed type. // rdar://10381507

llvm-svn: 143724
2011-11-04 18:51:24 +00:00
Fariborz Jahanian 3018b95093 objc: warn if a readonly property has a setter attribute too.
// rdar://10357768

llvm-svn: 143518
2011-11-01 23:02:16 +00:00
Ted Kremenek 5d6044e413 Downgrade err_iboutlet_object_type to a warning. It was breaking a bunch of code. We will reconsider promoting it back to an error later.
llvm-svn: 143470
2011-11-01 18:08:35 +00:00
Fariborz Jahanian d01ddd1d07 Improve text of a diagnostic.
llvm-svn: 143353
2011-10-31 17:27:06 +00:00
Fariborz Jahanian 244b187d22 objc-arc: desugar certain type and improve on diagnostic for
ownership qualifier cast which won't work.
// rdar://10244607

llvm-svn: 143258
2011-10-29 00:06:10 +00:00
Argyrios Kyrtzidis 729387327b [ARC] Do not transfer ARC ownership if the cast is going to result in r-value,
in which case the ownership is redundant. Thanks to John for the suggestion.

llvm-svn: 143240
2011-10-28 22:54:28 +00:00
Fariborz Jahanian 2fa646d596 objective-c arc: type-casting of an objc pointer to
an rvalue retainable object type with life-time qualifier has no
effect and wil be diagnosed as error. // rdar://10244607

llvm-svn: 143219
2011-10-28 20:06:07 +00:00
Argyrios Kyrtzidis a9aabf7d51 Fix crash on an @interface nested inside @implementation, rdar://10336158
llvm-svn: 143085
2011-10-27 00:09:34 +00:00
John McCall 526ab47a55 Restore r142914 and r142915, now with missing file and apparent
GCC compiler workaround.

llvm-svn: 142931
2011-10-25 17:37:35 +00:00
NAKAMURA Takumi 9a8f13961c Revert r142914 and r142915, due to possibly missing file.
r142914: "Introduce a placeholder type for "pseudo object""
r142915: "Pull the pseudo-object stuff into its own file."
llvm-svn: 142921
2011-10-25 14:32:25 +00:00
John McCall c4a2d3259f Introduce a placeholder type for "pseudo object"
expressions: expressions which refer to a logical rather
than a physical l-value, where the logical object is
actually accessed via custom getter/setter code.
A subsequent patch will generalize the AST for these
so that arbitrary "implementing" sub-expressions can
be provided.

Right now the only client is ObjC properties, but
this should be generalizable to similar language
features, e.g. Managed C++'s __property methods.

llvm-svn: 142914
2011-10-25 07:27:56 +00:00
Ted Kremenek 7b2fbc61de Relax restriction of assigning to 'self' in ARC when a method is attributed with ns_consumes_self. Fixes <rdar://problem/10274056>.
llvm-svn: 142909
2011-10-25 04:52:20 +00:00
Fariborz Jahanian e96f9c816b Fixes a minor hick up to my last patch.
llvm-svn: 142711
2011-10-22 01:56:45 +00:00
Fariborz Jahanian 512a4cc967 objc: private methods can have their attributes, no diagnostic is required.
None private methods if their implementation have attribute, they must exactly 
match those in their declarations. // rdar://10271563

llvm-svn: 142709
2011-10-22 01:21:15 +00:00
Fariborz Jahanian 2512747959 objective-c: Diagnose redeclaration of private
ivars in class extensions. // rdar://10309454

llvm-svn: 142664
2011-10-21 18:03:52 +00:00
Fariborz Jahanian 7f73302b4f objc: allow class name qualified with protocols in
iboutletcollection attribute. But ignore protocol
list. // rdar://10296078

llvm-svn: 142459
2011-10-18 23:13:50 +00:00
John McCall 91aee685d8 Add a __has_feature check for arc_cf_code_audited.
llvm-svn: 142423
2011-10-18 21:18:53 +00:00
Fariborz Jahanian 2f31b33f34 objc: more changes in use of IBOutletCollection attribute.
'Class' is disallowed as argument.  If the argument is missing, 
NSObject is assumed. // rdar://10296078

llvm-svn: 142409
2011-10-18 19:54:31 +00:00
Fariborz Jahanian 6b70865ec0 objc: diagnose invalid argument to an
iboutletcollection attribute intead of crashing.
// rdar://10296078

llvm-svn: 142364
2011-10-18 17:11:10 +00:00
John McCall 95ff270ee9 Fix several bugs with #pragma clang arc_cf_code_audited and macros.
llvm-svn: 142324
2011-10-18 00:44:04 +00:00
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
Fariborz Jahanian c27cd1b881 Avoid duplicate unavailbility diagnostics in objc++.
// rdar://10268422

llvm-svn: 142078
2011-10-15 19:18:36 +00:00
Fariborz Jahanian 1cb83e24d4 objc-arc: Improve arc diagnostic when method is not
found in receiver's class. // rdar://9970739

llvm-svn: 141961
2011-10-14 17:34:08 +00:00
Fariborz Jahanian df4f7ca331 objc-arc: 'Class' property is implicitly __unsafe_unretained.
// rdar://10239594

llvm-svn: 141915
2011-10-13 23:45:45 +00:00
Fariborz Jahanian fa643c8f3b objc: note location of the previously declared
property in the diagnostic.

llvm-svn: 141745
2011-10-12 00:00:57 +00:00
Fariborz Jahanian 55b4e5c208 objc: err on a property designated both atomic and
nonatomic. // rdar://10260017

llvm-svn: 141580
2011-10-10 21:53:24 +00:00
Fariborz Jahanian 9059124b41 objc: Do not warn about mismatch on Super's readonly property attribute,
related to a readwrite property, and
Sub's readwrite property. // rdar://9396329

llvm-svn: 141497
2011-10-08 17:45:33 +00:00
Fariborz Jahanian 9cd57a7061 objc: Improve on diagnostic when atomic proeprty is synthesized
on one accessor and user-provide with another.

llvm-svn: 141343
2011-10-06 23:47:58 +00:00
Argyrios Kyrtzidis c281c96675 Implicitly assume that a ObjC category to an unavailable interface is also unavailable;
only give an 'unavailable' error on the @implementation of the category. rdar://10234078

llvm-svn: 141335
2011-10-06 23:23:27 +00:00
Argyrios Kyrtzidis 9321ad3f97 When using an unavailable/deprecated interface Foo inside Foo's interface/implementation
don't emit unavailable errors.

llvm-svn: 141334
2011-10-06 23:23:20 +00:00
Argyrios Kyrtzidis a7324ede34 Fix crash when using archaic protocol, rdar://10238337
llvm-svn: 141215
2011-10-05 21:28:06 +00:00
Fariborz Jahanian f2a7b0eade objc: Turn diagnostic on property type mismatch in
continuation class into warning. // rdar://10231514

llvm-svn: 141100
2011-10-04 18:44:26 +00:00
Fariborz Jahanian ed1933b02b objc arc: Suppress certain arc diagnostics on unavailable
functions. // rdar://10186536

llvm-svn: 141037
2011-10-03 22:11:57 +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
John McCall e4fe245716 Allow the results of cf_returns_not_retained function
calls, or calls to audited functions without an explicit
return attribute, to be casted without a bridge cast.
Tie this mechanism in with the existing exceptions to
the cast restrictions.  State those restrictions more
correctly and generalize.

llvm-svn: 140912
2011-10-01 01:01:08 +00:00
John McCall f1e8b34f6c Add an ns_bridged attribute, used to specify that a
pointer to the annotated struct type can be used as an 
Objective-C object pointer.  If an argument is given, the
type is actually "toll-free bridged" to the specific type 
named there, rather than just to 'id'.

For now, we cannot rely on all types being so annotated,
and we'll always have to have exceptions for things like
CFTypeRef (aka const void*), but this is clearly a good
foundation for improving toolage in this area.

llvm-svn: 140779
2011-09-29 07:17:38 +00:00
Ted Kremenek 7fd1723619 Like IBOutletCollection, it only makes sense to apply the IBOutlet annotation to Objective-C object types. Fixes <rdar://problem/10142685>.
llvm-svn: 140778
2011-09-29 07:02:25 +00:00
Fariborz Jahanian 97676979a7 objc arc: Diagnose block pointer type mismatch when
some arguments types are ns_consumed and some otherwise
matching types are not. This is objc side of
// rdar://10187884

llvm-svn: 140729
2011-09-28 21:52:05 +00:00
Ted Kremenek 3f443a71dc Tweak -Wobjc-missing-super-calls to not warning about missing [super dealloc] when in GC-only mode, and to not warning about missing [super finalize] when not using GC.
llvm-svn: 140713
2011-09-28 19:32:29 +00:00
Ted Kremenek ab2dcc8de6 Include prefix with default synthesized ivars.
llvm-svn: 140657
2011-09-27 23:39:40 +00:00
Douglas Gregor 75acd925d0 Only print _Bool as 'bool' when 'bool' is defined as an object-like
macro whose only replacement token is '_Bool'.

llvm-svn: 140656
2011-09-27 23:30:47 +00:00
Douglas Gregor c0b07286cf When 'bool' is not a built-in type but is defined as a macro, print
'bool' rather than '_Bool' within types, to make things a bit more
readable. Fixes <rdar://problem/10063263>.

llvm-svn: 140650
2011-09-27 22:38:19 +00:00
Fariborz Jahanian ac8dbf0fc7 objcetive-c-arc: When overriding a method, its ns_consumed patameter
attribute must match its overriden method. Same also for
ns_returns_retained/not_retained on the result type.
This is one half of // rdar://10187884

llvm-svn: 140649
2011-09-27 22:35:36 +00:00
Douglas Gregor 486b74e596 Revert r139989 and r140031, which implemented the Objective-C type
system change in <rdar://problem/10109725> that allows conversion from
'self' in class methods to the root of the class's hierarchy. This
conversion rule is a hack that has non-trivial repurcussions
(particularly with overload resolution).

llvm-svn: 140605
2011-09-27 16:10:05 +00:00
Fariborz Jahanian 698bd3113e objc - don't complain about unimplemented property when conforming
protocol declares the property, as well as one of its superclasses.
Property will be implemented in the super class. // rdar://10120691

llvm-svn: 140586
2011-09-27 00:23:52 +00:00
Fariborz Jahanian 23ef165920 objc - in matching setter argument type to its property type,
ingore the type qualifiers. // rdar://10156674

llvm-svn: 140571
2011-09-26 22:12:27 +00:00
Fariborz Jahanian 6d5d6a277a objc-arc: mark functions which return types which can't be dealt with
in arc mode and are in system headers as unavailable. 
// rdar://10186625

llvm-svn: 140565
2011-09-26 21:23:35 +00:00
Benjamin Kramer 6f4f307d1f Turns out we tested for this typo.
llvm-svn: 140513
2011-09-26 02:32:23 +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
Fariborz Jahanian 44653709fd objc - fixes a crash when undefined typed property
followed by it implementation crashes when attempt
is made to access the synthesized ivar. 
// rdar://10177744

llvm-svn: 140432
2011-09-23 23:11:38 +00:00
Douglas Gregor 83dea558bc Add a test triple. Who knew that all the world wasn't darwin?
llvm-svn: 140408
2011-09-23 20:28:32 +00:00
Douglas Gregor b1fa148837 Don't propagate the 'availability' attribute through declaration
merging for overrides. One might want to make a method's availability
in a superclass different from that of its subclass. Fixes
<rdar://problem/10166223>.

llvm-svn: 140406
2011-09-23 20:23:42 +00:00
Douglas Gregor 0c254a00c1 Clean up parsing the category names in interfaces slightly, using
MatchRHSPunctuation appropriately and giving a useful source location
for the complaint about attributes being added to a category.

llvm-svn: 140404
2011-09-23 19:19:41 +00:00
Argyrios Kyrtzidis 712512bb36 [ARC] Allow forming 'id*' in an unevaluated context. Fixes rdar://10148540.
llvm-svn: 140212
2011-09-20 23:49:22 +00:00
Fariborz Jahanian db8015c449 objc - Treat type of 'self' in class methods as root of
class of this method. // rdar://10109725

llvm-svn: 139989
2011-09-17 19:23:40 +00:00
Fariborz Jahanian 8b148bb5b7 objc: Don't crash with decl context for property impl.
is missing. // rdar//10127639

llvm-svn: 139988
2011-09-17 18:48:50 +00:00
Fariborz Jahanian d923eb0d1e reverse patch in r139818 to focus on 'self'
instead of 'Class'.

llvm-svn: 139834
2011-09-15 20:40:18 +00:00
Fariborz Jahanian b7d278ba77 Objective-c: Conversion from type Class to any root class type is allowed
in class methods with no warning. //rdar://10109725

llvm-svn: 139818
2011-09-15 18:30:22 +00:00
Fariborz Jahanian 1723e17b78 objc-arc: warn when a 'retain' block property is
declared which does not force a 'copy' of the block literal
object. // rdar://9829425

llvm-svn: 139706
2011-09-14 18:03:46 +00:00
David Blaikie e5f9a9e603 Show either a location or a fixit note, not both, for uninitialized variable warnings.
llvm-svn: 139463
2011-09-10 05:35:08 +00:00
Douglas Gregor 97e3590a6e Fix a diagnostics crasher with -Wmissing-noreturn in Objective-C
methods, and improve the diagnostic slightly along the way. Fixes
<rdar://problem/10098695>.

llvm-svn: 139446
2011-09-10 00:56:20 +00:00
Douglas Gregor 3168dcf134 The integer type of an enumeration type isn't always canonical
llvm-svn: 139334
2011-09-08 23:29:05 +00:00
Douglas Gregor 8b7d403684 Allow C++0x enumerations with a fixed underlying type in
Objective-C. The @encode'ing of such an enumeration type is the same
as its underlying type. <rdar://problem/5276348>.

llvm-svn: 139297
2011-09-08 17:18:35 +00:00
Douglas Gregor bab8a96f2f Implement the Objective-C 'instancetype' type, which is an alias of
'id' that can be used (only!) via a contextual keyword as the result
type of an Objective-C message send. 'instancetype' then gives the
method a related result type, which we have already been inferring for
a variety of methods (new, alloc, init, self, retain). Addresses
<rdar://problem/9267640>.

llvm-svn: 139275
2011-09-08 01:46:34 +00:00
Fariborz Jahanian eebdb67420 objc-gc: More sema work for properties declared 'weak'
in GC mode. // rdar://10073896

llvm-svn: 139235
2011-09-07 16:24:21 +00:00
Fariborz Jahanian b93cd18a82 Test for default property synthesis.
llvm-svn: 138917
2011-08-31 23:32:48 +00:00
Fariborz Jahanian 97d744bea4 objective-c: this patch (re)introduces objective-c's default property
synthesis. This new feature is currently placed under 
-fobjc-default-synthesize-properties option
and is off by default pending further testing.
It will become the default feature soon. 
// rdar://8843851

llvm-svn: 138913
2011-08-31 22:24:06 +00:00
Fariborz Jahanian bd0642fede objective-c - This patch buffers method implementations
and does the Sema on their body after the entire 
class/category @implementation is seen. This change allows messaging 
of forward private methods, as well as, access to 
synthesized ivars of properties with foward synthesize
declarations; among others. In effect, this patch removes
several restrictions placed on objective-c due to in-place
semantics processing of methods.
This is part of // rdar://8843851.

llvm-svn: 138865
2011-08-31 17:37:55 +00:00
Chandler Carruth c841b6e598 Improve the diagnostic text for -Wmissing-noreturn to include the name
of the function in question when applicable (that is, not for blocks).
Patch by Joerg Sonnenberger with some stylistic tweaks by me.

When discussing this weth Joerg, streaming the decl directly into the
diagnostic didn't work because we have a pointer-to-const, and the
overload doesn't accept such. In order to make my style tweaks to the
patch, I first changed the overload to accept a pointer-to-const, and
then changed the diagnostic printing layer to also use
a pointer-to-const, cleaning up a gross line of code along the way.

llvm-svn: 138854
2011-08-31 09:01:53 +00:00
Fariborz Jahanian 59b75285f6 objc - fixes a regression in declaring c decls nested in
objective-c containers due to recent changes to objc decl 
contexts. // rdar://10041908

llvm-svn: 138803
2011-08-30 17:10:52 +00:00
Nico Weber f926a45df5 Do not warn about [super finalize] in arc mode.
llvm-svn: 138776
2011-08-29 22:59:14 +00:00
Nico Weber 1fb82667dd Warn on missing [super finalize] calls.
This matches gcc's logic. Second half of PR10661.

llvm-svn: 138730
2011-08-28 22:35:17 +00:00
Fariborz Jahanian 83aa8ab3ae objective-c - Make warning on unimplemented protocols point
to class implementation where it is supposed to be
implemented. // rdar://10009982.

llvm-svn: 138714
2011-08-27 21:55:47 +00:00
Fariborz Jahanian 97b6ac5407 objc-arc: Mention property's attribute by name when
finding life-time conflict with its declared ivar.
// rdar://10007230

llvm-svn: 138659
2011-08-26 21:21:19 +00:00
Fariborz Jahanian 5cc730cdef Don't warn on category implementing a method, if
declated method in the class belongs to a synthesized
property getter/setter. // rdar://10014946

llvm-svn: 138598
2011-08-25 22:58:42 +00:00
Fariborz Jahanian 73952fc263 objc - fix up the builtin type for objc_assign_ivar.
// rdar://9362887.

llvm-svn: 138412
2011-08-23 23:33:09 +00:00
Ted Kremenek 618e574253 Do not perform check for missing '[super dealloc]' under ARC as calling -dealloc is illegal in that mode.
llvm-svn: 138261
2011-08-22 19:07:43 +00:00
Nico Weber 715abaf213 Warn on missing [super dealloc] calls.
This matches gcc's logic. Half of PR10661.

llvm-svn: 138240
2011-08-22 17:25:57 +00:00
Fariborz Jahanian 8d382dc781 Restore patch I reversed in r138040. Known buildbot
failures are resolved.

llvm-svn: 138234
2011-08-22 15:54:49 +00:00
Fariborz Jahanian 7e47de3156 objc-arc: @property definitions should default to (strong) when not
specified. // rdar://9971982

llvm-svn: 138062
2011-08-19 19:28:44 +00:00
NAKAMURA Takumi 9f8a02d34e De-Unicode-ify.
llvm-svn: 137430
2011-08-12 05:49:51 +00:00
Fariborz Jahanian 3c12dd7675 objective-c: Using existing infrastructure for finding
overridden  methods to diagnose their type mismatch.
This is a general solution for previous fixes
for // rdar://6191214 and // rdar://9352731
and removes lots of duplicate code.

llvm-svn: 137222
2011-08-10 17:16:30 +00:00
Fariborz Jahanian 5ac085ab3a objective-c: diagnose protocol inconsistencies in following
situation. When a class explicitly or implicitly (through inheritance) 
"conformsTo" two protocols which conflict (have methods which conflict).
This patch fixes the previous patch where warnings were coming out in
non-deterministic order.  This is 2nd part of // rdar://6191214.

llvm-svn: 137055
2011-08-08 18:03:17 +00:00
John McCall 5939b16135 Do l-value conversion, etc., on a switch condition expression in
ActOnStartOfSwitchStmt (i.e. before binding up a full-expression)
instead of ActOnFinishSwitchStmt.

Among other things, this means that property l-values are properly
converted inside the full-expression.

llvm-svn: 137014
2011-08-06 07:30:58 +00:00
Ted Kremenek 1cd34b8fea Revert 136984 and 136927.
llvm-svn: 136998
2011-08-05 23:31:22 +00:00
Ted Kremenek 9dd9b882ae Make test/SemaObjC/qualified-protocol-method-conflicts.m always fail and mark it XFAIL. This is a stop gap until the output of the test is deterministic.
llvm-svn: 136984
2011-08-05 21:53:47 +00:00
Fariborz Jahanian 6a86844161 objective-c: diagnose protocol inconsistencies in following
situation. When a class explicitly or implicitly (through inheritance) 
"conformsTo" two protocols which conflict (have methods which conflict).
This is 2nd part of // rdar://6191214.

llvm-svn: 136927
2011-08-04 21:28:44 +00:00
Fariborz Jahanian 2bda1b65b1 objective-c: Methods declared in methods must type match
those declated in its protocols. First half or // rdar://6191214

llvm-svn: 136794
2011-08-03 18:21:12 +00:00
Fariborz Jahanian e1506cbfda objective-c: reverse patch for // rdar://9818354
llvm-svn: 136658
2011-08-01 22:39:49 +00:00
Douglas Gregor 7e1eb935db When complaining about a non-POD second argument to va_arg, use a
special diagnostic for ARC ownership-qualified types. We wouldn't want
to expose Objective-C programmers to the term "POD", would we? Fixes
<rdar://problem/9772982>.

llvm-svn: 136558
2011-07-30 06:45:27 +00:00
Fariborz Jahanian 9f8b19e9ae objective-c: warn if implementation of a method in category
masks an existing method in its primary class, class extensions,
and primary class's non-optional protocol methods; as primary
class, or one of its subclass's will implement this method.
This warning has potential of being noisy so it has its own
group.  // rdar://7020493

llvm-svn: 136426
2011-07-28 23:19:50 +00:00
Anna Zaks 3b402716b1 Add */& mismatch fixit generation to the Sema::DiagnoseAssignmentResult().
llvm-svn: 136379
2011-07-28 19:51:27 +00:00
John McCall 538482373b Clean up the analysis of the collection operand to ObjC
for-in statements;  specifically, make sure to close over any
temporaries or cleanups it might require.  In ARC, this has
implications for the lifetime of the collection, so emit it
with a retain and release it upon exit from the loop.

rdar://problem/9817306

llvm-svn: 136204
2011-07-27 01:07:15 +00:00
Argyrios Kyrtzidis e3be9795c8 In ARC we emit an error when compiling:
@interface Foo : NSObject
@property (readonly) id myProp;
@end

@implementation Foo
@synthesize myProp;
@end

t.m:9:13: error: ARC forbids synthesizing a property of an Objective-C object with unspecified storage attribute
@synthesize myProp;
            ^

which is fine, we want the ownership of the synthesized ivar to be explicit. But we should _not_ emit an error
for the following cases, because we can get the ownership either from the declared ivar or from the property type:

@interface Foo : NSObject {
	__weak id _myProp1;
	id myProp2;
}
@property (readonly) id myProp1;
@property (readonly) id myProp2;
@property (readonly) __strong id myProp3;
@end

@implementation Foo
@synthesize myProp1 = _myProp1;
@synthesize myProp2;
@synthesize myProp3;
@end

rdar://9844006.

llvm-svn: 136155
2011-07-26 21:48:26 +00:00
Fariborz Jahanian 4ceec3f0d1 objc: clang should warn if redeclaration of methods
declared in protocol in the class qualified by the
protocol have type conflicts. To reduce amount of
noise, this is done when class is implemented.
// rdar://9352731

llvm-svn: 135890
2011-07-24 20:53:26 +00:00
Fariborz Jahanian dff8de77a6 objective-c: Any use of @synthesize or @dynamic lexically after a method (or C function) implementation
will be rejected with a compilation error in ARC mode, and a compiler warning otherwise.
This may cause breakage in non-arc (and arc) tests which don't expect warning/error. Feel free
to fix the tests, or reverse the patch, if I am unavailable. // rdar://9818354 - WIP

llvm-svn: 135740
2011-07-22 01:06:53 +00:00
Fariborz Jahanian b5a52ca0c9 objc - Diagnose missing method return type specifier under
a warning flag. // rdar://9615045

llvm-svn: 135681
2011-07-21 17:00:47 +00:00
Fariborz Jahanian 9a881019a5 With -Wselector, don't warn about unimplemented optional method
used in @selector expression because, well, their implementation 
is optional. // rdar://9545564

llvm-svn: 135057
2011-07-13 19:05:43 +00:00
John McCall 3f4138c5d0 In debugger mode, make ObjC message sends to unknown selectors return
__unknown_anytype, and rewrite such message sends correctly.

I had to bite the bullet and actually add a debugger support mode for this
one, which is a bit unfortunate, but there really isn't anything else
I could imagine doing;  this is clearly just debugger-specific behavior.

llvm-svn: 135051
2011-07-13 17:56:40 +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
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 7f4427fc60 Fix a bug where a local variable named 'self' is causing
implicit ivar accesses to go through the 'self' variable
rather than the real 'self' for the method. // rdar://9730771

llvm-svn: 134992
2011-07-12 17:16:56 +00:00
Argyrios Kyrtzidis 52bfc2b668 [ARC] Complain about property without storage attribute when @synthesizing it, not at its declaration.
For this sample:

@interface Foo
@property id x;
@end

we get:

t.m:2:1: error: ARC forbids properties of Objective-C objects with unspecified storage attribute
@property  id x;
^
1 error generated.

The error should be imposed on the implementor of the interface, not the user. If the user uses
a header of a non-ARC library whose source code he does not have, we are basically asking him to
go change the header of the library (bad in general), possible overriding how the property is
implemented if he gets confused and says "Oh I'll just add 'copy' then" (even worse).

Second issue is that we don't emit any error for 'readonly' properties, e.g:

@interface Foo
@property (readonly) id x; // no error  here
@end

@implementation Foo
@synthesize x; // no error here too
@end

We should give an error when the implementor is @synthesizing a property which doesn't have
any storage specifier; this is when the explicit specifier is important, because we are
going to create an ivar and we want its ownership to be explicit.

Related improvements:
-OBJC_PR_unsafe_unretained turned out to not fit in ObjCPropertyDecl's bitfields, fix it.
-For properties of extension classes don't drop PropertyAttributesAsWritten values.
-Have PropertyAttributesAsWritten actually only reflect what the user wrote

rdar://9756610.

llvm-svn: 134960
2011-07-12 04:30:16 +00:00
Fariborz Jahanian 256d39d47d objc-arc: Diagnose when captured variable in block literals
require destruction and there is possibility of that without
construction. Thanks Johnm for review and suggestions offline.
// rdar://9535237.

llvm-svn: 134906
2011-07-11 18:04:54 +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 6f472e803b objc-arc: diagnose assignment/cast of a weak-unavailable
object to a __weak object/type. // rdar://9732636.
This is objc side of things. objc++ side tbd.

llvm-svn: 134624
2011-07-07 18:55:47 +00:00
Fariborz Jahanian 1f626d6fd1 objc-arc: Support objc_arc_weak_unavailable on those
classes which are incompatible with weak references.
// rdar://9693477

llvm-svn: 134522
2011-07-06 19:24:05 +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
Fariborz Jahanian b7a773626f objc-arc: enforce performSelector rules in rejecting retaining selectors
passed to it, and unknown selectors causing potential leak.
// rdar://9659270

llvm-svn: 134449
2011-07-05 22:38:59 +00:00
Argyrios Kyrtzidis 451ccc0892 Fix the warning that is emitted when an ownership attribute is applied incorrectly.
llvm-svn: 134278
2011-07-01 22:23:09 +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
Daniel Dunbar 421bb42c9f Revert r133024, "[format strings] correctly suggest correct type for '%@'
specifiers.  Fixes <rdar://problem/9607158>." because it causes false positives
on some code that uses CF toll free bridging.
 - I'll let Doug or Ted figure out the right fix here, possibly just to accept
   any pointer type.

llvm-svn: 134041
2011-06-28 23:33:55 +00:00
Douglas Gregor c2fa169d6c Add support for C++ namespace-aware typo correction, e.g., correcting
vector<int>

to

  std::vector<int>

Patch by Kaelyn Uhrain, with minor tweaks + PCH support from me. Fixes
PR5776/<rdar://problem/8652971>.

Thanks Kaelyn!

llvm-svn: 134007
2011-06-28 16:20:02 +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
Chandler Carruth c933221826 Factor out (some of) the checking for invalid forms of pointer
arithmetic into a couple of common routines. Use these to make the
messages more consistent in the various contexts, especially in terms of
consistently diagnosing binary operators with invalid types on both the
left- and right-hand side. Also, improve the grammar and wording of the
messages some, handling both two pointers and two (different) types.

The wording of function pointer arithmetic diagnostics still strikes me
as poorly phrased, and I worry this makes them slightly more awkward if
more consistent. I'm hoping to fix that with a follow-on patch and test
case that will also make them more helpful when a typedef or template
type parameter makes the type completely opaque.

Suggestions on better wording are very welcome, thanks to Richard Smith
for some initial help on that front.

llvm-svn: 133906
2011-06-27 08:02:19 +00:00
Fariborz Jahanian f4105f5cfe objc-arc/mrc: Allow ns_returns_not_retained attribute on properties
to turn off warning on those properties which follow Cocoa naming
convention for retaining objects and yet they were not meant for
such purposes. Also, perform consistancy checking for declared
getters of such methods. // rdar://9636091

llvm-svn: 133849
2011-06-25 00:17:46 +00:00
Fariborz Jahanian 9fc39c4944 No need to warn if 'unavailable' method/property
is not implemented. // rdar://9651605

llvm-svn: 133819
2011-06-24 20:31:37 +00:00
Fariborz Jahanian 5f98da0ea2 objc-arc: Check on a variety of unsafe assignment of retained
objects.  // rdar://9495837

llvm-svn: 133806
2011-06-24 18:25:34 +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 3ee91fad90 When forming a cycle in objc's inheritance hierarchy,
diagnose it properly and don't throw clang into an
infinit loop. // rdar://9653341

llvm-svn: 133773
2011-06-23 23:16:19 +00:00
Argyrios Kyrtzidis 694f75db13 Change "cannot assign retained object.." warning to "assigning retained object.."
llvm-svn: 133625
2011-06-22 18:03:53 +00:00
Fariborz Jahanian ec667fcc36 objc-arc: Allow unbridged cast of retainable object to
integral as it is not transferring ownership.. 
// rdar://9619861

llvm-svn: 133622
2011-06-22 16:36:45 +00:00
Fariborz Jahanian 4ad5686399 objc-arc: allow explicit unbridged casts if the source of the cast is a
message sent to an objc method (or property access)
// rdar://9474349

llvm-svn: 133469
2011-06-20 20:54:42 +00:00
John McCall 0c07bee8bd Only accept __bridge_retain in system headers, as Doug suggested.
llvm-svn: 133300
2011-06-17 21:56:12 +00:00
John McCall 0c32925aa0 As a hopefully temporary workaround for a header mistake, treat
__bridge_retain as a synonym for __bridge_retained.

llvm-svn: 133295
2011-06-17 21:23:37 +00:00
John McCall d463132f27 Objective-C fast enumeration loop variables are not retained in ARC, but
they should still be officially __strong for the purposes of errors, 
block capture, etc.  Make a new bit on variables, isARCPseudoStrong(),
and set this for 'self' and these enumeration-loop variables.  Change
the code that was looking for the old patterns to look for this bit,
and change IR generation to find this bit and treat the resulting         
variable as __unsafe_unretained for the purposes of init/destroy in
the two places it can come up.

llvm-svn: 133243
2011-06-17 06:42:21 +00:00
Fariborz Jahanian 62c72d06ff arc: diagnose dereferencing a __weak pointer which may be
null at any time. // rdar://9612030

llvm-svn: 133168
2011-06-16 17:29:56 +00:00
John McCall 54507ab83c Weaken the type-matching rules for methods that return aggregates when
complaining about mismatches in the global method pool.

llvm-svn: 133123
2011-06-16 01:15:19 +00:00