Re: [PATCH] D23003: [ObjC Availability] Warn upon unguarded use of partially available declaration

2016-10-26 Thread Nico Weber via cfe-commits
If you're working on it, let's just wait for that :-)

On Wed, Oct 26, 2016 at 12:01 PM, Erik Pilkington  wrote:

> Hi Nico,
> All that is left for the diagnostic to make sense it CodeGen support for
> @available, which is something I’m working on now. I should have a patch up
> for it in a couple days. I suppose it was a mistake to mention upgrading to
> something that doesn’t work yet, if this is an inconvenience for you I
> would be happy to temporarily remove that note!
>
> Thanks for pinging, and sorry for any confusion that I caused,
> Erik
>
> > On Oct 26, 2016, at 11:44 AM, Nico Weber  wrote:
> >
> > thakis added a comment.
> >
> > Erik, are you planning on adding the later phases soon? At the moment,
> due to this patch, clang emits "enclose 'setAllowsAutomaticWindowTabbing:'
> in an @available check to silence this warning" but then errors out when
> trying to use @available. This is proving to be confusing to folks :-)
> >
> >
> > Repository:
> >  rL LLVM
> >
> > https://reviews.llvm.org/D23003
> >
> >
> >
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D23003: [ObjC Availability] Warn upon unguarded use of partially available declaration

2016-10-26 Thread Erik Pilkington via cfe-commits
Hi Nico,
All that is left for the diagnostic to make sense it CodeGen support for 
@available, which is something I’m working on now. I should have a patch up for 
it in a couple days. I suppose it was a mistake to mention upgrading to 
something that doesn’t work yet, if this is an inconvenience for you I would be 
happy to temporarily remove that note!

Thanks for pinging, and sorry for any confusion that I caused,
Erik

> On Oct 26, 2016, at 11:44 AM, Nico Weber  wrote:
> 
> thakis added a comment.
> 
> Erik, are you planning on adding the later phases soon? At the moment, due to 
> this patch, clang emits "enclose 'setAllowsAutomaticWindowTabbing:' in an 
> @available check to silence this warning" but then errors out when trying to 
> use @available. This is proving to be confusing to folks :-)
> 
> 
> Repository:
>  rL LLVM
> 
> https://reviews.llvm.org/D23003
> 
> 
> 

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D23003: [ObjC Availability] Warn upon unguarded use of partially available declaration

2016-10-26 Thread Nico Weber via cfe-commits
thakis added a comment.

Erik, are you planning on adding the later phases soon? At the moment, due to 
this patch, clang emits "enclose 'setAllowsAutomaticWindowTabbing:' in an 
@available check to silence this warning" but then errors out when trying to 
use @available. This is proving to be confusing to folks :-)


Repository:
  rL LLVM

https://reviews.llvm.org/D23003



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D23003: [ObjC Availability] Warn upon unguarded use of partially available declaration

2016-08-16 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL278826: [ObjC] Warn on unguarded use of partial declaration 
(authored by epilk).

Changed prior to commit:
  https://reviews.llvm.org/D23003?vs=67713=68218#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D23003

Files:
  cfe/trunk/include/clang/AST/Stmt.h
  cfe/trunk/include/clang/Basic/DiagnosticGroups.td
  cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
  cfe/trunk/include/clang/Sema/ScopeInfo.h
  cfe/trunk/include/clang/Sema/Sema.h
  cfe/trunk/lib/AST/Stmt.cpp
  cfe/trunk/lib/Sema/JumpDiagnostics.cpp
  cfe/trunk/lib/Sema/ScopeInfo.cpp
  cfe/trunk/lib/Sema/SemaDecl.cpp
  cfe/trunk/lib/Sema/SemaDeclAttr.cpp
  cfe/trunk/lib/Sema/SemaExpr.cpp
  cfe/trunk/lib/Sema/SemaStmt.cpp
  cfe/trunk/test/Parser/objc-available.m
  cfe/trunk/test/Sema/attr-availability.c
  cfe/trunk/test/SemaObjC/attr-availability.m
  cfe/trunk/test/SemaObjC/property-deprecated-warning.m
  cfe/trunk/test/SemaObjC/unguarded-availability.m

Index: cfe/trunk/test/Sema/attr-availability.c
===
--- cfe/trunk/test/Sema/attr-availability.c
+++ cfe/trunk/test/Sema/attr-availability.c
@@ -30,7 +30,7 @@
   ATSFontGetPostScriptName(100); // expected-error {{'ATSFontGetPostScriptName' is unavailable: obsoleted in macOS 9.0 - use ATSFontGetFullPostScriptName}}
 
 #if defined(WARN_PARTIAL)
-  // expected-warning@+2 {{is partial: introduced in macOS 10.8}} expected-note@+2 {{explicitly redeclare 'PartiallyAvailable' to silence this warning}}
+  // expected-warning@+2 {{is only available on macOS 10.8 or newer}} expected-note@+2 {{enclose 'PartiallyAvailable' in an @available check to silence this warning}}
 #endif
   PartiallyAvailable();
 }
Index: cfe/trunk/test/SemaObjC/property-deprecated-warning.m
===
--- cfe/trunk/test/SemaObjC/property-deprecated-warning.m
+++ cfe/trunk/test/SemaObjC/property-deprecated-warning.m
@@ -9,7 +9,7 @@
 @property(nonatomic,assign) id ptarget __attribute__((availability(ios,introduced=2.0,deprecated=3.0))); // expected-note {{property 'ptarget' is declared deprecated here}} expected-note {{'ptarget' has been explicitly marked deprecated here}}
 
 #if defined(WARN_PARTIAL)
-// expected-note@+2 {{property 'partialPtarget' is declared partial here}} expected-note@+2 {{'partialPtarget' has been explicitly marked partial here}}
+// expected-note@+2 {{'partialPtarget' has been explicitly marked partial here}}
 #endif
 @property(nonatomic,assign) id partialPtarget __attribute__((availability(ios,introduced=5.0)));
 @end
@@ -24,7 +24,7 @@
 @property(nonatomic,assign) id target __attribute__((availability(ios,introduced=2.0,deprecated=3.0))); // expected-note {{property 'target' is declared deprecated here}} expected-note {{'setTarget:' has been explicitly marked deprecated here}}
 
 #if defined(WARN_PARTIAL)
-// expected-note@+2 {{property 'partialTarget' is declared partial here}} expected-note@+2 {{'setPartialTarget:' has been explicitly marked partial here}}
+// expected-note@+2 {{'setPartialTarget:' has been explicitly marked partial here}}
 #endif
 @property(nonatomic,assign) id partialTarget __attribute__((availability(ios,introduced=5.0)));
 @end
@@ -40,7 +40,7 @@
 // expected-note 2 {{'setDep_target:' has been explicitly marked deprecated here}}
 
 #if defined(WARN_PARTIAL)
-// expected-note@+2 4 {{property 'partial_dep_target' is declared partial here}} expected-note@+2 2 {{'partial_dep_target' has been explicitly marked partial here}} expected-note@+2 2 {{'setPartial_dep_target:' has been explicitly marked partial here}}
+// expected-note@+2 2 {{'partial_dep_target' has been explicitly marked partial here}} expected-note@+2 2 {{'setPartial_dep_target:' has been explicitly marked partial here}}
 #endif
 @property(nonatomic,assign) id partial_dep_target  __attribute__((availability(ios,introduced=5.0)));
 @end
@@ -57,7 +57,7 @@
   [self setPtarget: (id)0]; // no-warning
   [self setPartialTarget: (id)0]; // no-warning
 #if defined(WARN_PARTIAL)
-  // expected-warning@+2 {{'partial_dep_target' is partial: introduced in iOS 5.0}} expected-warning@+2 {{'setPartial_dep_target:' is partial: introduced in iOS 5.0}} expected-note@+2 {{explicitly redeclare 'partial_dep_target' to silence this warning}} expected-note@+2 {{explicitly redeclare 'setPartial_dep_target:' to silence this warning}}
+  // expected-warning@+2 {{'partial_dep_target' is only available on iOS 5.0 or newer}} expected-warning@+2 {{'setPartial_dep_target:' is only available on iOS 5.0 or newer}} expected-note@+2 {{enclose 'partial_dep_target' in an @available check to silence this warning}} expected-note@+2 {{enclose 'setPartial_dep_target:' in an @available check to silence this warning}}
 #endif
   [self setPartial_dep_target: [self 

Re: [PATCH] D23003: [ObjC Availability] Warn upon unguarded use of partially available declaration

2016-08-15 Thread Manman Ren via cfe-commits
manmanren accepted this revision.
manmanren added a comment.
This revision is now accepted and ready to land.



> This is done so containers, such as `vector` can be used 
> safely provided `partially_available` is safe at the point of instantiation. 
> I think the way to improve this is in `Sema::getVersionForDecl()`. There we 
> could look at function and template parameters to determine the best base 
> version, then diagnose against it.


Let's fix the diagnostics for dependent type in a follow-up patch. And your 
suggestion above sounds reasonable to me.

Thanks for the work!
Manman


https://reviews.llvm.org/D23003



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D23003: [ObjC Availability] Warn upon unguarded use of partially available declaration

2016-08-11 Thread Erik Pilkington via cfe-commits
erik.pilkington updated this revision to Diff 67713.
erik.pilkington added a comment.

This new patch adds some testcases for templates, and simplifies some control 
flow in `TraverseIfStmt`. This patch also removes diagnostics for instantiated 
templates, instead just using the pattern. This means that a dependent type 
that was resolved during instantiation can refer to an unavailable declaration. 
For example, the following now compiles cleanly (when we want a diagnostic):

  void f(int);
  void f(char) __attribute__((availability(macos, introduced=10.12)));
  
  template  void use_f(T p) { f(p); }
  
  template void use_f();

This is done so containers, such as `vector` can be used 
safely provided `partially_available` is safe at the point of instantiation. I 
think the way to improve this is in `Sema::getVersionForDecl()`. There we could 
look at function and template parameters to determine the best base version, 
then diagnose against it.


https://reviews.llvm.org/D23003

Files:
  include/clang/AST/Stmt.h
  include/clang/Basic/DiagnosticGroups.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/ScopeInfo.h
  include/clang/Sema/Sema.h
  lib/AST/Stmt.cpp
  lib/Sema/JumpDiagnostics.cpp
  lib/Sema/ScopeInfo.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaDeclAttr.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaStmt.cpp
  test/Parser/objc-available.m
  test/Sema/attr-availability.c
  test/SemaObjC/attr-availability.m
  test/SemaObjC/property-deprecated-warning.m
  test/SemaObjC/unguarded-availability.m

Index: test/SemaObjC/unguarded-availability.m
===
--- test/SemaObjC/unguarded-availability.m
+++ test/SemaObjC/unguarded-availability.m
@@ -0,0 +1,180 @@
+// RUN: %clang_cc1 -triple x86_64-apple-macosx-10.9 -Wunguarded-availability -fblocks -fsyntax-only -verify %s
+// RUN: %clang_cc1 -xobjective-c++ -DOBJCPP -triple x86_64-apple-macosx-10.9 -Wunguarded-availability -fblocks -fsyntax-only -verify %s
+
+#define AVAILABLE_10_0  __attribute__((availability(macos, introduced = 10.0)))
+#define AVAILABLE_10_11 __attribute__((availability(macos, introduced = 10.11)))
+#define AVAILABLE_10_12 __attribute__((availability(macos, introduced = 10.12)))
+
+int func_10_11() AVAILABLE_10_11; // expected-note 4 {{'func_10_11' has been explicitly marked partial here}}
+
+#ifdef OBJCPP
+// expected-note@+2 {{marked partial here}}
+#endif
+int func_10_12() AVAILABLE_10_12; // expected-note 5 {{'func_10_12' has been explicitly marked partial here}}
+
+int func_10_0() AVAILABLE_10_0;
+
+void use_func() {
+  func_10_11(); // expected-warning{{'func_10_11' is only available on macOS 10.11 or newer}} expected-note{{enclose 'func_10_11' in an @available check to silence this warning}}
+
+  if (@available(macos 10.11, *))
+func_10_11();
+  else
+func_10_11(); // expected-warning{{'func_10_11' is only available on macOS 10.11 or newer}} expected-note{{enclose 'func_10_11' in an @available check to silence this warning}}
+}
+
+void defn_10_11() AVAILABLE_10_11;
+
+void defn_10_11() {
+  func_10_11();
+}
+
+void nested_ifs() {
+  if (@available(macos 10.12, *)) {
+if (@available(macos 10.10, *)) {
+  func_10_12();
+} else {
+  func_10_12();
+}
+  } else {
+func_10_12(); // expected-warning{{'func_10_12' is only available on macOS 10.12 or newer}} expected-note{{enclose 'func_10_12' in an @available check to silence this warning}}
+  }
+}
+
+void star_case() {
+  if (@available(ios 9, *)) {
+func_10_11(); // expected-warning{{'func_10_11' is only available on macOS 10.11 or newer}} expected-note{{enclose 'func_10_11' in an @available check to silence this warning}}
+func_10_0();
+  } else
+func_10_11(); // expected-warning{{'func_10_11' is only available on macOS 10.11 or newer}} expected-note{{enclose 'func_10_11' in an @available check to silence this warning}}
+
+  if (@available(macos 10.11, *)) {
+if (@available(ios 8, *)) {
+  func_10_11();
+  func_10_12(); // expected-warning{{'func_10_12' is only available on macOS 10.12 or newer}} expected-note{{enclose}}
+} else {
+  func_10_11();
+  func_10_12(); // expected-warning{{'func_10_12' is only available on macOS 10.12 or newer}} expected-note{{enclose}}
+}
+  }
+}
+
+typedef int int_10_11 AVAILABLE_10_11; // expected-note {{'int_10_11' has been explicitly marked partial here}}
+#ifdef OBJCPP
+// expected-note@+2 {{marked partial here}}
+#endif
+typedef int int_10_12 AVAILABLE_10_12; // expected-note 3 {{'int_10_12' has been explicitly marked partial here}}
+
+void use_typedef() {
+  int_10_11 x; // expected-warning{{'int_10_11' is only available on macOS 10.11 or newer}} expected-note{{enclose 'int_10_11' in an @available check to silence this warning}}
+}
+
+__attribute__((objc_root_class))
+AVAILABLE_10_11 @interface Class_10_11 {
+  int_10_11 foo;
+  int_10_12 bar; // expected-warning {{'int_10_12' is partial: introduced in macOS 

Re: [PATCH] D23003: [ObjC Availability] Warn upon unguarded use of partially available declaration

2016-08-10 Thread Manman Ren via cfe-commits
manmanren added a comment.

This looks pretty good. Can you add a few more testing cases for templates such 
as @available inside the template function, @available enclosing the template 
instantiation?

Cheers,
Manman



Comment at: lib/Sema/SemaDeclAttr.cpp:6634
@@ +6633,3 @@
+  // branches.
+  if (CondVersion <= AvailabilityStack.back())
+return Base::TraverseStmt(If->getThen()) &&

I wonder if it is better to combine this with the above if (!E->hasVersion()) 
i.e
if (!E->hasVersion() || E->getVersion() <= AvailabilityStack.back())


https://reviews.llvm.org/D23003



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D23003: [ObjC Availability] Warn upon unguarded use of partially available declaration

2016-08-10 Thread Erik Pilkington via cfe-commits
erik.pilkington updated this revision to Diff 67582.
erik.pilkington added a comment.

This new patch rebases on top of r277887, and addresses Manman's comments.

After looking through the AST nodes, I realized I neglected to emit a 
diagnostic for member expressions. I also noticed that function parameters are 
not being handled correctly. For example:

  int f(introduced_in_10_12_t x) __attribute__((availability(macos, 
introduced=10.12)));

Triggers `-Wunguarded-availability`, which is clearly incorrect. I think the 
fix here is just to delay the diagnostic until we know the context 
availability. This isn't really related to this patch, so I'll fix it in a 
follow up.

Outside of that I can't think of any cases of referencing a declaration in a 
function body that we're missing.

Thanks!


https://reviews.llvm.org/D23003

Files:
  include/clang/AST/Stmt.h
  include/clang/Basic/DiagnosticGroups.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/ScopeInfo.h
  include/clang/Sema/Sema.h
  lib/AST/Stmt.cpp
  lib/Sema/JumpDiagnostics.cpp
  lib/Sema/ScopeInfo.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaDeclAttr.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaStmt.cpp
  test/Parser/objc-available.m
  test/Sema/attr-availability.c
  test/SemaObjC/attr-availability.m
  test/SemaObjC/property-deprecated-warning.m
  test/SemaObjC/unguarded-availability.m

Index: test/SemaObjC/unguarded-availability.m
===
--- test/SemaObjC/unguarded-availability.m
+++ test/SemaObjC/unguarded-availability.m
@@ -0,0 +1,139 @@
+// RUN: %clang_cc1 -triple x86_64-apple-macosx-10.9 -Wunguarded-availability -fblocks -fsyntax-only -verify %s
+// RUN: %clang_cc1 -xobjective-c++ -DOBJCPP -triple x86_64-apple-macosx-10.9 -Wunguarded-availability -fblocks -fsyntax-only -verify %s
+
+#define AVAILABLE_10_0  __attribute__((availability(macos, introduced = 10.0)))
+#define AVAILABLE_10_11 __attribute__((availability(macos, introduced = 10.11)))
+#define AVAILABLE_10_12 __attribute__((availability(macos, introduced = 10.12)))
+
+int func_10_11() AVAILABLE_10_11; // expected-note 4 {{'func_10_11' has been explicitly marked partial here}}
+
+int func_10_12() AVAILABLE_10_12; // expected-note 5 {{'func_10_12' has been explicitly marked partial here}}
+
+int func_10_0() AVAILABLE_10_0;
+
+void use_func() {
+  func_10_11(); // expected-warning{{'func_10_11' is only available on macOS 10.11 or newer}} expected-note{{enclose 'func_10_11' in an @available check to silence this warning}}
+
+  if (@available(macos 10.11, *))
+func_10_11();
+  else
+func_10_11(); // expected-warning{{'func_10_11' is only available on macOS 10.11 or newer}} expected-note{{enclose 'func_10_11' in an @available check to silence this warning}}
+}
+
+void defn_10_11() AVAILABLE_10_11;
+
+void defn_10_11() {
+  func_10_11();
+}
+
+void nested_ifs() {
+  if (@available(macos 10.12, *)) {
+if (@available(macos 10.10, *)) {
+  func_10_12();
+} else {
+  func_10_12();
+}
+  } else {
+func_10_12(); // expected-warning{{'func_10_12' is only available on macOS 10.12 or newer}} expected-note{{enclose 'func_10_12' in an @available check to silence this warning}}
+  }
+}
+
+void star_case() {
+  if (@available(ios 9, *)) {
+func_10_11(); // expected-warning{{'func_10_11' is only available on macOS 10.11 or newer}} expected-note{{enclose 'func_10_11' in an @available check to silence this warning}}
+func_10_0();
+  } else
+func_10_11(); // expected-warning{{'func_10_11' is only available on macOS 10.11 or newer}} expected-note{{enclose 'func_10_11' in an @available check to silence this warning}}
+
+  if (@available(macos 10.11, *)) {
+if (@available(ios 8, *)) {
+  func_10_11();
+  func_10_12(); // expected-warning{{'func_10_12' is only available on macOS 10.12 or newer}} expected-note{{enclose}}
+} else {
+  func_10_11();
+  func_10_12(); // expected-warning{{'func_10_12' is only available on macOS 10.12 or newer}} expected-note{{enclose}}
+}
+  }
+}
+
+typedef int int_10_11 AVAILABLE_10_11; // expected-note {{'int_10_11' has been explicitly marked partial here}}
+typedef int int_10_12 AVAILABLE_10_12; // expected-note {{'int_10_12' has been explicitly marked partial here}}
+
+void use_typedef() {
+  int_10_11 x; // expected-warning{{'int_10_11' is only available on macOS 10.11 or newer}} expected-note{{enclose 'int_10_11' in an @available check to silence this warning}}
+}
+
+__attribute__((objc_root_class))
+AVAILABLE_10_11 @interface Class_10_11 {
+  int_10_11 foo;
+  int_10_12 bar; // expected-warning {{'int_10_12' is partial: introduced in macOS 10.12}} expected-note{{redeclare}}
+}
+- (void)method1;
+- (void)method2;
+@end
+
+@implementation Class_10_11
+- (void) method1 {
+  func_10_11();
+  func_10_12(); // expected-warning{{'func_10_12' is only available on macOS 10.12 or newer}} expected-note{{enclose 'func_10_12' in an @available 

Re: [PATCH] D23003: [ObjC Availability] Warn upon unguarded use of partially available declaration

2016-08-04 Thread Manman Ren via cfe-commits
manmanren added a comment.

Hi Erik,

Thanks for working on this! It is great to see these patches coming.

Manman



Comment at: include/clang/Sema/Sema.h:9608
@@ -9604,1 +9607,3 @@
 
+  /// \brief Whether we should emit an availability diagnostic for \c D.
+  bool ShouldDiagnoseAvailabilityOfDecl(

Can you explain the inputs and outputs?


Comment at: lib/Sema/SemaDeclAttr.cpp:6517
@@ +6516,3 @@
+
+/// \brief This class implements -Wunguarded-availability.
+class DiagnoseUnguardedAvailability

Can you add a high level description of what this class is doing to issue 
unguarded diagnostics?


Comment at: lib/Sema/SemaDeclAttr.cpp:6540
@@ +6539,3 @@
+
+  bool VisitTypeLoc(TypeLoc TL);
+

Do we cover all usage of decls with the above three member functions?


Comment at: lib/Sema/SemaDeclAttr.cpp:6552
@@ +6551,3 @@
+
+  if (SemaRef.ShouldDiagnoseAvailabilityOfDecl(D, nullptr, false, ObjCPDecl,
+   ContextVersion, nullptr, AD)) {

It is easier to read if you add comment for the boolean argument.


Comment at: lib/Sema/SemaDeclAttr.cpp:6554
@@ +6553,3 @@
+   ContextVersion, nullptr, AD)) {
+// All other diagnostic kinds have already been handled.
+if (AD != Sema::AD_Partial)

Can you mention where they are handled?


Comment at: lib/Sema/SemaExpr.cpp:110
@@ -113,1 +109,3 @@
+VersionTuple ContextVersion, std::string *Message,
+Sema::AvailabilityDiagnostic ) {
 

This looks like a refactoring of DiagnoseAvailabilityOfDecl. Is it possible to 
commit as a NFC patch?


Comment at: test/SemaObjC/unguarded-availability.m:93
@@ +92,3 @@
+  label2:
+goto label1; // expected-error{{cannot jump from this goto statement to 
its label}}
+  }

Should we emit error here? Or should we just ignore the tighter availability 
scope?


https://reviews.llvm.org/D23003



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D23003: [ObjC Availability] Warn upon unguarded use of partially available declaration

2016-08-02 Thread Erik Pilkington via cfe-commits
erik.pilkington updated this revision to Diff 66555.
erik.pilkington added a comment.

@dcoughlin: Yes, good point!

This new patch uses the enclosing version to diagnose both branches of the '*' 
case, as opposed to ignoring them.


https://reviews.llvm.org/D23003

Files:
  include/clang/AST/Stmt.h
  include/clang/Basic/DiagnosticGroups.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/ScopeInfo.h
  include/clang/Sema/Sema.h
  lib/AST/Stmt.cpp
  lib/Sema/JumpDiagnostics.cpp
  lib/Sema/ScopeInfo.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaDeclAttr.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaStmt.cpp
  test/Parser/objc-available.m
  test/Sema/attr-availability.c
  test/SemaObjC/attr-availability.m
  test/SemaObjC/property-deprecated-warning.m
  test/SemaObjC/unguarded-availability.m

Index: test/SemaObjC/unguarded-availability.m
===
--- test/SemaObjC/unguarded-availability.m
+++ test/SemaObjC/unguarded-availability.m
@@ -0,0 +1,111 @@
+// RUN: %clang_cc1 -triple x86_64-apple-macosx-10.9 -Wunguarded-availability -fsyntax-only -verify %s
+// RUN: %clang_cc1 -xobjective-c++ -DOBJCPP -triple x86_64-apple-macosx-10.9 -Wunguarded-availability -fsyntax-only -verify %s
+
+#define AVAILABLE_10_0  __attribute__((availability(macos, introduced = 10.0)))
+#define AVAILABLE_10_11 __attribute__((availability(macos, introduced = 10.11)))
+#define AVAILABLE_10_12 __attribute__((availability(macos, introduced = 10.12)))
+
+int func_10_11() AVAILABLE_10_11; // expected-note 4 {{'func_10_11' has been explicitly marked partial here}}
+
+int func_10_12() AVAILABLE_10_12; // expected-note 4 {{'func_10_12' has been explicitly marked partial here}}
+
+int func_10_0() AVAILABLE_10_0;
+
+void use_func() {
+  func_10_11(); // expected-warning{{'func_10_11' is only available on macOS 10.11 or newer}} expected-note{{enclose 'func_10_11' in an @available check to silence this warning}}
+
+  if (@available(macos 10.11, *))
+func_10_11();
+  else
+func_10_11(); // expected-warning{{'func_10_11' is only available on macOS 10.11 or newer}} expected-note{{enclose 'func_10_11' in an @available check to silence this warning}}
+}
+
+void defn_10_11() AVAILABLE_10_11;
+
+void defn_10_11() {
+  func_10_11();
+}
+
+void nested_ifs() {
+  if (@available(macos 10.12, *)) {
+if (@available(macos 10.10, *)) {
+  func_10_12();
+} else {
+  func_10_12();
+}
+  } else {
+func_10_12(); // expected-warning{{'func_10_12' is only available on macOS 10.12 or newer}} expected-note{{enclose 'func_10_12' in an @available check to silence this warning}}
+  }
+}
+
+void star_case() {
+  if (@available(ios 9, *)) {
+func_10_11(); // expected-warning{{'func_10_11' is only available on macOS 10.11 or newer}} expected-note{{enclose 'func_10_11' in an @available check to silence this warning}}
+func_10_0();
+  } else
+func_10_11(); // expected-warning{{'func_10_11' is only available on macOS 10.11 or newer}} expected-note{{enclose 'func_10_11' in an @available check to silence this warning}}
+
+  if (@available(macos 10.11, *)) {
+if (@available(ios 8, *)) {
+  func_10_11();
+  func_10_12(); // expected-warning{{'func_10_12' is only available on macOS 10.12 or newer}} expected-note{{enclose}}
+} else {
+  func_10_11();
+  func_10_12(); // expected-warning{{'func_10_12' is only available on macOS 10.12 or newer}} expected-note{{enclose}}
+}
+  }
+}
+
+typedef int int_10_11 AVAILABLE_10_11; // expected-note {{'int_10_11' has been explicitly marked partial here}}
+typedef int int_10_12 AVAILABLE_10_12; // expected-note {{'int_10_12' has been explicitly marked partial here}}
+
+void use_typedef() {
+  int_10_11 x; // expected-warning{{'int_10_11' is only available on macOS 10.11 or newer}} expected-note{{enclose 'int_10_11' in an @available check to silence this warning}}
+}
+
+__attribute__((objc_root_class))
+AVAILABLE_10_11 @interface Class_10_11 {
+  int_10_11 foo;
+  int_10_12 bar; // expected-warning {{'int_10_12' is partial: introduced in macOS 10.12}} expected-note{{redeclare}}
+}
+- (void)method1;
+- (void)method2;
+@end
+
+@implementation Class_10_11
+- (void) method1 {
+  func_10_11();
+  func_10_12(); // expected-warning{{'func_10_12' is only available on macOS 10.12 or newer}} expected-note{{enclose 'func_10_12' in an @available check to silence this warning}}
+}
+
+- (void)method2 AVAILABLE_10_12 {
+  func_10_12();
+}
+
+@end
+
+int protected_scope() {
+  if (@available(macos 10.20, *)) { // expected-note 2 {{jump enters controlled statement of if available}}
+  label1:
+return 0;
+  } else {
+  label2:
+goto label1; // expected-error{{cannot jump from this goto statement to its label}}
+  }
+
+  goto label2; // expected-error{{cannot jump from this goto statement to its label}}
+}
+
+#ifdef OBJCPP
+
+int f(char) __attribute__((availability(macos, introduced=10.12))); // expected-note {{'f' has been 

Re: [PATCH] D23003: [ObjC Availability] Warn upon unguarded use of partially available declaration

2016-08-02 Thread Devin Coughlin via cfe-commits
dcoughlin added inline comments.


Comment at: lib/Sema/SemaDeclAttr.cpp:6611
@@ +6610,3 @@
+  if (auto *E = dyn_cast(If->getCond())) {
+// If we're using the '*' case here, then we cannot emit any warnings for
+// the 'then' branch.

Do you still want to suppress warnings in the 'then' branch for '*'? I think 
there is potential value in pointing out uses of APIs that are not available on 
the minimum deployment target for the '*' case.


https://reviews.llvm.org/D23003



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D23003: [ObjC Availability] Warn upon unguarded use of partially available declaration

2016-08-02 Thread Erik Pilkington via cfe-commits
erik.pilkington updated this revision to Diff 66501.
erik.pilkington added a comment.

This new patch removes the warning `diag::warn_available_using_star_case`, as 
per Devin's suggestion.


https://reviews.llvm.org/D23003

Files:
  include/clang/AST/Stmt.h
  include/clang/Basic/DiagnosticGroups.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/ScopeInfo.h
  include/clang/Sema/Sema.h
  lib/AST/Stmt.cpp
  lib/Sema/JumpDiagnostics.cpp
  lib/Sema/ScopeInfo.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaDeclAttr.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaStmt.cpp
  test/Parser/objc-available.m
  test/Sema/attr-availability.c
  test/SemaObjC/attr-availability.m
  test/SemaObjC/property-deprecated-warning.m
  test/SemaObjC/unguarded-availability.m

Index: test/SemaObjC/unguarded-availability.m
===
--- test/SemaObjC/unguarded-availability.m
+++ test/SemaObjC/unguarded-availability.m
@@ -0,0 +1,97 @@
+// RUN: %clang_cc1 -triple x86_64-apple-macosx-10.9 -Wunguarded-availability -fsyntax-only -verify %s
+// RUN: %clang_cc1 -xobjective-c++ -DOBJCPP -triple x86_64-apple-macosx-10.9 -Wunguarded-availability -fsyntax-only -verify %s
+
+#define AVAILABLE_10_11 __attribute__((availability(macos, introduced = 10.11)))
+#define AVAILABLE_10_12 __attribute__((availability(macos, introduced = 10.12)))
+
+int func_10_11() AVAILABLE_10_11; // expected-note 3 {{'func_10_11' has been explicitly marked partial here}}
+
+int func_10_12() AVAILABLE_10_12; // expected-note 2 {{'func_10_12' has been explicitly marked partial here}}
+
+void use_func() {
+  func_10_11(); // expected-warning{{'func_10_11' is only available on macOS 10.11 or newer}} expected-note{{enclose 'func_10_11' in an @available check to silence this warning}}
+
+  if (@available(macos 10.11, *))
+func_10_11();
+  else
+func_10_11(); // expected-warning{{'func_10_11' is only available on macOS 10.11 or newer}} expected-note{{enclose 'func_10_11' in an @available check to silence this warning}}
+}
+
+void defn_10_11() AVAILABLE_10_11;
+
+void defn_10_11() {
+  func_10_11();
+}
+
+void nested_ifs() {
+  if (@available(macos 10.12, *)) {
+if (@available(macos 10.10, *)) {
+  func_10_12();
+} else {
+  func_10_12();
+}
+  } else {
+func_10_12(); // expected-warning{{'func_10_12' is only available on macOS 10.12 or newer}} expected-note{{enclose 'func_10_12' in an @available check to silence this warning}}
+  }
+}
+
+void star_case() {
+  if (@available(ios 9, *))
+func_10_11();
+  else
+func_10_11(); // expected-warning{{'func_10_11' is only available on macOS 10.11 or newer}} expected-note{{enclose 'func_10_11' in an @available check to silence this warning}}
+}
+
+typedef int int_10_11 AVAILABLE_10_11; // expected-note {{'int_10_11' has been explicitly marked partial here}}
+typedef int int_10_12 AVAILABLE_10_12; // expected-note {{'int_10_12' has been explicitly marked partial here}}
+
+void use_typedef() {
+  int_10_11 x; // expected-warning{{'int_10_11' is only available on macOS 10.11 or newer}} expected-note{{enclose 'int_10_11' in an @available check to silence this warning}}
+}
+
+__attribute__((objc_root_class))
+AVAILABLE_10_11 @interface Class_10_11 {
+  int_10_11 foo;
+  int_10_12 bar; // expected-warning {{'int_10_12' is partial: introduced in macOS 10.12}} expected-note{{redeclare}}
+}
+- (void)method1;
+- (void)method2;
+@end
+
+@implementation Class_10_11
+- (void) method1 {
+  func_10_11();
+  func_10_12(); // expected-warning{{'func_10_12' is only available on macOS 10.12 or newer}} expected-note{{enclose 'func_10_12' in an @available check to silence this warning}}
+}
+
+- (void)method2 AVAILABLE_10_12 {
+  func_10_12();
+}
+
+@end
+
+int protected_scope() {
+  if (@available(macos 10.20, *)) { // expected-note 2 {{jump enters controlled statement of if available}}
+  label1:
+return 0;
+  } else {
+  label2:
+goto label1; // expected-error{{cannot jump from this goto statement to its label}}
+  }
+
+  goto label2; // expected-error{{cannot jump from this goto statement to its label}}
+}
+
+#ifdef OBJCPP
+
+int f(char) __attribute__((availability(macos, introduced=10.12))); // expected-note {{'f' has been explicitly marked partial here}}
+int f(int);
+
+template  int use_f() {
+  return f(T()); // expected-warning{{'f' is only available on macOS 10.12 or newer}} expected-note{{enclose}}
+}
+
+int a = use_f();
+int b = use_f(); // expected-note{{in instantiation}}
+
+#endif
Index: test/SemaObjC/property-deprecated-warning.m
===
--- test/SemaObjC/property-deprecated-warning.m
+++ test/SemaObjC/property-deprecated-warning.m
@@ -9,7 +9,7 @@
 @property(nonatomic,assign) id ptarget __attribute__((availability(ios,introduced=2.0,deprecated=3.0))); // expected-note {{property 'ptarget' is declared deprecated here}} expected-note {{'ptarget' has been explicitly marked 

Re: [PATCH] D23003: [ObjC Availability] Warn upon unguarded use of partially available declaration

2016-08-01 Thread Devin Coughlin via cfe-commits
dcoughlin added a comment.

It's really great to see this!



Comment at: lib/Sema/SemaExpr.cpp:15200
@@ -15182,2 +15199,3 @@
 // platform.
-Diag(AtLoc, diag::warn_available_using_star_case) << RParen << Platform;
+Diag(AtLoc, diag::warn_available_using_star_case)
+<< SourceRange(AtLoc, RParen) << Platform;

In Swift we don't warn for this scenario and don't require the programmer to 
explicitly account for the current platform. The rationale behind '*' was to 
make platform bringup easier. Because new platforms are typically forked from 
existing platforms, treating '*' as the minimum deployment target on the 
current platform would typically do the "right thing" on new platforms. In 
cases where it doesn't, the user would still get a diagnostic if she tried to 
use a potentially unavailable API.

If I understand it correctly, with the behavior here anyone porting code to a 
new platform will get a warning for each `@available`. Is this what you want?


https://reviews.llvm.org/D23003



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits