summaryrefslogtreecommitdiffstats
path: root/clang/test/SemaObjCXX
Commit message (Collapse)AuthorAgeFilesLines
...
* [Sema][ObjC] Check whether a variable has a definition, rather thanAkira Hatanaka2017-04-111-0/+16
| | | | | | | | | | | | | | | | checking its storage class, when determining whether casting a C pointer to an ObjC pointer is allowed. This change allows casting variables whose declarations are directly contained in a linkage specification to an ObjC pointer type. Those variables are treated as if they contain the extern specifier for the purpose of determining whether they are definitions or not. rdar://problem/29249853 Differential Revision: https://reviews.llvm.org/D31673 llvm-svn: 299992
* [ObjC++] Conversions from specialized to non-specialized Objective-C genericAlex Lorenz2017-04-061-0/+27
| | | | | | | | | | | | | | | | | | | object types should be preferred over conversions to other object pointers This change ensures that Clang will select the correct overload for the following code sample: void overload(Base *b); void overload(Derived *d); void test(Base<Base *> b) { overload(b); // Select overload(Base *), not overload(Derived *) } rdar://20124827 Differential Revision: https://reviews.llvm.org/D31597 llvm-svn: 299648
* [ARC][ObjC++] Use ObjC semantic rules for comparisons between a pointer andAlex Lorenz2017-03-301-0/+24
| | | | | | | | | | | | | | | | | | | | an ObjC object pointer When ARC is enabled in Objective-C++, comparisons between a pointer and Objective-C object pointer typically result in errors like this: "invalid operands to a binary expression". This error message can be quite confusing as it doesn't provide a solution to the problem, unlike the non-C++ diagnostic: "implicit conversion of Objective-C pointer type 'id' to C pointer type 'void *' requires a bridged cast" (it also provides fix-its). This commit forces comparisons between pointers and Objective-C object pointers in ARC to use the Objective-C semantic rules to ensure that a better diagnostic is reported. rdar://31103857 Differential Revision: https://reviews.llvm.org/D31177 llvm-svn: 299080
* [Objective-C] Miscellaneous -fobjc-weak FixesBrian Kelley2017-03-291-0/+28
| | | | | | | | | | | | | | Summary: After examining the remaining uses of LangOptions.ObjCAutoRefCount, found a some additional places to also check for ObjCWeak not covered by previous test cases. Added a test file to verify all the code paths that were changed. Reviewers: rsmith, doug.gregor, rjmccall Reviewed By: rjmccall Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D31007 llvm-svn: 299015
* [Objective-C] Fix "weak-unavailable" warning with -fobjc-weakBrian Kelley2017-03-291-0/+1
| | | | | | | | | | | | | | 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
* [Objective-C] Fix __weak type traits with -fobjc-weakBrian Kelley2017-03-291-0/+210
| | | | | | | | | | | | | | Summary: Similar to ARC, in ObjCWeak Objective-C object pointers qualified with a weak lifetime are not POD or trivial types. Update the type trait code to reflect this. Copy and adapt the arc-type-traits.mm test case to verify correctness. Reviewers: rsmith, doug.gregor, rjmccall Reviewed By: rjmccall Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D31004 llvm-svn: 299010
* Print nested name specifiers for typedefs and type aliasesAlex Lorenz2017-03-101-2/+2
| | | | | | | | | | | | Printing typedefs or type aliases using clang_getTypeSpelling() is missing the namespace they are defined in. This is in contrast to other types that always yield the full typename including namespaces. Patch by Michael Reiher! Differential Revision: https://reviews.llvm.org/D29944 llvm-svn: 297465
* [Sema] Add variable captured by a block to the enclosing lambda'sAkira Hatanaka2017-03-011-1/+12
| | | | | | | | | | | | | | | potential capture list. Fix Sema::getCurLambda() to return the innermost lambda scope when there is a block enclosed in the lambda. Previously, the method would return a nullptr in such cases, which would prevent a variable captured by the enclosed block to be added to the lambda scope's potential capture list. rdar://problem/28412462 Differential Revision: https://reviews.llvm.org/D25556 llvm-svn: 296584
* [Sema] Disallow returning a __block variable via a move.Akira Hatanaka2017-02-151-1/+15
| | | | | | | | | | | | | | | r274291 made changes to prefer calling a move constructor to calling a copy constructor when returning from a function. This caused programs to crash when a __block variable in the heap was moved out and used later. This commit fixes the bug by disallowing moving out of __block variables implicitly. rdar://problem/28181080 Differential Revision: https://reviews.llvm.org/D29908 llvm-svn: 295150
* [test] Make Lit tests C++11 Compatible - Objective-C++Charles Li2017-02-132-2/+2
| | | | | | | | Set 5 Objective-C++ tests to run at gnu++98 Differential Revision: https://reviews.llvm.org/D29739 llvm-svn: 294997
* [Sema][ObjC++] Typo correction should handle ivars and propertiesAlex Lorenz2017-02-031-0/+15
| | | | | | | | | | | | | | | | After r260016 and r260017 disabled typo correction for ivars and properties clang didn't report errors about unresolved identifier in the base of ivar and property ref expressions. This meant that clang invoked CodeGen on invalid AST which then caused a crash. This commit re-enables typo correction for ivars and properites, and fixes the PR25113 & PR26486 (that were originally fixed in r260017 and r260016) in a different manner by transforming the Objective-C ivar reference expression with 'IsFreeIvar' preserved. rdar://30310772 llvm-svn: 294008
* Add fix-it notes to the nullability consistency warning.Jordan Rose2016-12-1911-15/+120
| | | | | | | | | | | | | | | | | | | | | This is especially important for arrays, since no one knows the proper syntax for putting qualifiers in arrays. nullability.h:3:26: warning: array parameter is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) void arrayParameter(int x[]); ^ nullability.h:3:26: note: insert '_Nullable' if the array parameter may be null void arrayParameter(int x[]); ^ _Nullable nullability.h:3:26: note: insert '_Nonnull' if the array parameter should never be null void arrayParameter(int x[]); ^ _Nonnull rdar://problem/29524992 llvm-svn: 290132
* [ObjC++] Don't enter a C++ declarator scope when the current context isAlex Lorenz2016-12-071-0/+35
| | | | | | | | | | | | | | | an Objective-C declaration This commit ensures that Sema won't enter a C++ declarator scope when the current context is an Objective-C declaration. This prevents an assertion failure in EnterDeclaratorContext that's used to ensure that current context will be restored correctly after exiting the declarator context. rdar://20560175 Differential Revision: https://reviews.llvm.org/D26922 llvm-svn: 288893
* Don't require nullability on 'va_list'.Jordan Rose2016-11-101-0/+22
| | | | | | | | | | | There are many non-portable typedefs, but va_list is one that nobody ever thinks of as a pointer or an array. (When's the last time you saw someone check for a NULL va_list?) Make an exception for this one special type. Part of rdar://problem/25846421. llvm-svn: 286522
* Warn when 'assume_nonnull' infers nullability within an array.Jordan Rose2016-11-101-6/+6
| | | | | | | | | | | ...or within a reference. Both of these add an extra level of indirection that make us less certain that the pointer really was supposed to be non-nullable. However, changing the default behavior would be a breaking change, so we'll just make it a warning instead. Part of rdar://problem/25846421 llvm-svn: 286521
* Add -Wnullability-completeness-on-arrays.Jordan Rose2016-11-102-0/+99
| | | | | | | | | | | | | | | | This is an addition to (and sub-warning of) -Wnullability-completeness that warns when an array parameter is missing nullability. When the specific warning is switched off, the compiler falls back to only warning on pointer types written as pointer types. Note that use of nullability /within/ an array triggers the completeness checks regardless of whether or not the array-specific warning is enabled; the intent there is simply to determine whether a particular header is trying to be nullability-aware at all. Part of rdar://problem/25846421. llvm-svn: 286520
* Don't require nullability on template parameters in typedefs.Jordan Rose2016-11-021-0/+8
| | | | | | | | | | | | | | | | | | | Previously the following code would warn on the use of "T": template <typename T> struct X { typedef T *type; }; ...because nullability is /allowed/ on template parameters (because they could be pointers). (Actually putting nullability on this use of 'T' will of course break if the argument is a non-pointer type.) This fix doesn't handle the case where a template parameter is used /outside/ of a typedef. That seems trickier, especially in parameter position. llvm-svn: 285856
* DR583, DR1512: Implement a rewrite to C++'s 'composite pointer type' rules.Richard Smith2016-10-211-3/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | This has two significant effects: 1) Direct relational comparisons between null pointer constants (0 and nullopt) and pointers are now ill-formed. This was always the case for C, and it appears that C++ only ever permitted by accident. For instance, cases like nullptr < &a are now rejected. 2) Comparisons and conditional operators between differently-cv-qualified pointer types now work, and produce a composite type that both source pointer types can convert to (when possible). For instance, comparison between 'int **' and 'const int **' is now valid, and uses an intermediate type of 'const int *const *'. Clang previously supported #2 as an extension. We do not accept the cases in #1 as an extension. I've tested a fair amount of code to check that this doesn't break it, but if it turns out that someone is relying on this, we can easily add it back as an extension. This is a re-commit of r284800. llvm-svn: 284890
* Revert "DR583, DR1512: Implement a rewrite to C++'s 'composite pointer type' ↵Renato Golin2016-10-211-2/+3
| | | | | | | | rules." This reverts commit r284800, as it failed all ARM/AArch64 bots. llvm-svn: 284811
* DR583, DR1512: Implement a rewrite to C++'s 'composite pointer type' rules.Richard Smith2016-10-211-3/+2
| | | | | | | | | | | | | | | | | | | | | | | | This has two significant effects: 1) Direct relational comparisons between null pointer constants (0 and nullopt) and pointers are now ill-formed. This was always the case for C, and it appears that C++ only ever permitted by accident. For instance, cases like nullptr < &a are now rejected. 2) Comparisons and conditional operators between differently-cv-qualified pointer types now work, and produce a composite type that both source pointer types can convert to (when possible). For instance, comparison between 'int **' and 'const int **' is now valid, and uses an intermediate type of 'const int *const *'. Clang previously supported #2 as an extension. We do not accept the cases in #1 as an extension. I've tested a fair amount of code to check that this doesn't break it, but if it turns out that someone is relying on this, we can easily add it back as an extension. llvm-svn: 284800
* Sema: support __declspec(dll*) on ObjC interfacesSaleem Abdulrasool2016-07-152-0/+65
| | | | | | | | | | | 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
* Re-commit r273548, reverted in r273589, with a fix to not produceRichard Smith2016-06-231-6/+3
| | | | | | | | | | | | | | | | -Wfor-loop-analysis warnings for a for-loop with a condition variable. In such a case, the loop condition variable is modified on each iteration of the loop by definition. Original commit message: Rearrange condition handling so that semantic checks on a condition variable are performed before the other substatements of the construct are parsed, rather than deferring them until the end. This allows better error recovery from semantic errors in the condition, improves diagnostic order, and is a prerequisite for C++17 constexpr if. llvm-svn: 273600
* Revert r273548, "Rearrange condition handling so that semantic checks on a ↵Peter Collingbourne2016-06-231-3/+6
| | | | | | | | condition variable" as it caused a regression in -Wfor-loop-analysis. llvm-svn: 273589
* Rearrange condition handling so that semantic checks on a condition variableRichard Smith2016-06-231-6/+3
| | | | | | | | | are performed before the other substatements of the construct are parsed, rather than deferring them until the end. This allows better error recovery from semantic errors in the condition, improves diagnostic order, and is a prerequisite for C++17 constexpr if. llvm-svn: 273548
* Obj-C: Fix assert-on-invalid (PR27822)Hans Wennborg2016-06-031-0/+7
| | | | | | | Clang would assert when isObjCInstancetype() was called on a tok::annot_cxxscope token. llvm-svn: 271688
* [ObjC] Enter a new evaluation context before callingAkira Hatanaka2016-05-041-0/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | BuildBlockForLambdaConversion. Previously, clang would build an incorrect AST for the following code: id test() { return @{@"a": [](){}, @"b": [](){}}; } ReturnStmt 0x10d080448 `-ExprWithCleanups 0x10d080428 |-cleanup Block 0x10d0801f0 // points to the second BlockDecl ... -BlockDecl 0x10d07f150 // First block ... -BlockDecl 0x10d0801f0 // Second block ... `-ExprWithCleanups 0x10d0801d0 |-cleanup Block 0x10d07f150 // points to the first BlockDecl To fix the bug, this commit enters a new evaluation context to reset ExprNeedsCleanups before each block is parsed. rdar://problem/16879958 Differential Revision: http://reviews.llvm.org/D18815 llvm-svn: 268527
* [ObjCXX] Warn undeclared identifiers.Manman Ren2016-03-251-0/+23
| | | | | | | | | | | | | | | | | | | | Instantiation dependence were not being handled correctly for OpqaueValueExpr AST nodes. As a result, if an undeclared identifier was used in a CXXNewExpr that is assigned to a ObjC property, there would be no error during parsing, and there would be a crash during code gen. This patch makes sure that an error will be issued during parsing in this case. Before the fix, if CXXNewExpr has a typo, its InstantiationDependent will be set to true, but if it is wrapped in a OpaqueValueExpr, the OpaqueValueExpr will not be instantiation dependent, causing the TypoExpr not be to resolved. The fix propagates InstantiationDependent to OpaqueValueExpr from its SourceExpr. It also propagates the other instantiation bits. rdar://24975562 Differential Revision: http://reviews.llvm.org/D18461 llvm-svn: 264444
* Improve some infrastructure for extended parameter infos andJohn McCall2016-03-032-2/+10
| | | | | | | fix a bug with the instantiation of ns_consumed parameter attributes in ARC. llvm-svn: 262551
* Test template instantiation of ns_consumed and ns_returns_retained.John McCall2016-03-011-1/+125
| | | | llvm-svn: 262311
* [Sema] Remove assert in TreeTransform<Derived>::TransformObjCObjectType.Akira Hatanaka2016-02-251-0/+9
| | | | | | | | | | | | | The assert isn't correct since TypeLoc::ObjCObjectTypeLoc doesn't indicate whether the type is a dependent type. The function returns false for a type like "<SomeProtocol>" which is a synonym for "id<SomeProtocol>". rdar://problem/23838912 Differential Revision: http://reviews.llvm.org/D17355 llvm-svn: 261829
* [Sema] Fix bug in TypeLocBuilder::pushImplAkira Hatanaka2016-02-181-0/+12
| | | | | | | | | | | | | | The code in TypeLocBuilder::pushImpl wasn't correctly handling the case where an element that has an 8-byte alignment was being pushed. I plan to follow up with a patch to remove redundancies and simplify the function. rdar://problem/23838912 Differential Revision: http://reviews.llvm.org/D16843 llvm-svn: 261260
* ObjCXX: fix a crash during typo correction.Manman Ren2016-02-021-0/+27
| | | | | | | | | | | | | For ObjCXX, we can create a CastExpr with Kind being CK_UserDefinedConversion and SubExpr being BlockExpr. Specifically one can return BlockExpr from BuildCXXMemberCallExpr and the result can be used to build a CastExpr. Fix the assumption in CastExpr::getSubExprAsWritten that SubExpr can only be CXXMemberCallExpr. rdar://problem/24364077 llvm-svn: 259591
* Allow pseudo-destructor calls on forward-declared Objective-C class pointers.John McCall2015-12-141-0/+23
| | | | | | rdar://18522255 llvm-svn: 255531
* [Lit Test] Updated 20 Lit tests to be C++11 compatible.Charles Li2015-12-101-3/+16
| | | | | | | | This is the 5th Lit test patch. Expanded expected diagnostics to vary by C++ dialect. Expanded RUN line to: default, C++98/03 and C++11. llvm-svn: 255196
* Objective-C properties: fix bogus use of "isa<>" on a QualType.Douglas Gregor2015-12-081-0/+10
| | | | | | | | | The code used "isa" to check the type and then "getAs" to look through sugar; we need to look through the sugar when checking, too, otherwise any kind of sugar (nullability qualifiers in the example; or a typedef) will thwart this semantic check. Fixes rdar://problem/23804250. llvm-svn: 255066
* [Lit Test] Updated 26 Lit tests to be C++11 compatible.Charles Li2015-11-112-3/+14
| | | | | | | Expected diagnostics have been expanded to vary by C++ dialect. RUN line has also been expanded to: default, C++98/03 and C++11. llvm-svn: 252785
* Stop back-patching 'readonly' Objective-C properties with 'readwrite' ones.Douglas Gregor2015-11-031-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | A 'readonly' Objective-C property declared in the primary class can effectively be shadowed by a 'readwrite' property declared within an extension of that class, so long as the types and attributes of the two property declarations are compatible. Previously, this functionality was implemented by back-patching the original 'readonly' property to make it 'readwrite', destroying source information and causing some hideously redundant, incorrect code. Simplify the implementation to express how this should actually be modeled: as a separate property declaration in the extension that shadows (via the name lookup rules) the declaration in the primary class. While here, correct some broken Fix-Its, eliminate a pile of redundant code, clean up the ARC migrator's handling of properties declared in extensions, and fix debug info's naming of methods that come from categories. A wonderous side effect of doing this write is that it eliminates the "AddedObjCPropertyInClassExtension" method from the AST mutation listener, which in turn eliminates the last place where we rewrite entire declarations in a chained PCH file or a module file. This change (which fixes rdar://problem/18475765) will allow us to eliminate the rewritten-decls logic from the serialization library, and fixes a crash (rdar://problem/23247794) illustrated by the test/PCH/chain-categories.m example. llvm-svn: 251874
* Refine r251469 to give better (and more localizable) diagnosticsJohn McCall2015-10-281-2/+2
| | | | | | for all the reasons that ARC makes things implicitly unavailable. llvm-svn: 251496
* Add the ability to define "fake" arguments on attributes.John McCall2015-10-281-1/+1
| | | | | | | | | | | | | | Fake arguments are automatically handled for serialization, cloning, and other representational tasks, but aren't included in pretty-printing or parsing (should we eventually ever automate that). This is chiefly useful for attributes that can be written by the user, but which are also frequently synthesized by the compiler, and which we'd like to remember details of the synthesis for. As a simple example, use this to narrow the cases in which we were generating a specialized note for implicitly unavailable declarations. llvm-svn: 251469
* Be more conservative about diagnosing "incorrect" uses of __weak:John McCall2015-10-271-1/+1
| | | | | | | | | | | | allow them to be written in certain kinds of user declaration and diagnose on the use-site instead. Also, improve and fix some diagnostics relating to __weak and properties. rdar://23228631 llvm-svn: 251384
* Some minor ARC diagnostic improvements.John McCall2015-10-211-2/+2
| | | | llvm-svn: 250917
* Fix inference of _Nullable for weak Objective-C properties.Douglas Gregor2015-10-092-0/+15
| | | | | | | | | | | | | | | | | | | | The inference of _Nullable for weak Objective-C properties was broken in several ways: * It was back-patching the type information very late in the process of checking the attributes for an Objective-C property, which is just wrong. * It was using ad hoc checks to try to suppress the warning about missing nullability specifiers (-Wnullability-completeness), which didn't actual work in all cases (rdar://problem/22985457) * It was inferring _Nullable even outside of assumes-nonnull regions, which is wrong. Putting the inference of _Nullable for weak Objective-C properties in the same place as all of the other inference logic fixes all of these ills. llvm-svn: 249896
* Perform Objective-C lifetime adjustments before comparing deduced lambda ↵Douglas Gregor2015-10-011-0/+19
| | | | | | | | | | result types. Objective-C ARC lifetime qualifiers are dropped when canonicalizing function types. Perform the same adjustment before comparing the deduced result types of lambdas. Fixes rdar://problem/22344904. llvm-svn: 249065
* Forbid qualifiers on ObjC generic parameters and arguments, butJohn McCall2015-09-231-0/+119
| | | | | | | | | | | | | | silently ignore them on arguments when they're provided indirectly (.e.g behind a template argument or typedef). This is mostly just good language design --- specifying that a generic argument is __weak doesn't actually do anything --- but it also prevents assertions when trying to apply a different ownership qualifier. rdar://21612439 llvm-svn: 248436
* Don't crash when passing &@selector to a _Nonnull parameter. Fixes PR24774.Nico Weber2015-09-151-1/+6
| | | | | | | | | The root cause here is that ObjCSelectorExpr is an rvalue, yet it can have its address taken. That's kind of awkward, but fixing this is awkward in other ways, see https://llvm.org/bugs/show_bug.cgi?id=24774#c16 . For now, just fix the crash. llvm-svn: 247740
* Move sel-address.mm from test/CodeGenCXX to test/SemaObjCXX, it's not a ↵Nico Weber2015-09-101-0/+14
| | | | | | codegen test. llvm-svn: 247327
* Add a new frontend warning for referencing members from the handler of a ↵Aaron Ballman2015-09-011-5/+4
| | | | | | | | constructor or destructor function-try-block, which is UB in C++. This corresponds to the CERT secure coding rule ERR53-CPP. llvm-svn: 246548
* [Sema] Be consistent about diagnostic wording: always use "cannot".Davide Italiano2015-08-151-1/+1
| | | | | | Discussed with Richard Smith. llvm-svn: 245162
* Cleanup ObjCInterfaceDecl lookup for ObjC literalsAlex Denisov2015-07-241-1/+1
| | | | llvm-svn: 243092
* Add missing files for objc_boxable feature.Alex Denisov2015-07-231-0/+118
| | | | | | Original patch [r240761] is missing all new files because of committer's mistake. llvm-svn: 243018
OpenPOWER on IntegriCloud