]> granicus.if.org Git - clang/commitdiff
Unguarded availability diagnoser should use TraverseStmt instead of
authorAlex Lorenz <arphaman@gmail.com>
Thu, 17 Aug 2017 14:22:27 +0000 (14:22 +0000)
committerAlex Lorenz <arphaman@gmail.com>
Thu, 17 Aug 2017 14:22:27 +0000 (14:22 +0000)
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
test/FixIt/fixit-availability.mm

index 41f8f9f0bc50900c7fb9515387d1a7039b623f4f..3d58b9ae05af91ba50212596ba1d774f4a4c01f3 100644 (file)
@@ -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);
index f6a185569443499457686f046aafb4d8b8e46d0b..a5660825327f77ae524a495336dd2c4e8db005dc 100644 (file)
@@ -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