Author: arphaman Date: Tue May 16 08:58:53 2017 New Revision: 303170 URL: http://llvm.org/viewvc/llvm-project?rev=303170&view=rev Log: [Sema] Avoid duplicate -Wunguarded-availability warnings in nested functions
rdar://31862310 Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp cfe/trunk/test/SemaObjC/unguarded-availability.m Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=303170&r1=303169&r2=303170&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original) +++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Tue May 16 08:58:53 2017 @@ -7230,6 +7230,13 @@ public: SemaRef.Context.getTargetInfo().getPlatformMinVersion()); } + bool TraverseDecl(Decl *D) { + // Avoid visiting nested functions to prevent duplicate warnings. + if (!D || isa<FunctionDecl>(D)) + return true; + return Base::TraverseDecl(D); + } + bool TraverseStmt(Stmt *S) { if (!S) return true; @@ -7243,6 +7250,8 @@ public: bool TraverseIfStmt(IfStmt *If); + bool TraverseLambdaExpr(LambdaExpr *E) { return true; } + bool VisitObjCMessageExpr(ObjCMessageExpr *Msg) { if (ObjCMethodDecl *D = Msg->getMethodDecl()) DiagnoseDeclAvailability( Modified: cfe/trunk/test/SemaObjC/unguarded-availability.m URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/unguarded-availability.m?rev=303170&r1=303169&r2=303170&view=diff ============================================================================== --- cfe/trunk/test/SemaObjC/unguarded-availability.m (original) +++ cfe/trunk/test/SemaObjC/unguarded-availability.m Tue May 16 08:58:53 2017 @@ -8,7 +8,7 @@ int func_10_11() AVAILABLE_10_11; // expected-note 4 {{'func_10_11' has been explicitly marked partial here}} #ifdef OBJCPP -// expected-note@+2 2 {{marked partial here}} +// expected-note@+2 6 {{marked partial here}} #endif int func_10_12() AVAILABLE_10_12; // expected-note 6 {{'func_10_12' has been explicitly marked partial here}} @@ -188,4 +188,19 @@ auto topLevelLambda = [] () { func_10_12(); }; +void functionInFunction() { + func_10_12(); // expected-warning{{'func_10_12' is only available on macOS 10.12 or newer}} expected-note{{@available}} + struct DontWarnTwice { + void f() { + func_10_12(); // expected-warning{{'func_10_12' is only available on macOS 10.12 or newer}} expected-note{{@available}} + } + }; + void([] () { + func_10_12(); // expected-warning{{'func_10_12' is only available on macOS 10.12 or newer}} expected-note{{@available}} + }); + (void)(^ { + func_10_12(); // expected-warning{{'func_10_12' is only available on macOS 10.12 or newer}} expected-note{{@available}} + }); +} + #endif _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits