llvm-project/clang/lib/Sema
Alex Lorenz 50b2dd336e [ObjC] Pick a 'readwrite' property when synthesizing ambiguous
property and check for incompatible attributes

This commit changes the way ambiguous property synthesis (i.e. when synthesizing
a property that's declared in multiple protocols) is performed. Previously,
Clang synthesized the first property that was found. This lead to problems when
the property was synthesized in a class that conformed to two protocols that
declared that property and a second protocols had a 'readwrite' declaration -
the setter was not synthesized so the class didn't really conform to the second
protocol and user's code would crash at runtime when they would try to set the
property.

This commit ensures that a first readwrite property is selected. This is a
semantic change that changes users code in this manner:

```
@protocol P @property(readonly) int p; @end
@protocol P2 @property(readwrite) id p; @end
@interface I <P2> @end
@implementation I
@syntesize p; // Users previously got a warning here, and Clang synthesized
              // readonly 'int p' here. Now Clang synthesizes readwrite 'id' p..
@end
```

To ensure that this change is safe, the warning about incompatible types is
promoted to an error when this kind of readonly/readwrite ambiguity is detected
in the @implementation. This will ensure that previous code that had this subtle
bug and ignored the warning now will fail to compile with an error, and users
should not get suprises at runtime once they resolve the error.

The commit also extends the ambiguity checker, and now it can detect conflicts
among the different property attributes. An error diagnostic is used for
conflicting attributes, to ensure that the user won't get "suprises" at runtime.

ProtocolPropertyMap is removed in favour of a a set + vector because the map's
order of iteration is non-deterministic, so it couldn't be used to select the
readwrite property.

rdar://31579994

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

llvm-svn: 307903
2017-07-13 11:06:22 +00:00
..
AnalysisBasedWarnings.cpp Address comments that escaped D33333 2017-07-05 16:43:45 +00:00
AttributeList.cpp Add #pragma clang attribute 2017-04-18 14:33:39 +00:00
CMakeLists.txt Enabling the /bigobj flag for SemaDeclAttr.cpp. 2017-05-12 14:30:49 +00:00
CodeCompleteConsumer.cpp Retire llvm::alignOf in favor of C++11 alignof. 2016-10-20 14:27:22 +00:00
CoroutineStmtBuilder.h [coroutines] Fix rebuilding of dependent coroutine parameters 2017-06-03 00:22:18 +00:00
DeclSpec.cpp Recommit r289979 [OpenCL] Allow disabling types and declarations associated with extensions 2016-12-18 05:18:55 +00:00
DelayedDiagnostic.cpp [Sema] Don't allow -Wunguarded-availability to be silenced with redecls 2017-07-05 17:08:56 +00:00
IdentifierResolver.cpp [modules] Separately track whether an identifier's preprocessor information and 2016-02-05 19:03:40 +00:00
JumpDiagnostics.cpp [Sema][ObjC] Disallow jumping into ObjC fast enumeration loops. 2017-04-19 17:54:08 +00:00
MultiplexExternalSemaSource.cpp Modular Codegen: Support homing debug info for types in modular objects 2017-04-11 21:13:37 +00:00
Scope.cpp [Parser] Clear the TemplateParamScope bit of the current scope's flag 2016-04-29 02:24:14 +00:00
ScopeInfo.cpp [coroutines] Fix diagnostics depending on the first coroutine statement. 2017-03-11 02:35:37 +00:00
Sema.cpp [modules ts] Declarations from a module interface unit are only visible outside 2017-07-05 01:42:07 +00:00
SemaAccess.cpp P0136R1, DR1573, DR1645, DR1715, DR1736, DR1903, DR1941, DR1959, DR1991: 2016-06-28 19:03:57 +00:00
SemaAttr.cpp Add support for #pragma clang section 2017-06-05 10:11:57 +00:00
SemaCUDA.cpp Function with unparsed body is a definition 2017-06-21 12:46:57 +00:00
SemaCXXScopeSpec.cpp Add support for editor placeholders to Clang 2017-04-19 08:58:56 +00:00
SemaCast.cpp [clang] Implement -Wcast-qual for C++ 2017-07-03 17:59:22 +00:00
SemaChecking.cpp Fix crash parsing invalid code 2017-07-07 09:38:59 +00:00
SemaCodeComplete.cpp [Completion] Code complete the members for a dependent type after a '::' 2017-06-15 21:40:54 +00:00
SemaConsumer.cpp
SemaCoroutine.cpp Remove incorrect FIXME comment; the FIXME was addressed before the changes were committed 2017-07-10 02:59:26 +00:00
SemaDecl.cpp [modules ts] Declarations from a module interface unit are only visible outside 2017-07-05 01:42:07 +00:00
SemaDeclAttr.cpp [Sema] Don't allow -Wunguarded-availability to be silenced with redecls 2017-07-05 17:08:56 +00:00
SemaDeclCXX.cpp Recommit r306103: PR26195: Set correct NestedNameSpecifierLoc for the 2017-06-27 10:35:30 +00:00
SemaDeclObjC.cpp [ObjC] Avoid the -Wunguarded-availability warnings for protocol 2017-07-07 09:15:29 +00:00
SemaExceptionSpec.cpp [coroutines] Add DependentCoawaitExpr and fix re-building CoroutineBodyStmt. 2017-03-06 23:38:15 +00:00
SemaExpr.cpp [Sema] Mark a virtual CXXMethodDecl as used if a call to it can be 2017-07-13 06:08:27 +00:00
SemaExprCXX.cpp [Sema] Issue diagnostics if a new/delete expression generates a call to 2017-06-29 18:48:40 +00:00
SemaExprMember.cpp [OPENMP] Skip BuildMemberExpr() in BuildFieldReferenceExpr(), NFC, by Kai Noda 2017-07-11 19:43:28 +00:00
SemaExprObjC.cpp [Sema][ObjC] Clean up possible null dereference. 2017-05-09 01:54:51 +00:00
SemaFixItUtils.cpp Wire a SourceLocation into IsDerivedFrom and move the RequireCompleteType call 2015-12-18 21:45:41 +00:00
SemaInit.cpp Fix PR 10758: Infinite recursion when dealing with copy-initialization 2017-05-16 10:23:58 +00:00
SemaLambda.cpp fix trivial typos in comments; NFC 2017-07-05 05:37:45 +00:00
SemaLookup.cpp [modules ts] Improve merging of module-private declarations. 2017-07-05 07:47:11 +00:00
SemaObjCProperty.cpp [ObjC] Pick a 'readwrite' property when synthesizing ambiguous 2017-07-13 11:06:22 +00:00
SemaOpenMP.cpp [OPENMP] Add restriction for reduction clause in taskloop directives. 2017-07-11 19:16:44 +00:00
SemaOverload.cpp [Sema] Mark a virtual CXXMethodDecl as used if a call to it can be 2017-07-13 06:08:27 +00:00
SemaPseudoObject.cpp [ObjC] Check that a subscript methods is declared for a qualified id type 2017-07-11 10:18:35 +00:00
SemaStmt.cpp [Sema] Make BreakContinueFinder handle nested loops. 2017-07-04 00:52:24 +00:00
SemaStmtAsm.cpp Added LLVM_FALLTHROUGH to address warning: this statement may fall through. NFC. 2017-06-03 06:35:06 +00:00
SemaStmtAttr.cpp Add [[clang::suppress(rule, ...)]] attribute 2017-03-27 19:45:24 +00:00
SemaTemplate.cpp [MS] Don't statically initialize dllimport member function pointers 2017-07-07 22:04:29 +00:00
SemaTemplateDeduction.cpp [c++1z] Support deducing B in noexcept(B). 2017-06-07 21:46:22 +00:00
SemaTemplateInstantiate.cpp PR33552: Distinguish between declarations that are owned by no module and 2017-06-23 01:04:34 +00:00
SemaTemplateInstantiateDecl.cpp PR33552: Distinguish between declarations that are owned by no module and 2017-06-23 01:04:34 +00:00
SemaTemplateVariadic.cpp PR24440: Do not silently discard a fold-expression appearing as the operand of a cast-expression. 2017-02-15 19:57:10 +00:00
SemaType.cpp [Modules] Implement ODR-like semantics for tag types in C/ObjC 2017-07-01 00:06:47 +00:00
TreeTransform.h [coroutines] Fix rebuilding of dependent coroutine parameters 2017-06-03 00:22:18 +00:00
TypeLocBuilder.cpp [Sema] Fix bug in TypeLocBuilder::pushImpl 2016-02-18 21:05:09 +00:00
TypeLocBuilder.h Retire llvm::alignOf in favor of C++11 alignof. 2016-10-20 14:27:22 +00:00