Commit Graph

1553 Commits

Author SHA1 Message Date
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
Erik Pilkington 5cd57177a5 [ObjC] Warn on unguarded use of partial declaration
This commit adds a traversal of the AST after Sema of a function that diagnoses
unguarded references to declarations that are partially available (based on
availability attributes). This traversal is only done when we would otherwise
emit -Wpartial-availability.

This commit is part of a feature I proposed here:
http://lists.llvm.org/pipermail/cfe-dev/2016-July/049851.html

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

llvm-svn: 278826
2016-08-16 17:44:11 +00:00
Manman Ren ef61168708 Objective-C diagnostics: isObjCNSObjectType should check through AttributedType.
For the following example:
typedef __attribute__((NSObject)) CGColorRef ColorAttrRef;
@property (strong, nullable) ColorAttrRef color;
The property type should be ObjC NSObject type and the compiler should not emit
error: property with 'retain (or strong)' attribute must be of object type

rdar://problem/27747154

llvm-svn: 278742
2016-08-15 21:05:00 +00:00
Erik Pilkington 3f3fbf6b6c [ObjC Availability] Fix partial-availability false positive introduced in r277058
Thanks to Nico Weber for pointing this out!

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

llvm-svn: 277378
2016-08-01 20:19:49 +00:00
Erik Pilkington 48c7cc9bc0 Reapply r277058: "[ObjC] Consider availability of context when emitting availability warnings"
llvm-svn: 277175
2016-07-29 17:37:38 +00:00
Erik Pilkington 376789fc73 Revert "[ObjC] Consider availability of context when emitting availability warnings"
Reverting r277058, while I fugure out why it broke internal bots.

This reverts commit e514ffa8b657416c6784bbe6da9f5de19365103d.

llvm-svn: 277070
2016-07-28 22:51:11 +00:00
Erik Pilkington 4f2dd2d4f2 [ObjC] Consider availability of context when emitting availability warnings
This means that a function marked with an availability attribute can safely
refer to a declaration that is greater than the deployment target, but less then
or equal to the context availability without -Wpartial-availability firing.

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

llvm-svn: 277058
2016-07-28 22:09:53 +00:00
Akira Hatanaka 1b07496cea [Sema][ObjC] Compute the nullability of a conditional expression based
on the nullabilities of its operands.

This commit is a follow-up to r276076 and enables
computeConditionalNullability to compute the merged nullability when
the operands are objective-c pointers.

rdar://problem/22074116

llvm-svn: 276696
2016-07-25 21:58:19 +00:00
Bruno Cardoso Lopes 1383ddc40b [SemaObjC] Improve ObjCDictionaryLiteral and ObjCArryLiteral diagnostics
Sema actions on ObjCDictionaryLiteral and ObjCArryLiteral are currently
done as a side-effect of Sema upon parent expressions, which incurs of
delayed typo corrections for such literals to be performed by TypoTransforms
upon the ObjCDictionaryLiteral and ObjCArryLiteral themselves instead of
its elements individually.

This is specially bad because it was not designed to act on several
elements; searching through all possible combinations of corrections for
several elements is very expensive. Additionally, when one of the
elements has no correction candidate, we still explore all options and
at the end emit no typo corrections whatsoever.

Do the proper sema actions by acting on each element alone during appropriate
literal parsing time to get proper diagonistics and decent compile time
behavior.

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

rdar://problem/21046678

llvm-svn: 276020
2016-07-19 20:21:18 +00:00
Saleem Abdulrasool 511f2e5a89 Sema: support __declspec(dll*) on ObjC interfaces
Extend the __declspec(dll*) attribute to cover ObjC interfaces.  This was
requested by Microsoft for their ObjC support.  Cover both import and export.
This only adds the semantic analysis portion of the support, code-generation
still remains outstanding.  Add some basic initial documentation on the
attributes that were previously empty.  Tweak the previous tests to use the
relative expected-warnings to make the tests easier to read.

llvm-svn: 275610
2016-07-15 20:41:10 +00:00
Manman Ren 2b2b1a9200 ObjC Class Property: diagnostics when accessing a class property using instance.
When a class property is accessed with an object instance, before this commit,
we try to apply a typo correction of the same property:
property 'c' not found on object of type 'A *'; did you mean 'c'?

With this commit, we correctly emit a diagnostics:
property 'c' is a class property; did you mean to access it with class 'A'?

rdar://26866973

llvm-svn: 274076
2016-06-28 23:01:49 +00:00
Manman Ren ccf25bbf3f AvailabilityAttr: we accept "macos" as the platform name.
We continue accepting "macosx" but canonicalize it to "macos", When emitting
diagnostics, we use "macOS" instead of "OS X".

The PlatformName in TargetInfo is changed from "macosx" to "macos" so we can
directly compare the Platform in AvailabilityAttr with the PlatformName
in TargetInfo.

rdar://26795172
rdar://26800775

llvm-svn: 274064
2016-06-28 20:55:30 +00:00
Manman Ren 2c3933f402 ObjC lifetime: pull sugar off when the qualifiers conflict.
It's possible to have multiple local ObjCLifetime qualifiers. When there is
a conflict, we can't stop after we reach a type that is directly qualified.
We need to keep pulling sugar off and removing the ObjCLifetime qualifers.

rdar://25804796

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

llvm-svn: 271409
2016-06-01 17:14:19 +00:00
Akira Hatanaka d1af08c3d6 Don't feed standard error to FileCheck.
This is an attempt to fix the buildbot that started failing after
r270808.

http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/13141 

llvm-svn: 270817
2016-05-26 02:32:10 +00:00
Akira Hatanaka de6f25f6a3 [ObjC] Remove _Atomic from return type and parameter type of
objective-c properties.

This fixes an assert in CodeGen that fires when the getter and setter
functions for an objective-c property of type _Atomic(_Bool) are
synthesized.

rdar://problem/26322972

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

llvm-svn: 270808
2016-05-26 00:37:30 +00:00
Bob Wilson f4f54e3178 arc-repeated-use-of-weak should not warn about IBOutlet properties
Revision r211132 was supposed to disable -Warc-repeated-use-of-weak for
Objective-C properties marked with the IBOutlet attribute. Those properties
are supposed to be weak but they are only accessed from the main thread
so there is no risk of asynchronous updates setting them to nil. That
combination makes -Warc-repeated-use-of-weak very noisy. The previous
change only handled one kind of access to weak IBOutlet properties.
Instead of trying to add checks for all the different kinds of property
accesses, this patch removes the previous special case check and adds a
check at the point where the diagnostic is reported. rdar://21366461

llvm-svn: 270665
2016-05-25 05:41:57 +00:00
Manman Ren b7fda4baa9 ObjectiveC: canonicalize "kindof id" to "id".
There is no need to apply kindof on an unqualified id type.

rdar://24753825

llvm-svn: 270241
2016-05-20 17:29:43 +00:00
Manman Ren 08ce73470c ObjectiveC Class Properties: warn if a class property accessor is mistakenly an
instance method.

When diagnosing unimplemented class property, make sure we emit
a warning when we only see an instance method with the right selector.

Also warn when we only see a class method for an instance property.

rdar://26141719

llvm-svn: 269968
2016-05-18 18:12:34 +00:00
Manman Ren c46f7d1883 ObjC kindof: set the type of a conditional expression when involving kindof.
When either LHS or RHS is a kindof type, we return a kindof type.

rdar://problem/20513780

llvm-svn: 268781
2016-05-06 19:35:02 +00:00
Paul Robinson e801f6a7f4 Add a Subjects line to NoDebugAttr [NFC].
The 'nodebug' attribute had hand-coded constraints; replace those with
a Subjects line in Attr.td.
Also add a missing test to verify the attribute is okay on an
Objective-C method.

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

llvm-svn: 268065
2016-04-29 17:03:34 +00:00
Sunil Srivastava bf01080672 Set the default C standard to C99 when targeting the PS4.
Patch by Douglas Yung!

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

llvm-svn: 267772
2016-04-27 19:53:03 +00:00
Bob Wilson 410ae489b4 Remove the (ignored) -Wreceived-is-weak diagnostic.
We kept this around for a while since Xcode 6 and earlier had a build
setting for this warning. It was removed in Xcode 7 so there should be
no need for this warning now.

llvm-svn: 266938
2016-04-21 00:11:24 +00:00
Manman Ren 99d133482f Block: Fix a crash when we have type attributes or qualifiers with omitted
return type.

Emit a warning instead of crashing in IR generation.

rdar://22762981

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

llvm-svn: 266648
2016-04-18 18:40:51 +00:00
Manman Ren 051d0b620d ObjC kindof: order the methods in global pool relative to availability.
r265877 tries to put methods that are deprecated or unavailable to the
front of the global pool to emit diagnostics, but it breaks some of
our existing codes that depend on choosing a certain method for id
lookup.

This commit orders the methods with the same declaration with respect
to the availability, but do not order methods with different declaration.

rdar://25707511

llvm-svn: 266264
2016-04-13 23:43:56 +00:00
Bruno Cardoso Lopes c54768f7fa [SemaObjC] Properly handle mix between type arguments and protocols.
Under certain conditions clang currently fails to properly diagnostic ObjectC
parameter list when type args and protocols are mixed in the same list. This
happens when the first item in the parameter list is a (1) protocol, (2)
unknown type or (3) a list of protocols/unknown types up to the first type
argument. Fix the problem to report the proper error, example:

NSArray<M, NSValue *, NSURL, NSArray <id <M>>> *foo = @[@"a"];
NSNumber *bar = foo[0];
NSLog(@"%@", bar);

$ clang ...
x.m:7:13: error: angle brackets contain both a type ('NSValue') and a protocol ('M')
        NSArray<M, NSValue *, NSURL, NSArray <id <M>>> *foo = @[@"a"];
                ~  ^

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

rdar://problem/22204367

llvm-svn: 266245
2016-04-13 20:59:07 +00:00
Manman Ren 16a7d637dd ObjC class properties: add diagnostics for unimplemented class properties.
rdar://24711047

llvm-svn: 266146
2016-04-12 23:01:55 +00:00
Manman Ren 71224530c1 ObjC kindof: check the context when inserting methods to global pool.
To make kindof lookup work, we need to insert methods with different
context into the global pool, even though they have the same siganture.

Since diagnosis of availability is performed on the best candidate,
which is often the first candidate from the global pool, we prioritize
the methods that are unavaible or deprecated to the head of the list.

Since we now have more methods in the global pool, we need to watch
out for performance impact.

rdar://25635831

llvm-svn: 265877
2016-04-09 18:59:48 +00:00
Manman Ren 7ed4f988c1 [ObjC kindof] Use type bound to filter out the candidate methods.
rdar://21306753

llvm-svn: 265712
2016-04-07 19:32:24 +00:00
Douglas Gregor 24ae22c047 [Objective-C] Introduce objc_runtime_visible attribute.
The objc_runtime_visible attribute deals with an odd corner case where
a particular Objective-C class is known to the Objective-C runtime
(and, therefore, accessible by name) but its symbol has been hidden
for some reason. For such classes, teach CodeGen to use
objc_lookUpClass to retrieve the Class object, rather than referencing
the class symbol directly.

Classes annotated with objc_runtime_visible have two major limitations
that fall out from places where Objective-C metadata needs to refer to
the class (or metaclass) symbol directly:

* One cannot implement a subclass of an objc_runtime_visible class.
* One cannot implement a category on an objc_runtime_visible class.

Implements rdar://problem/25494092.

llvm-svn: 265201
2016-04-01 23:23:52 +00:00
Bruno Cardoso Lopes 03e18d41ad [Sema] Attempt [3] to fix tests for utf-8 invalid format string specifiers
Make the tests darwin only. The bots complaining already output UTF-8
invalid specifiers, test the output as we expect on darwin systems.

llvm-svn: 264788
2016-03-29 21:30:58 +00:00
Bruno Cardoso Lopes 10b1c8031f [Sema] Attempt [2] to fix tests for utf-8 invalid format string specifiers
Some buildbots still complain. Followup from r264752 and 264765.

llvm-svn: 264784
2016-03-29 20:47:09 +00:00
Bruno Cardoso Lopes dc195d005f [Sema] Attempt to fix tests for utf-8 invalid format string specifiers
Followup from r264752.

Attempt to appease buildbots:
 http://lab.llvm.org:8011/builders/clang-ppc64be-linux/builds/2882
 http://lab.llvm.org:8011/builders/clang-s390x-linux/builds/2619

llvm-svn: 264765
2016-03-29 18:38:44 +00:00
Bruno Cardoso Lopes 0c18d03d91 [Sema] Handle UTF-8 invalid format string specifiers
Improve invalid format string specifier handling by printing out
invalid specifiers characters with \x, \u and \U. Previously clang
would print gargabe whenever the character is unprintable.

Example, before:
  NSLog(@"%\u25B9"); => warning: invalid conversion specifier ' [-Wformat-invalid-specifier]
after:
  NSLog(@"%\u25B9"); => warning: invalid conversion specifier '\u25b9' [-Wformat-invalid-specifier]

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

rdar://problem/24672159

llvm-svn: 264752
2016-03-29 17:35:02 +00:00
Manman Ren 15325f80af ObjC: add getter/setter for class properties to global pool.
rdar://problem/25323072

llvm-svn: 264196
2016-03-23 21:39:31 +00:00
Manman Ren 6d93ad844a ObjC: Handle boolean fixed type for enum.
Before this commit, we assert failure in ImplicitCastExpr
"unheralded conversion to bool". This commit fixes the assertion by using
the correct cast type when the fixed type is boolean.

This commit also fixes the behavior for Microsoft mode as well, since
Obj-C and Microsoft mode share the same code path.

rdar://24999533

llvm-svn: 264167
2016-03-23 16:28:28 +00:00
Akira Hatanaka 7e2c82da90 [Objective-c] Do not set IsExact to true when the receiver is a class.
IsExact shouldn't be set to true in WeakObjectProfileTy::getBaseInfo
when the receiver is a class because having a class as the receiver
doesn't guarantee that the Base is exact.

This is a follow-up to r263818.

rdar://problem/25208167

llvm-svn: 264025
2016-03-22 05:00:21 +00:00
Akira Hatanaka 4c62c7c981 [Objective-c] Fix a crash in WeakObjectProfileTy::getBaseInfo.
The crash occurs in WeakObjectProfileTy::getBaseInfo when getBase() is
called on an ObjCPropertyRefExpr object whose receiver is an interface.
This commit fixes the crash by checking the type of the receiver and
setting IsExact to true if it is an interface.

rdar://problem/25208167

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

llvm-svn: 263818
2016-03-18 19:03:50 +00:00
Bob Wilson 57819fc809 Move the fixit for -Wformat-security to a note.
r263299 added a fixit for the -Wformat-security warning, but that runs
into complications with our guideline that error recovery should be done
as-if the fixit had been applied. Putting the fixit on a note avoids that.

llvm-svn: 263584
2016-03-15 20:56:38 +00:00
Bob Wilson cf2cf0dba4 Add fix-it for format-security warnings.
llvm-svn: 263299
2016-03-11 21:55:37 +00:00
Manman Ren 515758e076 Add has_feature objc_class_property.
rdar://23891898

llvm-svn: 263171
2016-03-10 23:51:03 +00:00
Manman Ren 073db02476 Add TreatUnavailableAsInvalid for the verification-only mode in InitListChecker.
Given the following test case:
typedef struct {
  const char *name;
  id field;
} Test9;
extern void doSomething(Test9 arg);
void test9() {
  Test9 foo2 = {0, 0};
  doSomething(foo2);
}
With a release compiler, we don't emit any message and silently ignore the
variable "foo2". With an assert compiler, we get an assertion failure.

The root cause —————————————
Back in r140457 we gave InitListChecker a verification-only mode, and will use
CanUseDecl instead of DiagnoseUseOfDecl for verification-only mode.

These two functions handle unavailable issues differently:
In Sema::CanUseDecl, we say the decl is invalid when the Decl is unavailable and
the current context is available.

In Sema::DiagnoseUseOfDecl, we say the decl is usable by ignoring the return
code of DiagnoseAvailabilityOfDecl

So with an assert build, we will hit an assertion in diagnoseListInit
assert(DiagnoseInitList.HadError() &&
       "Inconsistent init list check result.");

The fix -------------------
If we follow what is implemented in CanUseDecl and treat Decls with
unavailable issues as invalid, the variable decl of “foo2” will be marked as
invalid. Since unavailable checking is processed in delayed diagnostics
(r197627), we will silently ignore the diagnostics when we find out that
the variable decl is invalid.

We add a flag "TreatUnavailableAsInvalid" for the verification-only mode.
For overload resolution, we want to say decls with unavailable issues are
invalid; but for everything else, we should say they are valid and
emit diagnostics. Depending on the value of the flag, CanUseDecl
can return different values for unavailable issues.

rdar://23557300
Differential Revision: http://reviews.llvm.org/D15314

llvm-svn: 263149
2016-03-10 18:53:19 +00:00
Steven Wu 92910f69a0 Fix false positives for for-loop-analysis warning
Summary:
For PseudoObjectExpr, the DeclMatcher need to search only all the semantics
but also need to search pass OpaqueValueExpr for all potential uses for the
Decl.

Reviewers: thakis, rtrieu, rjmccall, doug.gregor

Subscribers: xazax.hun, rjmccall, doug.gregor, cfe-commits

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

llvm-svn: 263087
2016-03-10 02:02:48 +00:00
Aaron Ballman e7964789da Implement support for [[nodiscard]] in C++1z that is based off existing support for warn_unused_result, and treat it as an extension pre-C++1z. This also means extending the existing warn_unused_result attribute so that it can be placed on an enum as well as a class.
llvm-svn: 262872
2016-03-07 22:44:55 +00:00
Bob Wilson f5c53b859b [Sema] More changes to fix Objective-C fallout from r249995.
This is a follow-up to PR26085. That was fixed in r257710 but the testcase
there was incomplete. There is a related issue where the overload resolution
for Objective-C incorrectly picks a method that is not valid without a
bridge cast. The call to Sema::CheckSingleAssignmentConstraints that was
added to SemaOverload.cpp's IsStandardConversion() function does not catch
that case and reports that the method is Compatible even when it is not.

The root cause here is that various Objective-C-related functions in Sema
do not consistently return a value to indicate whether there was an error.
This was fine in the past because they would report diagnostics when needed,
but r257710 changed them to suppress reporting diagnostics when checking
during overload resolution.

This patch adds a new ACR_error result to the ARCConversionResult enum and
updates Sema::CheckObjCARCConversion to return that value when there is an
error. Most of the calls to that function do not check the return value,
so adding this new result does not affect them. The one exception is in
SemaCast.cpp where it specifically checks for ACR_unbridged, so that is
also OK. The call in Sema::CheckSingleAssignmentConstraints can then check
for an ACR_okay result and identify assignments as Incompatible. To
preserve the existing behavior, it only changes the return value to
Incompatible when the new Diagnose argument (from r257710) is false.

Similarly, the CheckObjCBridgeRelatedConversions and
ConversionToObjCStringLiteralCheck need to identify when an assignment is
Incompatible. Those functions already return appropriate values but they
need some fixes related to the new Diagnose argument.

llvm-svn: 260787
2016-02-13 01:41:41 +00:00
Saleem Abdulrasool 02e19a1696 Sema: handle typo correction on ARC'ed ivar
The ivar ref would be transformed by the Typo Correction TreeTransform, but not
be owned, resulting in the source location being invalid.  This would eventually
lead to an assertion in findCapturingExpr.  Prevent this assertion from
triggering.

Resolves PR25113.

llvm-svn: 260017
2016-02-07 02:30:59 +00:00
Saleem Abdulrasool 407f36bde9 Sema: handle typo correction with ARC'ed objc properties
We would previously assert in findCapturingExpr when performing a typo
correction resulting in an assignment of an ObjC property with a strong lifetype
specifier due to the expression not being rooted in the file (invalid SLoc)
during the retain cycle check on the typo-corrected expression.  Handle the
expression type appropriately during the TreeTransform to ensure that we have a
source location associated with the expression.

Fixes PR26486.

llvm-svn: 260016
2016-02-07 02:30:55 +00:00
Manman Ren dfef4069e3 Class Property: warn for synthesize on a class property.
rdar://23891898

llvm-svn: 259226
2016-01-29 19:16:39 +00:00
Manman Ren 0fe61f8688 Class Property: parse @dynamic (class).
rdar://23891898

llvm-svn: 259224
2016-01-29 19:05:57 +00:00