Commit Graph

1038 Commits

Author SHA1 Message Date
Fariborz Jahanian 8061f92c6b use ';' instead of '-' in the note part of my last patch.
llvm-svn: 165177
2012-10-03 22:39:32 +00:00
Fariborz Jahanian e0e4bd3c76 Fix a typo in my last patch reported by Erik Schwiebert.
llvm-svn: 165142
2012-10-03 19:05:41 +00:00
Fariborz Jahanian 4a67508685 objective-C arc: Warn under arc about a use of an ivar inside a block
that doesn't have a 'self' as this implicitly captures 'self' and could
create retain cycles. Provide fixit. // rdar://11194874

llvm-svn: 165133
2012-10-03 17:55:29 +00:00
Benjamin Kramer 4bb04704f3 Force triple in test to unbreak it on non-darwin platforms.
llvm-svn: 164994
2012-10-02 09:29:48 +00:00
Ted Kremenek 2f88c40ded Tweak diagnostic text to indicate that __weak on a local variable is only allowed
for ARC.  Fixes <rdar://problem/12407705>

llvm-svn: 164990
2012-10-02 05:36:02 +00:00
Fariborz Jahanian c491c3f27a availability in structured documents. Takes
care of comments by Dimitri and Doug.

llvm-svn: 164957
2012-10-01 18:42:25 +00:00
Jordan Rose 13d6b71929 -Wreceiver-is-weak: rephrase warning text and add a suggestion Note.
New output:
  warning: weak property may be unpredictably set to nil
  note: property declared here
  note: assign the value to a strong variable to keep the object alive
        during use

<rdar://problem/12277204>

llvm-svn: 164857
2012-09-28 22:21:42 +00:00
Jordan Rose 657b5f464d -Warc-repeated-use-of-weak: check ivars and variables as well.
Like properties, loading from a weak ivar twice in the same function can
give you inconsistent results if the object is deallocated between the
two loads. It is safer to assign to a strong local variable and use that.

Second half of <rdar://problem/12280249>.

llvm-svn: 164855
2012-09-28 22:21:35 +00:00
Jordan Rose d393458c33 Add a warning (off by default) for repeated use of the same weak property.
The motivating example:

if (self.weakProp)
  use(self.weakProp);

As with any non-atomic test-then-use, it is possible a weak property to be
non-nil at the 'if', but be deallocated by the time it is used. The correct
way to write this example is as follows:

id tmp = self.weakProp;
if (tmp)
  use(tmp);

The warning is controlled by -Warc-repeated-use-of-receiver, and uses the
property name and base to determine if the same property on the same object
is being accessed multiple times. In cases where the base is more
complicated than just a single Decl (e.g. 'foo.bar.weakProp'), it picks a
Decl for some degree of uniquing and reports the problem under a subflag,
-Warc-maybe-repeated-use-of-receiver. This gives a way to tune the
aggressiveness of the warning for a particular project.

The warning is not on by default because it is not flow-sensitive and thus
may have a higher-than-acceptable rate of false positives, though it is
less noisy than -Wreceiver-is-weak. On the other hand, it will not warn
about some cases that may be legitimate issues that -Wreceiver-is-weak
will catch, and it does not attempt to reason about methods returning weak
values.

Even though this is not a real "analysis-based" check I've put the bug
emission code in AnalysisBasedWarnings for two reasons: (1) to run on
every kind of code body (function, method, block, or lambda), and (2) to
suggest that it may be enhanced by flow-sensitive analysis in the future.

The second (smaller) half of this work is to extend it to weak locals
and weak ivars. This should use most of the same infrastructure.

Part of <rdar://problem/12280249>

llvm-svn: 164854
2012-09-28 22:21:30 +00:00
Fariborz Jahanian 61740f6649 objective-C: use 'instance variables' as plural when referring
to the feature.

llvm-svn: 164566
2012-09-24 22:51:51 +00:00
Fariborz Jahanian 14fd801f8f objective-C: remove use of 'ivar' in favor of
'instance variable' in text of all diagnostics
for objective-C: // rdar://12352442

llvm-svn: 164559
2012-09-24 22:00:36 +00:00
Fariborz Jahanian 974c948049 objective-C: when diagnosing deprecated/unavailable usage of
setter or getter backing a deprecated/unavailable property,
also not location of the property. // rdar://12324295

llvm-svn: 164412
2012-09-21 20:46:37 +00:00
Fariborz Jahanian cfb00a4137 objective-C: don't warn about class extension property's
missing 'assign' attribute as it is determined by its
overridden property in primary class. // rdar://12214070 

llvm-svn: 164080
2012-09-17 23:57:35 +00:00
Fariborz Jahanian 8439c78fa5 objective-C: add Doug's test for my last patch.
llvm-svn: 164079
2012-09-17 23:24:36 +00:00
Fariborz Jahanian 84f4984331 objective-C: improve on warnings about misplacement of method
argument names. // rdar://12263549

llvm-svn: 164077
2012-09-17 23:09:59 +00:00
Fariborz Jahanian b14a3b24b1 objective-C: peroform property attribute consistency
checking on property declared in class extension.
// rdar://12214070

llvm-svn: 164053
2012-09-17 20:57:19 +00:00
Fariborz Jahanian f4ffdf357c objective-C: issue warning when there is no whitespace
between objc method parameter name and colon.
// rdar://12263549

llvm-svn: 164047
2012-09-17 19:15:26 +00:00
Jordan Rose 67e887c9b5 -Warc-retain-cycles: look through [^{...} copy] and Block_copy(^{...})
Retain cycles happen in the case where a block is persisted past its
life on the stack, and the way that occurs is by copying the block.
We should thus look through any explicit copies we see.

Note that Block_copy is actually a type-safe wrapper for _Block_copy,
which does all the real work.

<rdar://problem/12219663>

llvm-svn: 164039
2012-09-17 17:54:30 +00:00
Jordan Rose fa9e4badce -Warc-retain-cycles: warn at variable initialization as well as assignment.
Specifically, this should warn:

  __block block_t a = ^{ a(); };

Furthermore, this case which previously warned now does not, since the value
of 'b' is captured before the assignment occurs:

  block_t b; // not __block
  b = ^{ b(); };

(This will of course warn under -Wuninitialized, as before.)

<rdar://problem/11015883>

llvm-svn: 163962
2012-09-15 02:48:31 +00:00
Ted Kremenek edf22edca0 Teach -Wuninitialized to recognize common "noreturn" idioms in
Objective-C related to NSException.

Fixes <rdar://problem/12287498>

I debated whether or not this logic should be sunk into the CFG
itself.  It's not clear if we should, as different analyses may
wish to have different policies.  We can re-evaluate this in the
future.

llvm-svn: 163760
2012-09-13 00:21:35 +00:00
Fariborz Jahanian 70b8bd8ad6 objective-C arc: don't issue no explicit ownership warning when
__autoreleasing is explicitely added to param type.
// rdar://12280826

llvm-svn: 163738
2012-09-12 20:34:47 +00:00
Ted Kremenek 191ffd35a0 Revert "objective-C: warn under a flag if missing argument"
We plan on discussing this more, but we shouldn't have it in the compiler
in an incomplete state.

llvm-svn: 163720
2012-09-12 16:50:35 +00:00
Ted Kremenek 632a6432f5 Revert "objective-C: warn if selector has nothing but bare"
We plan on discussing this more.

llvm-svn: 163719
2012-09-12 16:50:30 +00:00
NAKAMURA Takumi fcd16e36c8 clang/test: [PR8833] Introduce the feature "LP64" to suppress LLP64-incompatible tests.
I think some of them could be rewritten to fit also LLP64.

llvm-svn: 163699
2012-09-12 10:45:40 +00:00
Fariborz Jahanian 822ab6b2e4 objective-C: warn if selector has nothing but bare
':' in its name. // rdar://8366823

llvm-svn: 163650
2012-09-11 21:27:45 +00:00
Fariborz Jahanian 66d2e88799 objective-C: warn under a flag if missing argument
name results in unintended selector name. 
// rdar://12263549

llvm-svn: 163634
2012-09-11 17:24:26 +00:00
Fariborz Jahanian d6876b20e7 More tweaking and test cases for call to super
annotations. // rdar://6386358

llvm-svn: 163525
2012-09-10 18:04:25 +00:00
Fariborz Jahanian b05417e1e1 objective-C: Improving diagnostocs for missing call to
super's annotated methods. // rdar://6386358

llvm-svn: 163517
2012-09-10 16:51:09 +00:00
Fariborz Jahanian 566fff0dac objective-C: introduce __attribute((objc_requires_super)) on method
in classes. Use it to flag those method implementations which don't
contain call to 'super' if they have 'super' class and it has the method
with this attribute set. This is wip. // rdar://6386358

llvm-svn: 163434
2012-09-07 23:46:23 +00:00
Fariborz Jahanian 979780f68f refactoring + objective-C specific test for my last patch.
// rdar://12233989

llvm-svn: 163338
2012-09-06 18:38:58 +00:00
Fariborz Jahanian 0e337543dc objective-C ARC; detect and warn on retain cycle when
property-dot syntax is used on an object whose
capture causes retain cycle. // rdar://11702054

llvm-svn: 163017
2012-08-31 20:04:47 +00:00
Fariborz Jahanian cd278ffa28 objective-C ARC: under -Wexplicit-ownership-type diagnose those
method parameter types which are reference to an objective-C
pointer to object with no explicit ownership. // rdar://10907090

llvm-svn: 162959
2012-08-30 23:56:02 +00:00
Ted Kremenek 2aa89dd03e Make this test portable.
llvm-svn: 162880
2012-08-30 00:27:25 +00:00
Ted Kremenek 7712eef0d7 Fix serious regression introduced in r157780 where __attribute__((NSObject))
could not be attached to a CFTypeRef.

Fixes <rdar://problem/12197822>

llvm-svn: 162872
2012-08-29 22:54:47 +00:00
Fariborz Jahanian f07bcc527a objective-C: make -Widiomatic-parentheses work
when assignment expression in conditional invloves
property reference. // rdar://11066598

llvm-svn: 162846
2012-08-29 17:17:11 +00:00
Fariborz Jahanian 272b7dc8ae objective-C arc: ns_returns_retained is a type attribute in ARC,
and when used in property type declaration, is handled as type
attribute. Do not issue the warning when declaraing the property. 
// rdar://12173491

llvm-svn: 162801
2012-08-28 22:26:21 +00:00
Fariborz Jahanian 1cfbe7a240 objective-C: Do not warn if align attribute on method
declaration is not provided. It is only necessary on
the method implementation. // rdar://11593375

llvm-svn: 162628
2012-08-24 23:50:13 +00:00
Fariborz Jahanian fd5cf6cf26 objective-C: When checking for valid overriden property
in class extension, assume default is rewdwrite and don't
issue any diagnostics, privided other ownership models
are ok.

llvm-svn: 162583
2012-08-24 20:10:53 +00:00
Fariborz Jahanian 27400e003c make test pass on linux platforms.
llvm-svn: 162324
2012-08-21 22:21:43 +00:00
Fariborz Jahanian 8d1ca5a142 objective-C: Change rules for overriding properties in
class extensions a little. clang now allows readonly property 
with no ownership rule (assign, unsafe_unretained, weak, retain, 
strong, or copy) with a readwrite property with an ownership rule.
// rdar://12103400 

llvm-svn: 162319
2012-08-21 21:45:58 +00:00
Fariborz Jahanian 350a17b7ce objective-C: make -Wcast-of-sel-type the default.
// rdar://12107381

llvm-svn: 162045
2012-08-16 20:16:46 +00:00
Fariborz Jahanian 5ad9659688 objective-C: deprecate casts of ObjC's SEL
expressions except to void, void * and their
qualified versions. // rdar://12107381

llvm-svn: 162036
2012-08-16 18:33:47 +00:00
Fariborz Jahanian 29622c1f0b objective-C: test for delayed parsing of K&R funcitons
inside objc class implementation. // rdar://10387088

llvm-svn: 161705
2012-08-10 22:01:36 +00:00
Eli Friedman 89b1f2c7e1 Handle deprecation diagnostics correctly for C struct fields and Objective-C properties/ivars. <rdar://problem/6642337>.
llvm-svn: 161534
2012-08-08 23:04:35 +00:00
Eli Friedman 971bfa11c6 Unify the codepaths for emitting deprecation warnings. The test changes are just to account for us emitting notes more consistently.
llvm-svn: 161528
2012-08-08 21:52:41 +00:00
Jordan Rose 742c6079e2 Implicitly annotate __CFStringMakeConstantString with format_arg(1).
We handled the builtin version of this function in r157968, but the builtin
isn't used when compiling as -fno-constant-cfstrings.

This should complete <rdar://problem/6157200>.

llvm-svn: 161525
2012-08-08 21:17:31 +00:00
Fariborz Jahanian a5063a6208 objc: Include all types when issuing warning under
-Wdirect-ivar-access.

llvm-svn: 161500
2012-08-08 16:41:04 +00:00
Fariborz Jahanian 285a7cc721 objc-arc: Make -Wdirect-ivar-access accessible to all
memory models, except when arc is accessing a weak
ivar (which is an error). // rdar://6505197

llvm-svn: 161458
2012-08-07 23:48:10 +00:00
Fariborz Jahanian a7c9f883e6 objective-c: Exclude -Wdirect-ivar-access for arc.
Allow direct ivar access in init and dealloc methods
in mrr. // rdar://650197

llvm-svn: 161426
2012-08-07 16:38:44 +00:00
Fariborz Jahanian 14f1aa70a9 objective-c: Implement gcc's -Wdirect-ivar-access option.
// rdar://6505197

llvm-svn: 161362
2012-08-06 23:50:51 +00:00