From d4d128789d475f17fa1d04de15e491a4920f0e74 Mon Sep 17 00:00:00 2001
From: Alex Lorenz <arphaman@gmail.com>
Date: Thu, 17 Aug 2017 14:22:27 +0000
Subject: [PATCH] Unguarded availability diagnoser should use TraverseStmt
 instead of Base::TraverseStmt when visiting the then/else branches of if
 statements

This ensures that the statement stack is correctly tracked and correct
multi-statement fixit is generated inside of an if (@available)


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@311088 91177308-0d34-0410-b5e6-96231b3b80d8
---
 lib/Sema/SemaDeclAttr.cpp        | 3 +--
 test/FixIt/fixit-availability.mm | 8 ++++++++
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp
index 41f8f9f0bc5..3d58b9ae05a 100644
--- a/lib/Sema/SemaDeclAttr.cpp
+++ b/lib/Sema/SemaDeclAttr.cpp
@@ -7695,8 +7695,7 @@ bool DiagnoseUnguardedAvailability::TraverseIfStmt(IfStmt *If) {
     // If we're using the '*' case here or if this check is redundant, then we
     // use the enclosing version to check both branches.
     if (CondVersion.empty() || CondVersion <= AvailabilityStack.back())
-      return Base::TraverseStmt(If->getThen()) &&
-             Base::TraverseStmt(If->getElse());
+      return TraverseStmt(If->getThen()) && TraverseStmt(If->getElse());
   } else {
     // This isn't an availability checking 'if', we can just continue.
     return Base::TraverseIfStmt(If);
diff --git a/test/FixIt/fixit-availability.mm b/test/FixIt/fixit-availability.mm
index f6a18556944..a5660825327 100644
--- a/test/FixIt/fixit-availability.mm
+++ b/test/FixIt/fixit-availability.mm
@@ -108,6 +108,14 @@ void wrapDeclStmtUses() {
 // CHECK-NEXT: fix-it:{{.*}}:{[[@LINE-2]]:24-[[@LINE-2]]:24}:"\n    } else {\n        // Fallback on earlier versions\n    }"
   anotherFunction(y);
   anotherFunction(x);
+
+  if (@available(macOS 10.1, *)) {
+    int z = function();
+    (void)z;
+// CHECK: fix-it:{{.*}}:{[[@LINE-2]]:5-[[@LINE-2]]:5}:"if (@available(macOS 10.12, *)) {\n        "
+// CHECK-NEXT: fix-it:{{.*}}:{[[@LINE-2]]:13-[[@LINE-2]]:13}:"\n    } else {\n        // Fallback on earlier versions\n    }"
+    anotherFunction(x);
+  }
 }
 
 #define API_AVAILABLE(X) __attribute__((availability(macos, introduced=10.12))) // dummy macro
-- 
GitLab