r284265 - [Sema] Refactor context checking for availability diagnostics

2016-10-14 Thread Erik Pilkington via cfe-commits
Author: epilk
Date: Fri Oct 14 14:08:01 2016
New Revision: 284265

URL: http://llvm.org/viewvc/llvm-project?rev=284265&view=rev
Log:
[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

Modified:
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/SemaObjC/class-unavail-warning.m

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=284265&r1=284264&r2=284265&view=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Fri Oct 14 14:08:01 2016
@@ -9889,23 +9889,16 @@ public:
 return OriginalLexicalContext ? OriginalLexicalContext : CurContext;
   }
 
-  AvailabilityResult getCurContextAvailability() const;
-
-  /// \brief Get the verison that this context implies.
-  /// For instance, a method in an interface that is annotated with an
-  /// availability attribuite effectively has the availability of the 
interface.
-  VersionTuple getVersionForDecl(const Decl *Ctx) const;
-
   /// \brief The diagnostic we should emit for \c D, or \c AR_Available.
   ///
   /// \param D The declaration to check. Note that this may be altered to point
   /// to another declaration that \c D gets it's availability from. i.e., we
   /// walk the list of typedefs to find an availability attribute.
   ///
-  /// \param ContextVersion The version to compare availability against.
-  AvailabilityResult
-  ShouldDiagnoseAvailabilityOfDecl(NamedDecl *&D, VersionTuple ContextVersion,
-   std::string *Message);
+  /// \param Message If non-null, this will be populated with the message from
+  /// the availability attribute that is selected.
+  AvailabilityResult ShouldDiagnoseAvailabilityOfDecl(NamedDecl *&D,
+  std::string *Message);
 
   const DeclContext *getCurObjCLexicalContext() const {
 const DeclContext *DC = getCurLexicalContext();

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=284265&r1=284264&r2=284265&view=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Oct 14 14:08:01 2016
@@ -15615,29 +15615,3 @@ void Sema::ActOnPragmaWeakAlias(Identifi
 Decl *Sema::getObjCDeclContext() const {
   return (dyn_cast_or_null(CurContext));
 }
-
-AvailabilityResult Sema::getCurContextAvailability() const {
-  const Decl *D = cast_or_null(getCurObjCLexicalContext());
-  if (!D)
-return AR_Available;
-
-  // If we are within an Objective-C method, we should consult
-  // both the availability of the method as well as the
-  // enclosing class.  If the class is (say) deprecated,
-  // the entire method is considered deprecated from the
-  // purpose of checking if the current context is deprecated.
-  if (const ObjCMethodDecl *MD = dyn_cast(D)) {
-AvailabilityResult R = MD->getAvailability();
-if (R != AR_Available)
-  return R;
-D = MD->getClassInterface();
-  }
-  // If we are within an Objective-c @implementation, it
-  // gets the same availability context as the @interface.
-  else if (const ObjCImplementationDecl *ID =
-dyn_cast(D)) {
-D = ID->getClassInterface();
-  }
-  // Recover from user error.
-  return D ? D->getAvailability() : AR_Available;
-}

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=284265&r1=284264&r2=284265&view=diff
==
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Fri Oct 14 14:08:01 2016
@@ -6317,30 +6317,6 @@ static void handleDelayedForbiddenType(S
   diag.Triggered = true;
 }
 
-static bool isDeclDeprecated(Decl *D) {
-  do {
-if (D->isDeprecated())
-  return true;
-// A category implicitly has the availability of the interface.
-if (const ObjCCategoryDecl *CatD = dyn_cast(D))
-  if (const ObjCInterfaceDecl *Interface = CatD->getClassInterface())
-return Interface->isDeprecated();
-  } while ((D = cast_or_null(D->getDeclContext(;
-  return false;
-}
-
-static bool isDeclUnavailable(Decl *D) {
-  do {
-if (D->isUnavailable())
-  return true;
-// A category implicitly has the availability of the interface.
-if (const ObjCCategoryDecl *CatD = dyn_cast(D))
-  if (const ObjCInterfaceDecl *Interface = CatD->getClassInterface())
-return Interf

Re: r284265 - [Sema] Refactor context checking for availability diagnostics

2016-10-17 Thread Bob Wilson via cfe-commits
Hi Erik,

This change does not work with one of the headers from the AVFoundation 
framework in tvOS 10.0. We can try to get a fix into the tvOS SDK, but it will 
probably be a while before we could release an SDK with that change. In the 
meantime, this is kind of disruptive. Can you find a way to keep the previous 
behavior, at least until we have a chance to fix that header?

The header in question is 
System/Library/Frameworks/AVFoundation.framework/Headers/AVCaptureDevice.h in 
the AppleTVSimulator.sdk directory from Xcode 8.0. The problematic declaration 
is this one:

AVF_EXPORT const AVCaptureWhiteBalanceGains AVCaptureWhiteBalanceGainsCurrent 
NS_AVAILABLE_IOS(8_0);

The problem is that the type is declared like this:

typedef struct {
float redGain;
float greenGain;
float blueGain;
} AVCaptureWhiteBalanceGains NS_AVAILABLE_IOS(8_0) __TVOS_PROHIBITED;

The variable is missing the __TVOS_PROHIBITED attribute. You can reproduce this 
easily:

$ cat t.m
#import 
$ clang -c -arch x86_64 -mtvos-simulator-version-min=10.0 -isysroot 
/Applications/Xcode-8.0.app/Contents/Developer/Platforms/AppleTVSimulator.platform/Developer/SDKs/AppleTVSimulator.sdk
 t.m
/Applications/Xcode-8.0.app/Contents/Developer/Platforms/AppleTVSimulator.platform/Developer/SDKs/AppleTVSimulator.sdk/System/Library/Frameworks/AVFoundation.framework/Headers/AVCaptureDevice.h:1184:14:
 error: 
  'AVCaptureWhiteBalanceGains' is unavailable: not available on tvOS
extern const AVCaptureWhiteBalanceGains AVCaptureWhiteBalanceGainsCurren...
 ^
/Applications/Xcode-8.0.app/Contents/Developer/Platforms/AppleTVSimulator.platform/Developer/SDKs/AppleTVSimulator.sdk/System/Library/Frameworks/AVFoundation.framework/Headers/AVCaptureDevice.h:1081:3:
 note: 
  'AVCaptureWhiteBalanceGains' has been explicitly marked unavailable here
} AVCaptureWhiteBalanceGains __attribute__((availability(ios,introduced=...
  ^
1 error generated.

Maybe we can carve out an exception based on the fact that this is just an 
extern declaration of the variable — it’s not actually being used here. It is 
also defined within the @interface for an Objective-C class, in case that helps 
at all.

> On Oct 14, 2016, at 12:08 PM, Erik Pilkington via cfe-commits 
>  wrote:
> 
> Author: epilk
> Date: Fri Oct 14 14:08:01 2016
> New Revision: 284265
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=284265&view=rev
> Log:
> [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
> 
> Modified:
>cfe/trunk/include/clang/Sema/Sema.h
>cfe/trunk/lib/Sema/SemaDecl.cpp
>cfe/trunk/lib/Sema/SemaDeclAttr.cpp
>cfe/trunk/lib/Sema/SemaExpr.cpp
>cfe/trunk/test/SemaObjC/class-unavail-warning.m
> 
> Modified: cfe/trunk/include/clang/Sema/Sema.h
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=284265&r1=284264&r2=284265&view=diff
> ==
> --- cfe/trunk/include/clang/Sema/Sema.h (original)
> +++ cfe/trunk/include/clang/Sema/Sema.h Fri Oct 14 14:08:01 2016
> @@ -9889,23 +9889,16 @@ public:
> return OriginalLexicalContext ? OriginalLexicalContext : CurContext;
>   }
> 
> -  AvailabilityResult getCurContextAvailability() const;
> -
> -  /// \brief Get the verison that this context implies.
> -  /// For instance, a method in an interface that is annotated with an
> -  /// availability attribuite effectively has the availability of the 
> interface.
> -  VersionTuple getVersionForDecl(const Decl *Ctx) const;
> -
>   /// \brief The diagnostic we should emit for \c D, or \c AR_Available.
>   ///
>   /// \param D The declaration to check. Note that this may be altered to 
> point
>   /// to another declaration that \c D gets it's availability from. i.e., we
>   /// walk the list of typedefs to find an availability attribute.
>   ///
> -  /// \param ContextVersion The version to compare availability against.
> -  AvailabilityResult
> -  ShouldDiagnoseAvailabilityOfDecl(NamedDecl *&D, VersionTuple 
> ContextVersion,
> -   std::string *Message);
> +  /// \param Message If non-null, this will be populated with the message 
> from
> +  /// the availability attribute that is selected.
> +  AvailabilityResult ShouldDiagnoseAvailabilityOfDecl(NamedDecl *&D,
> +  std::string *Message);
> 
>   const DeclContext *getCurObjCLexicalContext() const {
> const DeclContext *DC = getCurLexicalContext();
> 
> Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=284265&r1=284264&r2=284265&view=diff
> ==
> --- cfe/trunk/lib/Sema/S

Re: r284265 - [Sema] Refactor context checking for availability diagnostics

2016-10-18 Thread Erik Pilkington via cfe-commits
Hi Bob,
I think the code in the header is fine here, so I reverted in r284486. Here’s a 
reduced version:

typedef int unavail_int __attribute__((availability(tvos, unavailable)));

__attribute__((availability(tvos, unavailable)))
@interface A
extern unavail_int foo;
@end

The problem is that ‘foo’ is actually at file context, not in the context of 
the interface, because we temporarily switched contexts to parse it. This means 
we can’t just look at DeclContexts in the DelayedDiagnostic case, which is what 
I was doing here. I’ll try to get a fix out for this soon!

Thanks for pointing this out!
Erik

> On Oct 18, 2016, at 1:37 AM, Bob Wilson  wrote:
> 
> Hi Erik,
> 
> This change does not work with one of the headers from the AVFoundation 
> framework in tvOS 10.0. We can try to get a fix into the tvOS SDK, but it 
> will probably be a while before we could release an SDK with that change. In 
> the meantime, this is kind of disruptive. Can you find a way to keep the 
> previous behavior, at least until we have a chance to fix that header?
> 
> The header in question is 
> System/Library/Frameworks/AVFoundation.framework/Headers/AVCaptureDevice.h in 
> the AppleTVSimulator.sdk directory from Xcode 8.0. The problematic 
> declaration is this one:
> 
> AVF_EXPORT const AVCaptureWhiteBalanceGains AVCaptureWhiteBalanceGainsCurrent 
> NS_AVAILABLE_IOS(8_0);
> 
> The problem is that the type is declared like this:
> 
> typedef struct {
>float redGain;
>float greenGain;
>float blueGain;
> } AVCaptureWhiteBalanceGains NS_AVAILABLE_IOS(8_0) __TVOS_PROHIBITED;
> 
> The variable is missing the __TVOS_PROHIBITED attribute. You can reproduce 
> this easily:
> 
> $ cat t.m
> #import 
> $ clang -c -arch x86_64 -mtvos-simulator-version-min=10.0 -isysroot 
> /Applications/Xcode-8.0.app/Contents/Developer/Platforms/AppleTVSimulator.platform/Developer/SDKs/AppleTVSimulator.sdk
>  t.m
> /Applications/Xcode-8.0.app/Contents/Developer/Platforms/AppleTVSimulator.platform/Developer/SDKs/AppleTVSimulator.sdk/System/Library/Frameworks/AVFoundation.framework/Headers/AVCaptureDevice.h:1184:14:
>  error: 
>  'AVCaptureWhiteBalanceGains' is unavailable: not available on tvOS
> extern const AVCaptureWhiteBalanceGains AVCaptureWhiteBalanceGainsCurren...
> ^
> /Applications/Xcode-8.0.app/Contents/Developer/Platforms/AppleTVSimulator.platform/Developer/SDKs/AppleTVSimulator.sdk/System/Library/Frameworks/AVFoundation.framework/Headers/AVCaptureDevice.h:1081:3:
>  note: 
>  'AVCaptureWhiteBalanceGains' has been explicitly marked unavailable here
> } AVCaptureWhiteBalanceGains __attribute__((availability(ios,introduced=...
>  ^
> 1 error generated.
> 
> Maybe we can carve out an exception based on the fact that this is just an 
> extern declaration of the variable — it’s not actually being used here. It is 
> also defined within the @interface for an Objective-C class, in case that 
> helps at all.
> 
>> On Oct 14, 2016, at 12:08 PM, Erik Pilkington via cfe-commits 
>>  wrote:
>> 
>> Author: epilk
>> Date: Fri Oct 14 14:08:01 2016
>> New Revision: 284265
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=284265&view=rev
>> Log:
>> [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
>> 
>> Modified:
>>   cfe/trunk/include/clang/Sema/Sema.h
>>   cfe/trunk/lib/Sema/SemaDecl.cpp
>>   cfe/trunk/lib/Sema/SemaDeclAttr.cpp
>>   cfe/trunk/lib/Sema/SemaExpr.cpp
>>   cfe/trunk/test/SemaObjC/class-unavail-warning.m
>> 
>> Modified: cfe/trunk/include/clang/Sema/Sema.h
>> URL: 
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=284265&r1=284264&r2=284265&view=diff
>> ==
>> --- cfe/trunk/include/clang/Sema/Sema.h (original)
>> +++ cfe/trunk/include/clang/Sema/Sema.h Fri Oct 14 14:08:01 2016
>> @@ -9889,23 +9889,16 @@ public:
>>return OriginalLexicalContext ? OriginalLexicalContext : CurContext;
>>  }
>> 
>> -  AvailabilityResult getCurContextAvailability() const;
>> -
>> -  /// \brief Get the verison that this context implies.
>> -  /// For instance, a method in an interface that is annotated with an
>> -  /// availability attribuite effectively has the availability of the 
>> interface.
>> -  VersionTuple getVersionForDecl(const Decl *Ctx) const;
>> -
>>  /// \brief The diagnostic we should emit for \c D, or \c AR_Available.
>>  ///
>>  /// \param D The declaration to check. Note that this may be altered to 
>> point
>>  /// to another declaration that \c D gets it's availability from. i.e., we
>>  /// walk the list of typedefs to find an availability attribute.
>>  ///
>> -  /// \param ContextVersion The version to compare availability against.
>> -  AvailabilityResult
>> -  ShouldDiagnoseAvailabilityOf

Re: r284265 - [Sema] Refactor context checking for availability diagnostics

2016-10-18 Thread Erik Pilkington via cfe-commits

On second thought, I think the header *is* ill-formed here. If we allowed this 
behaviour, this would provide a way to circumvent an availability diagnostic. 
For example, now the following compiles cleanly, where we really should emit a 
diagnostic somewhere!

typedef int unavail_int __attribute__((availability(tvos, unavailable)));

__attribute__((availability(tvos, unavailable)))
@interface A
extern unavail_int foo;
@end

int main() { (void)foo; }

I’m not so sure about the politics of this, but could you file a radar or 
something to get the header fixed (i.e, make the variable __TVOS_PROHIBITED)? 
I’ll make a new patch that makes this a special case for now.

Sorry for the flip-flop!
Erik

> On Oct 18, 2016, at 11:47 AM, Erik Pilkington  
> wrote:
> 
> Hi Bob,
> I think the code in the header is fine here, so I reverted in r284486. Here’s 
> a reduced version:
> 
> typedef int unavail_int __attribute__((availability(tvos, unavailable)));
> 
> __attribute__((availability(tvos, unavailable)))
> @interface A
> extern unavail_int foo;
> @end
> 
> The problem is that ‘foo’ is actually at file context, not in the context of 
> the interface, because we temporarily switched contexts to parse it. This 
> means we can’t just look at DeclContexts in the DelayedDiagnostic case, which 
> is what I was doing here. I’ll try to get a fix out for this soon!
> 
> Thanks for pointing this out!
> Erik
> 
>> On Oct 18, 2016, at 1:37 AM, Bob Wilson > > wrote:
>> 
>> Hi Erik,
>> 
>> This change does not work with one of the headers from the AVFoundation 
>> framework in tvOS 10.0. We can try to get a fix into the tvOS SDK, but it 
>> will probably be a while before we could release an SDK with that change. In 
>> the meantime, this is kind of disruptive. Can you find a way to keep the 
>> previous behavior, at least until we have a chance to fix that header?
>> 
>> The header in question is 
>> System/Library/Frameworks/AVFoundation.framework/Headers/AVCaptureDevice.h 
>> in the AppleTVSimulator.sdk directory from Xcode 8.0. The problematic 
>> declaration is this one:
>> 
>> AVF_EXPORT const AVCaptureWhiteBalanceGains 
>> AVCaptureWhiteBalanceGainsCurrent NS_AVAILABLE_IOS(8_0);
>> 
>> The problem is that the type is declared like this:
>> 
>> typedef struct {
>>float redGain;
>>float greenGain;
>>float blueGain;
>> } AVCaptureWhiteBalanceGains NS_AVAILABLE_IOS(8_0) __TVOS_PROHIBITED;
>> 
>> The variable is missing the __TVOS_PROHIBITED attribute. You can reproduce 
>> this easily:
>> 
>> $ cat t.m
>> #import 
>> $ clang -c -arch x86_64 -mtvos-simulator-version-min=10.0 -isysroot 
>> /Applications/Xcode-8.0.app/Contents/Developer/Platforms/AppleTVSimulator.platform/Developer/SDKs/AppleTVSimulator.sdk
>>  t.m
>> /Applications/Xcode-8.0.app/Contents/Developer/Platforms/AppleTVSimulator.platform/Developer/SDKs/AppleTVSimulator.sdk/System/Library/Frameworks/AVFoundation.framework/Headers/AVCaptureDevice.h:1184:14:
>>  error: 
>>  'AVCaptureWhiteBalanceGains' is unavailable: not available on tvOS
>> extern const AVCaptureWhiteBalanceGains AVCaptureWhiteBalanceGainsCurren...
>> ^
>> /Applications/Xcode-8.0.app/Contents/Developer/Platforms/AppleTVSimulator.platform/Developer/SDKs/AppleTVSimulator.sdk/System/Library/Frameworks/AVFoundation.framework/Headers/AVCaptureDevice.h:1081:3:
>>  note: 
>>  'AVCaptureWhiteBalanceGains' has been explicitly marked unavailable here
>> } AVCaptureWhiteBalanceGains __attribute__((availability(ios,introduced=...
>>  ^
>> 1 error generated.
>> 
>> Maybe we can carve out an exception based on the fact that this is just an 
>> extern declaration of the variable — it’s not actually being used here. It 
>> is also defined within the @interface for an Objective-C class, in case that 
>> helps at all.
>> 
>>> On Oct 14, 2016, at 12:08 PM, Erik Pilkington via cfe-commits 
>>> mailto:cfe-commits@lists.llvm.org>> wrote:
>>> 
>>> Author: epilk
>>> Date: Fri Oct 14 14:08:01 2016
>>> New Revision: 284265
>>> 
>>> URL: http://llvm.org/viewvc/llvm-project?rev=284265&view=rev 
>>> 
>>> Log:
>>> [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 
>>> 
>>> 
>>> Modified:
>>>   cfe/trunk/include/clang/Sema/Sema.h
>>>   cfe/trunk/lib/Sema/SemaDecl.cpp
>>>   cfe/trunk/lib/Sema/SemaDeclAttr.cpp
>>>   cfe/trunk/lib/Sema/SemaExpr.cpp
>>>   cfe/trunk/test/SemaObjC/class-unavail-warning.m
>>> 
>>> Modified: cfe/trunk/include/clang/Sema/Sema.h
>>> URL: 
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=284265&r1=284264&r2=284265&view=diff
>>>  
>>> 

Re: r284265 - [Sema] Refactor context checking for availability diagnostics

2016-10-18 Thread Bob Wilson via cfe-commits
Yes. I filed rdar://problem/28812809  to report that 
problem in the SDK. I also filed rdar://problem/28825862 
 to remind us to restore the more strict checking 
after we release a version of the tvOS SDK with a fix.

Thanks, Erik!

> On Oct 18, 2016, at 9:46 AM, Erik Pilkington  
> wrote:
> 
> 
> On second thought, I think the header *is* ill-formed here. If we allowed 
> this behaviour, this would provide a way to circumvent an availability 
> diagnostic. For example, now the following compiles cleanly, where we really 
> should emit a diagnostic somewhere!
> 
> typedef int unavail_int __attribute__((availability(tvos, unavailable)));
> 
> __attribute__((availability(tvos, unavailable)))
> @interface A
> extern unavail_int foo;
> @end
> 
> int main() { (void)foo; }
> 
> I’m not so sure about the politics of this, but could you file a radar or 
> something to get the header fixed (i.e, make the variable __TVOS_PROHIBITED)? 
> I’ll make a new patch that makes this a special case for now.
> 
> Sorry for the flip-flop!
> Erik
> 
>> On Oct 18, 2016, at 11:47 AM, Erik Pilkington > > wrote:
>> 
>> Hi Bob,
>> I think the code in the header is fine here, so I reverted in r284486. 
>> Here’s a reduced version:
>> 
>> typedef int unavail_int __attribute__((availability(tvos, unavailable)));
>> 
>> __attribute__((availability(tvos, unavailable)))
>> @interface A
>> extern unavail_int foo;
>> @end
>> 
>> The problem is that ‘foo’ is actually at file context, not in the context of 
>> the interface, because we temporarily switched contexts to parse it. This 
>> means we can’t just look at DeclContexts in the DelayedDiagnostic case, 
>> which is what I was doing here. I’ll try to get a fix out for this soon!
>> 
>> Thanks for pointing this out!
>> Erik
>> 
>>> On Oct 18, 2016, at 1:37 AM, Bob Wilson >> > wrote:
>>> 
>>> Hi Erik,
>>> 
>>> This change does not work with one of the headers from the AVFoundation 
>>> framework in tvOS 10.0. We can try to get a fix into the tvOS SDK, but it 
>>> will probably be a while before we could release an SDK with that change. 
>>> In the meantime, this is kind of disruptive. Can you find a way to keep the 
>>> previous behavior, at least until we have a chance to fix that header?
>>> 
>>> The header in question is 
>>> System/Library/Frameworks/AVFoundation.framework/Headers/AVCaptureDevice.h 
>>> in the AppleTVSimulator.sdk directory from Xcode 8.0. The problematic 
>>> declaration is this one:
>>> 
>>> AVF_EXPORT const AVCaptureWhiteBalanceGains 
>>> AVCaptureWhiteBalanceGainsCurrent NS_AVAILABLE_IOS(8_0);
>>> 
>>> The problem is that the type is declared like this:
>>> 
>>> typedef struct {
>>>float redGain;
>>>float greenGain;
>>>float blueGain;
>>> } AVCaptureWhiteBalanceGains NS_AVAILABLE_IOS(8_0) __TVOS_PROHIBITED;
>>> 
>>> The variable is missing the __TVOS_PROHIBITED attribute. You can reproduce 
>>> this easily:
>>> 
>>> $ cat t.m
>>> #import 
>>> $ clang -c -arch x86_64 -mtvos-simulator-version-min=10.0 -isysroot 
>>> /Applications/Xcode-8.0.app/Contents/Developer/Platforms/AppleTVSimulator.platform/Developer/SDKs/AppleTVSimulator.sdk
>>>  t.m
>>> /Applications/Xcode-8.0.app/Contents/Developer/Platforms/AppleTVSimulator.platform/Developer/SDKs/AppleTVSimulator.sdk/System/Library/Frameworks/AVFoundation.framework/Headers/AVCaptureDevice.h:1184:14:
>>>  error: 
>>>  'AVCaptureWhiteBalanceGains' is unavailable: not available on tvOS
>>> extern const AVCaptureWhiteBalanceGains AVCaptureWhiteBalanceGainsCurren...
>>> ^
>>> /Applications/Xcode-8.0.app/Contents/Developer/Platforms/AppleTVSimulator.platform/Developer/SDKs/AppleTVSimulator.sdk/System/Library/Frameworks/AVFoundation.framework/Headers/AVCaptureDevice.h:1081:3:
>>>  note: 
>>>  'AVCaptureWhiteBalanceGains' has been explicitly marked unavailable 
>>> here
>>> } AVCaptureWhiteBalanceGains __attribute__((availability(ios,introduced=...
>>>  ^
>>> 1 error generated.
>>> 
>>> Maybe we can carve out an exception based on the fact that this is just an 
>>> extern declaration of the variable — it’s not actually being used here. It 
>>> is also defined within the @interface for an Objective-C class, in case 
>>> that helps at all.
>>> 
 On Oct 14, 2016, at 12:08 PM, Erik Pilkington via cfe-commits 
 mailto:cfe-commits@lists.llvm.org>> wrote:
 
 Author: epilk
 Date: Fri Oct 14 14:08:01 2016
 New Revision: 284265
 
 URL: http://llvm.org/viewvc/llvm-project?rev=284265&view=rev 
 
 Log:
 [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 
 
 
 Modified:
   cfe/trun

r284486 - Revert r284265 "[Sema] Refactor context checking for availability diagnostics"

2016-10-18 Thread Erik Pilkington via cfe-commits
Author: epilk
Date: Tue Oct 18 10:26:43 2016
New Revision: 284486

URL: http://llvm.org/viewvc/llvm-project?rev=284486&view=rev
Log:
Revert r284265 "[Sema] Refactor context checking for availability diagnostics"

This has a bug in it, pointed out by Bob Wilson!

Modified:
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/SemaObjC/class-unavail-warning.m

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=284486&r1=284485&r2=284486&view=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Tue Oct 18 10:26:43 2016
@@ -9890,16 +9890,23 @@ public:
 return OriginalLexicalContext ? OriginalLexicalContext : CurContext;
   }
 
+  AvailabilityResult getCurContextAvailability() const;
+
+  /// \brief Get the verison that this context implies.
+  /// For instance, a method in an interface that is annotated with an
+  /// availability attribuite effectively has the availability of the 
interface.
+  VersionTuple getVersionForDecl(const Decl *Ctx) const;
+
   /// \brief The diagnostic we should emit for \c D, or \c AR_Available.
   ///
   /// \param D The declaration to check. Note that this may be altered to point
   /// to another declaration that \c D gets it's availability from. i.e., we
   /// walk the list of typedefs to find an availability attribute.
   ///
-  /// \param Message If non-null, this will be populated with the message from
-  /// the availability attribute that is selected.
-  AvailabilityResult ShouldDiagnoseAvailabilityOfDecl(NamedDecl *&D,
-  std::string *Message);
+  /// \param ContextVersion The version to compare availability against.
+  AvailabilityResult
+  ShouldDiagnoseAvailabilityOfDecl(NamedDecl *&D, VersionTuple ContextVersion,
+   std::string *Message);
 
   const DeclContext *getCurObjCLexicalContext() const {
 const DeclContext *DC = getCurLexicalContext();

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=284486&r1=284485&r2=284486&view=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Oct 18 10:26:43 2016
@@ -15628,3 +15628,29 @@ void Sema::ActOnPragmaWeakAlias(Identifi
 Decl *Sema::getObjCDeclContext() const {
   return (dyn_cast_or_null(CurContext));
 }
+
+AvailabilityResult Sema::getCurContextAvailability() const {
+  const Decl *D = cast_or_null(getCurObjCLexicalContext());
+  if (!D)
+return AR_Available;
+
+  // If we are within an Objective-C method, we should consult
+  // both the availability of the method as well as the
+  // enclosing class.  If the class is (say) deprecated,
+  // the entire method is considered deprecated from the
+  // purpose of checking if the current context is deprecated.
+  if (const ObjCMethodDecl *MD = dyn_cast(D)) {
+AvailabilityResult R = MD->getAvailability();
+if (R != AR_Available)
+  return R;
+D = MD->getClassInterface();
+  }
+  // If we are within an Objective-c @implementation, it
+  // gets the same availability context as the @interface.
+  else if (const ObjCImplementationDecl *ID =
+dyn_cast(D)) {
+D = ID->getClassInterface();
+  }
+  // Recover from user error.
+  return D ? D->getAvailability() : AR_Available;
+}

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=284486&r1=284485&r2=284486&view=diff
==
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Tue Oct 18 10:26:43 2016
@@ -6327,6 +6327,30 @@ static void handleDelayedForbiddenType(S
   diag.Triggered = true;
 }
 
+static bool isDeclDeprecated(Decl *D) {
+  do {
+if (D->isDeprecated())
+  return true;
+// A category implicitly has the availability of the interface.
+if (const ObjCCategoryDecl *CatD = dyn_cast(D))
+  if (const ObjCInterfaceDecl *Interface = CatD->getClassInterface())
+return Interface->isDeprecated();
+  } while ((D = cast_or_null(D->getDeclContext(;
+  return false;
+}
+
+static bool isDeclUnavailable(Decl *D) {
+  do {
+if (D->isUnavailable())
+  return true;
+// A category implicitly has the availability of the interface.
+if (const ObjCCategoryDecl *CatD = dyn_cast(D))
+  if (const ObjCInterfaceDecl *Interface = CatD->getClassInterface())
+return Interface->isUnavaila

r285098 - Reapply r284265: "[Sema] Refactor context checking for availability diagnostics"

2016-10-25 Thread Erik Pilkington via cfe-commits
Author: epilk
Date: Tue Oct 25 14:05:50 2016
New Revision: 285098

URL: http://llvm.org/viewvc/llvm-project?rev=285098&view=rev
Log:
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.

Modified:
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/SemaObjC/class-unavail-warning.m

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=285098&r1=285097&r2=285098&view=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Tue Oct 25 14:05:50 2016
@@ -9909,23 +9909,16 @@ public:
 return OriginalLexicalContext ? OriginalLexicalContext : CurContext;
   }
 
-  AvailabilityResult getCurContextAvailability() const;
-
-  /// \brief Get the verison that this context implies.
-  /// For instance, a method in an interface that is annotated with an
-  /// availability attribuite effectively has the availability of the 
interface.
-  VersionTuple getVersionForDecl(const Decl *Ctx) const;
-
   /// \brief The diagnostic we should emit for \c D, or \c AR_Available.
   ///
   /// \param D The declaration to check. Note that this may be altered to point
   /// to another declaration that \c D gets it's availability from. i.e., we
   /// walk the list of typedefs to find an availability attribute.
   ///
-  /// \param ContextVersion The version to compare availability against.
-  AvailabilityResult
-  ShouldDiagnoseAvailabilityOfDecl(NamedDecl *&D, VersionTuple ContextVersion,
-   std::string *Message);
+  /// \param Message If non-null, this will be populated with the message from
+  /// the availability attribute that is selected.
+  AvailabilityResult ShouldDiagnoseAvailabilityOfDecl(NamedDecl *&D,
+  std::string *Message);
 
   const DeclContext *getCurObjCLexicalContext() const {
 const DeclContext *DC = getCurLexicalContext();

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=285098&r1=285097&r2=285098&view=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Oct 25 14:05:50 2016
@@ -15627,29 +15627,3 @@ void Sema::ActOnPragmaWeakAlias(Identifi
 Decl *Sema::getObjCDeclContext() const {
   return (dyn_cast_or_null(CurContext));
 }
-
-AvailabilityResult Sema::getCurContextAvailability() const {
-  const Decl *D = cast_or_null(getCurObjCLexicalContext());
-  if (!D)
-return AR_Available;
-
-  // If we are within an Objective-C method, we should consult
-  // both the availability of the method as well as the
-  // enclosing class.  If the class is (say) deprecated,
-  // the entire method is considered deprecated from the
-  // purpose of checking if the current context is deprecated.
-  if (const ObjCMethodDecl *MD = dyn_cast(D)) {
-AvailabilityResult R = MD->getAvailability();
-if (R != AR_Available)
-  return R;
-D = MD->getClassInterface();
-  }
-  // If we are within an Objective-c @implementation, it
-  // gets the same availability context as the @interface.
-  else if (const ObjCImplementationDecl *ID =
-dyn_cast(D)) {
-D = ID->getClassInterface();
-  }
-  // Recover from user error.
-  return D ? D->getAvailability() : AR_Available;
-}

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=285098&r1=285097&r2=285098&view=diff
==
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Tue Oct 25 14:05:50 2016
@@ -6328,30 +6328,6 @@ static void handleDelayedForbiddenType(S
   diag.Triggered = true;
 }
 
-static bool isDeclDeprecated(Decl *D) {
-  do {
-if (D->isDeprecated())
-  return true;
-// A category implicitly has the availability of the interface.
-if (const ObjCCategoryDecl *CatD = dyn_cast(D))
-  if (const ObjCInterfaceDecl *Interface = CatD->getClassInterface())
-return Interface->isDeprecated();
-  } while ((D = cast_or_null(D->getDeclContext(;
-  return false;
-}
-
-static bool isDeclUnavailable(Decl *D) {
-  do {
-if (D->isUnavailable())
-  return true;
-// A category implicitly has the availability of the interface.
-if (const ObjCCategoryDecl *CatD = dyn_cast