r311088 - Unguarded availability diagnoser should use TraverseStmt instead of
Alex Lorenz via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 17 07:22:27 PDT 2017
Author: arphaman
Date: Thu Aug 17 07:22:27 2017
New Revision: 311088
URL: http://llvm.org/viewvc/llvm-project?rev=311088&view=rev
Log:
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)
Modified:
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/test/FixIt/fixit-availability.mm
Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=311088&r1=311087&r2=311088&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Thu Aug 17 07:22:27 2017
@@ -7695,8 +7695,7 @@ bool DiagnoseUnguardedAvailability::Trav
// 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);
Modified: cfe/trunk/test/FixIt/fixit-availability.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/FixIt/fixit-availability.mm?rev=311088&r1=311087&r2=311088&view=diff
==============================================================================
--- cfe/trunk/test/FixIt/fixit-availability.mm (original)
+++ cfe/trunk/test/FixIt/fixit-availability.mm Thu Aug 17 07:22:27 2017
@@ -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
More information about the cfe-commits
mailing list