]> granicus.if.org Git - clang/commit
Add TreatUnavailableAsInvalid for the verification-only mode in InitListChecker.
authorManman Ren <manman.ren@gmail.com>
Thu, 10 Mar 2016 18:53:19 +0000 (18:53 +0000)
committerManman Ren <manman.ren@gmail.com>
Thu, 10 Mar 2016 18:53:19 +0000 (18:53 +0000)
commitdfc9e6a5fb591935d087aea7b63a1fade7ef9e6e
treeb2275d8be52c226754afdb5232409b11d38b3d0f
parentb6a743ebedc09bc5bf93697774756f0c16266b98
Add TreatUnavailableAsInvalid for the verification-only mode in InitListChecker.

Given the following test case:
typedef struct {
  const char *name;
  id field;
} Test9;
extern void doSomething(Test9 arg);
void test9() {
  Test9 foo2 = {0, 0};
  doSomething(foo2);
}
With a release compiler, we don't emit any message and silently ignore the
variable "foo2". With an assert compiler, we get an assertion failure.

The root cause —————————————
Back in r140457 we gave InitListChecker a verification-only mode, and will use
CanUseDecl instead of DiagnoseUseOfDecl for verification-only mode.

These two functions handle unavailable issues differently:
In Sema::CanUseDecl, we say the decl is invalid when the Decl is unavailable and
the current context is available.

In Sema::DiagnoseUseOfDecl, we say the decl is usable by ignoring the return
code of DiagnoseAvailabilityOfDecl

So with an assert build, we will hit an assertion in diagnoseListInit
assert(DiagnoseInitList.HadError() &&
       "Inconsistent init list check result.");

The fix -------------------
If we follow what is implemented in CanUseDecl and treat Decls with
unavailable issues as invalid, the variable decl of “foo2” will be marked as
invalid. Since unavailable checking is processed in delayed diagnostics
(r197627), we will silently ignore the diagnostics when we find out that
the variable decl is invalid.

We add a flag "TreatUnavailableAsInvalid" for the verification-only mode.
For overload resolution, we want to say decls with unavailable issues are
invalid; but for everything else, we should say they are valid and
emit diagnostics. Depending on the value of the flag, CanUseDecl
can return different values for unavailable issues.

rdar://23557300
Differential Revision: http://reviews.llvm.org/D15314

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@263149 91177308-0d34-0410-b5e6-96231b3b80d8
include/clang/Sema/Initialization.h
include/clang/Sema/Sema.h
lib/Sema/SemaDecl.cpp
lib/Sema/SemaExpr.cpp
lib/Sema/SemaInit.cpp
test/SemaObjC/Inputs/arc-system-header.h
test/SemaObjC/arc-system-header.m