[PATCH] D102338: [Sema] Always search the full function scope context if a potential availability violation is encountered

Logan Smith via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed May 12 10:52:32 PDT 2021


logan-5 created this revision.
logan-5 added reviewers: erik.pilkington, rsmith, arphaman.
logan-5 added a project: clang.
logan-5 requested review of this revision.
Herald added a subscriber: cfe-commits.

Always search the full function scope context if a potential availability violation is encountered. This fixes both https://bugs.llvm.org/show_bug.cgi?id=50309 and https://bugs.llvm.org/show_bug.cgi?id=50310.

Previously, lambdas inside functions would mark their own bodies for later analysis when encountering a potentially unavailable decl, without taking into consideration that the entire lambda itself might be correctly guarded inside an `@available` check. The same applied to inner class member functions. Blocks happened to work as expected already, since `Sema::getEnclosingFunction()` skips through block scopes.

This patch instead simply and conservatively marks the entire outermost function scope for search, and removes some special-case logic that prevented `DiagnoseUnguardedAvailabilityViolations` from traversing down into lambdas and nested functions. This correctly accounts for arbitrarily nested lambdas, inner classes, and blocks that may be inside appropriate `@available` checks at any ancestor level. It also treats all potential availability violations inside functions consistently, without being overly sensitive to the current DeclContext, which previously caused issues where e.g. nested struct members were warned about twice.

`DiagnoseUnguardedAvailabilityViolations` now has more work to do in some cases, particularly in functions with many (possibly deeply) nested lambdas and classes, but the big-O is the same, and the simplicity of the approach and the fact that it fixes at least two bugs feels like a strong win IMO.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D102338

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaAvailability.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/SemaObjC/unguarded-availability.m

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D102338.344854.patch
Type: text/x-patch
Size: 5712 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210512/f4dc4374/attachment-0001.bin>


More information about the cfe-commits mailing list