mirror of
https://github.com/intel/llvm.git
synced 2026-01-23 07:58:23 +08:00
Improve -Wuninitialized warning under ARC for block variables that are
recursively captured. Under ARC, a block variable is zero-initialized when it is recursively captured by the block literal initializer. rdar://problem/11022762 llvm-svn: 359049
This commit is contained in:
@@ -1911,8 +1911,8 @@ def note_var_declared_here : Note<"variable %0 is declared here">;
|
||||
def note_uninit_var_use : Note<
|
||||
"%select{uninitialized use occurs|variable is captured by block}0 here">;
|
||||
def warn_uninit_byref_blockvar_captured_by_block : Warning<
|
||||
"block pointer variable %0 is uninitialized when captured by block">,
|
||||
InGroup<Uninitialized>, DefaultIgnore;
|
||||
"block pointer variable %0 is %select{uninitialized|null}1 when captured by "
|
||||
"block">, InGroup<Uninitialized>, DefaultIgnore;
|
||||
def note_block_var_fixit_add_initialization : Note<
|
||||
"did you mean to use __block %0?">;
|
||||
def note_in_omitted_aggregate_initializer : Note<
|
||||
|
||||
@@ -998,7 +998,8 @@ static bool DiagnoseUninitializedUse(Sema &S, const VarDecl *VD,
|
||||
if (VD->getType()->isBlockPointerType() && !VD->hasAttr<BlocksAttr>())
|
||||
S.Diag(BE->getBeginLoc(),
|
||||
diag::warn_uninit_byref_blockvar_captured_by_block)
|
||||
<< VD->getDeclName();
|
||||
<< VD->getDeclName()
|
||||
<< VD->getType().getQualifiers().hasObjCLifetime();
|
||||
else
|
||||
DiagUninitUse(S, VD, Use, true);
|
||||
}
|
||||
|
||||
@@ -1,12 +1,18 @@
|
||||
// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -Wuninitialized -fblocks -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
|
||||
// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -Wuninitialized -fblocks -verify %s
|
||||
// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -Wuninitialized -fblocks -x objective-c -fobjc-arc -DARC -verify %s
|
||||
|
||||
// rdar://10817031
|
||||
|
||||
int main() {
|
||||
void (^arc_fail)() = ^() { // expected-warning {{block pointer variable 'arc_fail' is uninitialized when captured by block}} \
|
||||
// expected-note {{did you mean to use __block 'arc_fail'}}
|
||||
void (^arc_fail)() = ^() {
|
||||
#ifdef ARC
|
||||
// expected-warning@-2 {{block pointer variable 'arc_fail' is null when captured by block}}
|
||||
#else
|
||||
// expected-warning@-4 {{block pointer variable 'arc_fail' is uninitialized when captured by block}}
|
||||
#endif
|
||||
// expected-note@-6 {{did you mean to use __block 'arc_fail'}}
|
||||
arc_fail(); // BOOM
|
||||
};
|
||||
}
|
||||
// CHECK: {7:12-7:12}:"__block "
|
||||
// CHECK: {8:12-8:12}:"__block "
|
||||
|
||||
Reference in New Issue
Block a user