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)

llvm-svn: 311088
This commit is contained in:
Alex Lorenz 2017-08-17 14:22:27 +00:00
parent b5205c69d2
commit 98f9fcdb1b
2 changed files with 9 additions and 2 deletions

View 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);

View 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