diff options
| author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-01-31 21:34:11 +0000 | 
|---|---|---|
| committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-01-31 21:34:11 +0000 | 
| commit | dd88dbf9d2b342cf2ce7a9d093033adf95475d46 (patch) | |
| tree | 50f5cff069903a28a607af72beb2dde62bd3dac7 /clang/lib | |
| parent | 9a58919c8e24503f047068a8bf521d307c817f9d (diff) | |
| download | bcm5719-llvm-dd88dbf9d2b342cf2ce7a9d093033adf95475d46.tar.gz bcm5719-llvm-dd88dbf9d2b342cf2ce7a9d093033adf95475d46.zip | |
Add -Wcustom-atomic-properties which warns if an atomic-by-default property has custom getter or setter.
The rationale is that it is highly likely that the user's getter/setter isn't atomically implemented. Off by default.
Addresses rdar://8782645.
-Wcustom-atomic-properties and -Wimplicit-atomic-properties are under the -Watomic-properties group.
llvm-svn: 124609
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/Sema/SemaObjCProperty.cpp | 34 | 
1 files changed, 30 insertions, 4 deletions
| diff --git a/clang/lib/Sema/SemaObjCProperty.cpp b/clang/lib/Sema/SemaObjCProperty.cpp index 88ad4d7527c..2f5be478065 100644 --- a/clang/lib/Sema/SemaObjCProperty.cpp +++ b/clang/lib/Sema/SemaObjCProperty.cpp @@ -1081,7 +1081,32 @@ Sema::AtomicPropertySetterGetterRules (ObjCImplDecl* IMPDecl,         E = IDecl->prop_end();         I != E; ++I) {      ObjCPropertyDecl *Property = (*I); +    ObjCMethodDecl *GetterMethod = 0; +    ObjCMethodDecl *SetterMethod = 0; +    bool LookedUpGetterSetter = false; +      unsigned Attributes = Property->getPropertyAttributes(); +    unsigned AttributesAsWrittern = Property->getPropertyAttributesAsWritten(); + +    if (!(AttributesAsWrittern & ObjCPropertyDecl::OBJC_PR_atomic) && +        !(AttributesAsWrittern & ObjCPropertyDecl::OBJC_PR_nonatomic)) { +      GetterMethod = IMPDecl->getInstanceMethod(Property->getGetterName()); +      SetterMethod = IMPDecl->getInstanceMethod(Property->getSetterName()); +      LookedUpGetterSetter = true; +      if (GetterMethod) { +        Diag(GetterMethod->getLocation(), +             diag::warn_default_atomic_custom_getter_setter) +          << Property->getIdentifier(); +        Diag(Property->getLocation(), diag::note_property_declare); +      } +      if (SetterMethod) { +        Diag(SetterMethod->getLocation(), +             diag::warn_default_atomic_custom_getter_setter) +          << Property->getIdentifier(); +        Diag(Property->getLocation(), diag::note_property_declare); +      } +    } +      // We only care about readwrite atomic property.      if ((Attributes & ObjCPropertyDecl::OBJC_PR_nonatomic) ||          !(Attributes & ObjCPropertyDecl::OBJC_PR_readwrite)) @@ -1090,10 +1115,11 @@ Sema::AtomicPropertySetterGetterRules (ObjCImplDecl* IMPDecl,           = IMPDecl->FindPropertyImplDecl(Property->getIdentifier())) {        if (PIDecl->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic)          continue; -      ObjCMethodDecl *GetterMethod = -        IMPDecl->getInstanceMethod(Property->getGetterName()); -      ObjCMethodDecl *SetterMethod = -        IMPDecl->getInstanceMethod(Property->getSetterName()); +      if (!LookedUpGetterSetter) { +        GetterMethod = IMPDecl->getInstanceMethod(Property->getGetterName()); +        SetterMethod = IMPDecl->getInstanceMethod(Property->getSetterName()); +        LookedUpGetterSetter = true; +      }        if ((GetterMethod && !SetterMethod) || (!GetterMethod && SetterMethod)) {          SourceLocation MethodLoc =            (GetterMethod ? GetterMethod->getLocation() | 

