[PATCH] D25283: AvailabilityAttrs: Refactor context checking when diagnosing an availability violation

Erik Pilkington via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 5 10:04:03 PDT 2016


erik.pilkington created this revision.
erik.pilkington added a reviewer: manmanren.
erik.pilkington added a subscriber: cfe-commits.

This patch removes some redundant functions that implement checking availability against context, and implements a new, more correct one: `ShouldDiagnoseAvailabilityInContext`. This is done to more easily allow delaying `AD_NotYetIntroduced` diagnostics, which is a patch I'll submit right after this!

As it happens, this fixes a bug:

  int unavailable_global __attribute__((unavailable));
  
  __attribute__((unavailable))
  @interface Foo
  - meth;
  @end
  
  @implementation Foo
  - meth {
    (void) unavailable_global; // no error
    (void) ^{
      (void) unavailable_global; // incorrect-error: 'unavailable_global' is not available
    };
  }
  @end

Here, there is a reference to an unavailable declaration, `unavailable`, in the context of a block. We shouldn't emit an error here because 'meth' is implicitly unavailable, meaning that we should be able to reference other unavailable declarations inside it

The problem is that, though both `isDeclUnavailable()` and `getCurContextAvailability()` check the reference to `unavailable_global`, `isDeclUnavailable` doesn't infer availability attributes from @interface to @implementation (But does consider nested contexts), and `getCurContextAvailability()` doesn't consider non-immediate contexts (But does infer from @interface -> @implementation). Since they both don't catch this case, this error is emitted when it really shouldn't be!

Thanks for taking a look!


https://reviews.llvm.org/D25283

Files:
  include/clang/Sema/Sema.h
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaDeclAttr.cpp
  lib/Sema/SemaExpr.cpp
  test/SemaObjC/class-unavail-warning.m

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25283.73657.patch
Type: text/x-patch
Size: 14172 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161005/016fe4b2/attachment.bin>


More information about the cfe-commits mailing list