diff options
author | Alex Lorenz <arphaman@gmail.com> | 2017-08-17 14:22:27 +0000 |
---|---|---|
committer | Alex Lorenz <arphaman@gmail.com> | 2017-08-17 14:22:27 +0000 |
commit | 98f9fcdb1b83491017d4db639eb438a4da7e3ada (patch) | |
tree | 6da35e4220dd4d2ebcc8857e3fbdf5ab9604e8e7 | |
parent | b5205c69d29bca6f13d80c83977b9b435f976953 (diff) | |
download | bcm5719-llvm-98f9fcdb1b83491017d4db639eb438a4da7e3ada.tar.gz bcm5719-llvm-98f9fcdb1b83491017d4db639eb438a4da7e3ada.zip |
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
-rw-r--r-- | clang/lib/Sema/SemaDeclAttr.cpp | 3 | ||||
-rw-r--r-- | clang/test/FixIt/fixit-availability.mm | 8 |
2 files changed, 9 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index 41f8f9f0bc5..3d58b9ae05a 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/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/clang/test/FixIt/fixit-availability.mm b/clang/test/FixIt/fixit-availability.mm index f6a18556944..a5660825327 100644 --- a/clang/test/FixIt/fixit-availability.mm +++ b/clang/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 |