Commit Graph

1600 Commits

Author SHA1 Message Date
Alex Lorenz 0a484baa85 Warn about uses of `@available` that can't suppress the
-Wunguarded-availability warnings

rdar://32306520

Differential Revision: https://reviews.llvm.org/D33450

llvm-svn: 303761
2017-05-24 15:15:29 +00:00
Argyrios Kyrtzidis 9f4950afd2 Change __has_feature(objc_diagnose_if_attr) to __has_feature(attribute_diagnose_if_objc) for consistency with rest of attribute checks.
llvm-svn: 303713
2017-05-24 01:38:00 +00:00
Argyrios Kyrtzidis a7233bd801 Enhance the 'diagnose_if' attribute so that we can apply it for ObjC methods and properties as well
This is an initial commit to allow using it with constant expressions, a follow-up commit will enable full support for it in ObjC methods.

llvm-svn: 303712
2017-05-24 00:46:27 +00:00
Erik Pilkington 6ac77a6c37 [Sema][ObjC] Fix a bug where -Wunguarded-availability was emitted at the wrong location
Differential revision: https://reviews.llvm.org/D33250

llvm-svn: 303562
2017-05-22 15:41:12 +00:00
Alex Lorenz 6f91112051 [Sema] Avoid duplicate -Wunguarded-availability warnings in nested functions
rdar://31862310

llvm-svn: 303170
2017-05-16 13:58:53 +00:00
Erich Keane 7300119abb Fix errored return value in CheckFunctionReturnType and add a fixit hint
As discovered by ChenWJ and listed on cfe-dev, the error for Objective C 
return type ended up being wrong. This fixes that. Additionally, as a 
"while we're there", the other usages of this error and the usage of the 
FP above both use a FixItHint, so I'll add it here.

Differential Revision: https://reviews.llvm.org/D32759

llvm-svn: 302720
2017-05-10 20:03:16 +00:00
Alex Lorenz e1fb64e5e2 Add support for pretty platform names to `@available`/
`__builtin_available`

This commit allows us to use the macOS/iOS/tvOS/watchOS platform names in
`@available`/`__builtin_available`.

rdar://32067795

Differential Revision: https://reviews.llvm.org/D33000

llvm-svn: 302540
2017-05-09 15:34:46 +00:00
Alex Lorenz 9282483b11 [ObjC] Don't disallow vector parameters/return values in methods
whose introduced version is lower than the allowed version.

We should just rely on the target version as this introduced version can lead
to false positives (e.g. deprecated declarations).

rdar://31964333

llvm-svn: 302250
2017-05-05 16:15:17 +00:00
Alex Lorenz a8a372d85e [ObjC] Disallow vector parameters and return values in Objective-C methods
for iOS < 9 and OS X < 10.11 X86 targets

This commit adds a new error that disallows methods that have parameters/return
values with a vector type for some older X86 targets. This diagnostic is
needed because objc_msgSend doesn't support SIMD vector registers/return values
on X86 in iOS < 9 and OS X < 10.11. Note that we don't necessarily know if the
vector argument/return value will use a SIMD register, so instead we chose to
be conservative and prohibit all vector types.

rdar://21662309

Differential Revision: https://reviews.llvm.org/D28670

llvm-svn: 301532
2017-04-27 10:43:48 +00:00
Alex Lorenz 28559ceece -Wunguarded-availability should support if (@available) checks in top-level
blocks and lambdas

Prior to this commit Clang emitted the old "partial availability" warning for
expressions that referred to declarations that were not yet introduced in
blocks and lambdas that were not in a function/method. This commit ensures that
top-level blocks and lambdas use the new unguarded availability checks.

rdar://31835952

llvm-svn: 301409
2017-04-26 14:20:02 +00:00
Akira Hatanaka 3901377c22 [Sema][ObjC] Disallow jumping into ObjC fast enumeration loops.
rdar://problem/31635406

Differential Revision: https://reviews.llvm.org/D32187

llvm-svn: 300722
2017-04-19 17:54:08 +00:00
Alex Lorenz 535571a2a1 [Sema][ObjC] Avoid the "type of property does not match type of accessor"
warning for methods that resemble the setters of readonly properties

rdar://30415679

llvm-svn: 299078
2017-03-30 13:33:51 +00:00
Brian Kelley 11352a8fb9 [Objective-C] Fix "weak-unavailable" warning with -fobjc-weak
Summary: clang should produce the same errors Objective-C classes that cannot be assigned to weak pointers under both -fobjc-arc and -fobjc-weak. Check for ObjCWeak along with ObjCAutoRefCount when analyzing pointer conversions. Add an -fobjc-weak pass to the existing arc-unavailable-for-weakref test cases to verify the behavior is the same.

Reviewers: rsmith, doug.gregor, rjmccall

Reviewed By: rjmccall

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D31006

llvm-svn: 299014
2017-03-29 18:09:02 +00:00
Brian Kelley cafd9121cb [Objective-C] Fix "repeated use of weak" warning with -fobjc-weak
Summary: -Warc-repeated-use-of-weak should produce the same warnings with -fobjc-weak as it does with -objc-arc. Also check for ObjCWeak along with ObjCAutoRefCount when recording the use of an evaluated weak variable. Add a -fobjc-weak run to the existing arc-repeated-weak test case and adapt it slightly to work in both modes.

Reviewers: rsmith, doug.gregor, jordan_rose, rjmccall

Reviewed By: rjmccall

Subscribers: arphaman, rjmccall, cfe-commits

Differential Revision: https://reviews.llvm.org/D31005

llvm-svn: 299011
2017-03-29 17:55:11 +00:00
Erich Keane a32910da1a Correct class-template deprecation behavior-REDUX
Correct class-template deprecation behavior

Based on the comment in the test, and my reading of the standard, a deprecated warning should be issued in the following case:
template<typename T> [[deprecated]] class Foo{}; Foo<int> f;

This was not the case, because the ClassTemplateSpecializationDecl creation did not also copy the deprecated attribute.

Note: I did NOT audit the complete set of attributes to see WHICH ones should be copied, so instead I simply copy ONLY the deprecated attribute.

Previous DiffRev: https://reviews.llvm.org/D27486, was reverted.
This patch fixes the issues brought up here by the reverter: https://reviews.llvm.org/rL298410

Differential Revision: https://reviews.llvm.org/D31245

llvm-svn: 298634
2017-03-23 18:51:54 +00:00
Alex Lorenz f937139530 Support attributes for Objective-C categories
rdar://31095315

Differential Revision: https://reviews.llvm.org/D31179

llvm-svn: 298589
2017-03-23 11:44:25 +00:00
Alex Lorenz 5ffe4e14f1 [ObjC][ARC] Avoid -Warc-performSelector-leaks for performSelector variations
that became supported after r297019

The commit r297019 expanded the performSelector ObjC method family heuristic
to ensure that -Wobjc-unsafe-perform-selector covers all performSelector
variations. However, this made the -Warc-performSelector-leaks too noisy, as
that warning produces mostly false positives since the selector is unknown.
This commit reverts the ObjC method family heuristics introduced in r297019.
This ensures that -Warc-performSelector-leaks isn't too noisy. The commit still
preserves the coverage of -Wobjc-unsafe-perform-selector.

rdar://31124629

llvm-svn: 298587
2017-03-23 10:46:05 +00:00
Martin Bohme 926572303e Revert "Correct class-template deprecation behavior"
This reverts commit r298410 (which produces incorrect warnings, see
comments on https://reviews.llvm.org/rL298410).

llvm-svn: 298504
2017-03-22 13:34:37 +00:00
Erich Keane 8a8f5f0f00 Correct class-template deprecation behavior
Based on the comment in the test, and my reading of the standard, a deprecated warning should be issued in the following case:
template<typename T> [[deprecated]] class Foo{}; Foo<int> f;

This was not the case, because the ClassTemplateSpecializationDecl creation did not also copy the deprecated attribute.

Note: I did NOT audit the complete set of attributes to see WHICH ones should be copied, so instead I simply copy ONLY the deprecated attribute.

Differential Revision: https://reviews.llvm.org/D27486

llvm-svn: 298410
2017-03-21 17:49:17 +00:00
Alex Lorenz 3e54835ad7 [ObjC][Sema] Avoid ARC performSelector error for 'self' selector
The instance method 'self' does not actually return an over-retained object,
so we shouldn't report an error when it's used with 'performSelector'.

rdar://31071620

llvm-svn: 297961
2017-03-16 16:36:11 +00:00
Alex Lorenz 5e895cf2c3 [ObjC][Sema] Avoid warning about a call to an instance method on an
instance of a qualified Class object when that instance method comes from
a protocol that's implemented by NSObject

Instance methods from a root class like NSObject are also class methods because
the metaclass of root class derives from that root class. Therefore, we can
avoid the warning for instances of qualified Class objects that point to classes
that derive from NSObject. Note that we actually don't know if a Class instance
points to a class that derives from NSObject at compile-time, so we have to
make a reasonable assumption that the majority of instances will do so.

rdar://22812517

llvm-svn: 297862
2017-03-15 17:16:41 +00:00
Alex Lorenz 0e23c61c87 [Sema][ObjC] Warn about 'performSelector' calls with selectors
that return record or vector types

The performSelector family of methods from Foundation use objc_msgSend to
dispatch the selector invocations to objects. However, method calls to methods
that return record types might have to use the objc_msgSend_stret as the return
value won't find into the register. This is also supported by this sentence from
performSelector documentation: "The method should not have a significant return
value and should take a single argument of type id, or no arguments". This
commit adds a new warning that warns when a selector which corresponds to a
method that returns a record type is passed into performSelector.

rdar://12056271

Differential Revision: https://reviews.llvm.org/D30174

llvm-svn: 297019
2017-03-06 15:58:34 +00:00
Saleem Abdulrasool b3a2d04edd Sema: use PropertyDecl for property selector
Using the constructed name for the class properties with dot syntax may
yield an inappropriate selector (i.e. if it is specified via property
attributes).  Prefer the declaration for the selector, falling back to
the constructed name otherwise.

Patch by David Herzka!

llvm-svn: 295683
2017-02-20 23:45:49 +00:00
Alex Lorenz 51c0128310 [Sema][ObjC] perform-selector ARC check should see @selector in parens
llvm-svn: 295674
2017-02-20 17:55:15 +00:00
Alex Lorenz 55aaa844cb Use correct fix-it location for -Wblock-capture-autoreleasing
The '__autoreleasing' keyword should be inserted after the Objective-C pointer
type.

rdar://30123548

llvm-svn: 295381
2017-02-16 23:15:36 +00:00
Akira Hatanaka 034c6337e5 [Sema][ObjC] Don't pass a DeclRefExpr that doesn't reference a VarDecl
to WeakObjectProfileTy's constructor.

This fixes an assertion failure in WeakObjectProfileTy's constructor.

rdar://problem/30112633

llvm-svn: 293808
2017-02-01 20:22:26 +00:00
Akira Hatanaka c05c42567e Turn on -Wblock-capture-autoreleasing by default.
Turning on the warning by default helps the users as it's a common
mistake to capture out-parameters in a block without ensuring the object
assigned doesn't get released.

rdar://problem/30200058

llvm-svn: 293199
2017-01-26 18:51:10 +00:00
Akira Hatanaka 5d55a6c69d [Sema][ObjC] Make sure -Wblock-capture-autoreleasing issues a warning
even in the presence of nullability qualifiers.

This commit fixes bugs in r285031 where -Wblock-capture-autoreleasing
wouldn't issue warnings when the function parameters were annotated
with nullability qualifiers. Specifically, look through the sugar and
see if there is an AttributedType of kind attr_objc_ownership to
determine whether __autoreleasing was explicitly specified or implicitly
added by the compiler.

rdar://problem/30193488

llvm-svn: 293194
2017-01-26 18:13:06 +00:00
Alex Lorenz c7dc1a2a3c [ObjC] The declarator for a block literal should be a definition
This change avoids the -Wstrict-prototypes warning for block literals with an
empty argument list or without argument lists.

rdar://15060615

Differential Revision: https://reviews.llvm.org/D28296

llvm-svn: 291231
2017-01-06 11:31:12 +00:00
Mehdi Amini 9f10f34a6b Fix printf specifier handling: invalid specifier should not be marked as "consuming data arguments"
Reviewers: rsmith, bruno, dexonsmith

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D27796

llvm-svn: 289850
2016-12-15 18:54:00 +00:00
Paul Robinson 41a2508e59 [PS4] Undo dialect tweak for Objective-C.
In r267772, we had set the PS4's default dialect for both C and
Objective-C to gnu99.  Make that change only for C; we don't really
support Objective-C/C++ so there's no point fiddling the dialect.

llvm-svn: 289625
2016-12-14 02:06:11 +00:00
Richard Smith 4baaa5ab52 DR616, and part of P0135R1: member access (or pointer-to-member access) on a
temporary produces an xvalue, not a prvalue. Support this by materializing the
temporary prior to performing the member access.

llvm-svn: 288563
2016-12-03 01:14:32 +00:00
Alex Lorenz ff6c34b30d [ObjC] Prevent infinite loops when iterating over redeclaration
of a method that was declared in an invalid interface

This commit fixes an infinite loop that occurs when clang tries to iterate over
redeclaration of a method that was declared in an invalid @interface. The
existing validity checks don't catch this as that @interface is a duplicate of
a previously declared valid @interface declaration, so we have to verify that
the found redeclaration is in a valid declaration context.

rdar://29220965

Differential Revision: https://reviews.llvm.org/D26664

llvm-svn: 287530
2016-11-21 11:16:30 +00:00
Saleem Abdulrasool 765a219431 Sema: correct typo correction for ivars in @implementation
The previous typo correction handling assumed that ivars are only declared in
the interface declaration rather than as a private ivar in the implementation.
Adjust the handling to permit both interfaces.  Assert earlier that the
interface has been acquired to ensure that we can identify when both possible
casts have failed.

Addresses PR31040!

llvm-svn: 287238
2016-11-17 17:10:54 +00:00
Jordan Rose 303e2f1eac Accept nullability qualifiers on array parameters.
Since array parameters decay to pointers, '_Nullable' and friends
should be available for use there as well. This is especially
important for parameters that are typedefs of arrays. The unsugared
syntax for this follows the syntax for 'static'-sized arrays in C:

  void test(int values[_Nullable]);

This syntax was previously accepted but the '_Nullable' (and any other
attributes) were silently discarded. However, applying '_Nullable' to
a typedef was previously rejected and is now accepted; therefore, it
may be necessary to test for the presence of this feature:

  #if __has_feature(nullability_on_arrays)

One important change here is that DecayedTypes don't always
immediately contain PointerTypes anymore; they may contain an
AttributedType instead. This only affected one place in-tree, so I
would guess it's not likely to cause problems elsewhere.

This commit does not change -Wnullability-completeness just yet. I
want to think about whether it's worth doing something special to
avoid breaking existing clients that compile with -Werror. It also
doesn't change '#pragma clang assume_nonnull' behavior, which
currently treats the following two declarations as equivalent:

  #pragma clang assume_nonnull begin
  void test(void *pointers[]);
  #pragma clang assume_nonnull end

  void test(void * _Nonnull pointers[]);

This is not the desired behavior, but changing it would break
backwards-compatibility. Most likely the best answer is going to be
adding a new warning.

Part of rdar://problem/25846421

llvm-svn: 286519
2016-11-10 23:28:17 +00:00
Alex Lorenz a5430bd5d6 Add -Wduplicate-protocol for existing diagnostic
Expose a warning flag for warn_duplicate_protocol_def. This allows control
over the severity of duplicate protocol definitions.

For example -Werror=duplicate-protocol or
#pragma clang diagnostic ignored "-Wduplicate-protocol".

Patch provided by Dave Lee!

Differential Revision: https://reviews.llvm.org/D26406

llvm-svn: 286487
2016-11-10 18:30:26 +00:00
Erik Pilkington a80039721a [Sema] Delay partial availability diagnostics, just like deprecated
This is done so that the following compiles with no warnings:
int fn(type_10_12) __attribute__((availability(macos, introduced=10.12)));

Differential revision: https://reviews.llvm.org/D25284

llvm-svn: 285457
2016-10-28 21:39:27 +00:00
Alex Lorenz a8c44ba2c0 [Objective-C] Add objc_subclassing_restricted attribute
This patch adds an objc_subclassing_restricted attribute into clang. This
attribute acts similarly to 'final' - Objective-C classes with this attribute
can't be subclassed. However, @interface declarations that have
objc_subclassing_restricted but don't have @implementation are allowed to
inherit other @interface declarations with objc_subclassing_restricted. This is
needed to describe the Swift class hierarchy in clang while making sure that
the Objective-C classes cannot subclass the Swift classes.

This attribute is already implemented in a fork of clang that's used for Swift
(https://github.com/apple/swift-clang) and this patch moves that code to the
upstream clang repository.

rdar://28937548

Differential Revision: https://reviews.llvm.org/D25993

llvm-svn: 285391
2016-10-28 10:25:10 +00:00
Erik Pilkington f35114c543 Reapply r284265: "[Sema] Refactor context checking for availability diagnostics"
The problem with the original commit was that some of Apple's headers depended
on an incorrect behaviour, this commit adds a temporary workaround until those
headers are fixed.

llvm-svn: 285098
2016-10-25 19:05:50 +00:00
Benjamin Kramer 7dc585763e Fix diagnostic format string for err_os_log_argument_to_big
Patch by Sam McCall, test case by me.

Differential Revision: https://reviews.llvm.org/D25936

llvm-svn: 285065
2016-10-25 12:39:28 +00:00
Akira Hatanaka c81708e6ec [Sema][ObjC] Warn about implicitly autoreleasing out-parameters captured
by blocks.

Add a new warning "-Wblock-capture-autoreleasing". The warning warns
about implicitly autoreleasing out-parameters captured by blocks which
can introduce use-after-free bugs that are hard to debug.

rdar://problem/15377548

Differential Revision: https://reviews.llvm.org/D25844

llvm-svn: 285031
2016-10-24 21:45:54 +00:00
Mehdi Amini 06d367c6c6 Add support for __builtin_os_log_format[_buffer_size]
This reverts commit r285007 and reapply r284990, with a fix for the
opencl test that I broke. Original commit message follows:

These new builtins support a mechanism for logging OS events, using a
printf-like format string to specify the layout of data in a buffer.
The _buffer_size version of the builtin can be used to determine the size
of the buffer to allocate to hold the data, and then __builtin_os_log_format
can write data into that buffer. This implements format checking to report
mismatches between the format string and the data arguments. Most of this
code was written by Chris Willmore.

Differential Revision: https://reviews.llvm.org/D25888

llvm-svn: 285019
2016-10-24 20:39:34 +00:00
Mehdi Amini 9c39fdceda Revert "Add support for __builtin_os_log_format[_buffer_size]"
This reverts commit r284990, two opencl test are broken

llvm-svn: 285007
2016-10-24 19:41:36 +00:00
Mehdi Amini 29034362ae Add support for __builtin_os_log_format[_buffer_size]
These new builtins support a mechanism for logging OS events, using a
printf-like format string to specify the layout of data in a buffer.
The _buffer_size version of the builtin can be used to determine the size
of the buffer to allocate to hold the data, and then __builtin_os_log_format
can write data into that buffer. This implements format checking to report
mismatches between the format string and the data arguments. Most of this
code was written by Chris Willmore.

Differential Revision: https://reviews.llvm.org/D25888

llvm-svn: 284990
2016-10-24 16:56:23 +00:00
Alex Lorenz d900714299 [Sema] Formatting warnings should see through Objective-C message sends
This commit improves the '-Wformat' warnings by ensuring that the formatting
checker can see through Objective-C message sends when we are calling an
Objective-C method with an appropriate format_arg attribute.

rdar://23622446

Differential Revision: https://reviews.llvm.org/D25820

llvm-svn: 284961
2016-10-24 09:42:34 +00:00
Erik Pilkington d080746c19 Revert r284265 "[Sema] Refactor context checking for availability diagnostics"
This has a bug in it, pointed out by Bob Wilson!

llvm-svn: 284486
2016-10-18 15:26:43 +00:00
Erik Pilkington 88eff2575e [Sema] Refactor context checking for availability diagnostics
This commit combines a couple of redundant functions that do availability
attribute context checking into a more correct/simpler one.

Differential revision: https://reviews.llvm.org/D25283

llvm-svn: 284265
2016-10-14 19:08:01 +00:00
Bruno Cardoso Lopes 218c8743c8 [SemaObjC] Be more strict while parsing type arguments and protocols
Fix a crash-on-invalid.

When parsing type arguments and protocols,
parseObjCTypeArgsOrProtocolQualifiers() calls ParseTypeName(), which tries to
find matching tokens for '[', '(', etc whenever they appear among potential
type names. If unmatched, ParseTypeName() yields a tok::eof token stream. This
leads to crashes since the parsing at this point is not expected to go beyond
the param list closing '>'.

Fix that by properly handling tok::eof in
parseObjCTypeArgsOrProtocolQualifiers() callers.

Differential Revision: https://reviews.llvm.org/D23852

rdar://problem/25063557

llvm-svn: 281383
2016-09-13 20:04:35 +00:00
Manman Ren c5705bae05 ObjectiveC Generics: Start using ObjCTypeParamType.
For ObjC type parameter, we used to have TypedefType that is canonicalized to
id or the bound type. We can't represent "T <protocol>" and thus will lose
the type information in the following example:
@interface MyMutableDictionary<KeyType, ObjectType> : NSObject
- (void)setObject:(ObjectType)obj forKeyedSubscript:(KeyType <NSCopying>)key;
@end
MyMutableDictionary<NSString *, NSString *> *stringsByString;
NSNumber *n1, *n2;
stringsByString[n1] = n2;
--> no warning on type mismatch of the key.

To fix the problem, we introduce a new type ObjCTypeParamType that supports
a list of protocol qualifiers.

We create ObjCTypeParamType for ObjCTypeParamDecl when we create
ObjCTypeParamDecl. We also substitute ObjCTypeParamType instead of TypedefType
on an ObjCTypeParamDecl.

rdar://24619481
rdar://25060179

Differential Revision: http://reviews.llvm.org/D23080

llvm-svn: 281358
2016-09-13 17:41:05 +00:00
Bruno Cardoso Lopes 25f02cfc52 [SemaObjC] Do not RebuildObjCMessageExpr without valid method decl
Fix crash-on-invalid in ObjC Sema by avoiding to rebuild a message
expression to a 'super' class in case the method to call does not exist
(i.e. comes from another missing identifier).

In this case, the typo transform is invoked upon the message expression
in an attempt to solve a typo in a 'super' call parameters, but it
crashes since it assumes the method to call has a valid declaration.

rdar://problem/27305403

llvm-svn: 279481
2016-08-22 21:50:22 +00:00