]> granicus.if.org Git - clang/commitdiff
Improve -Wuninitialized warning under ARC for block variables that are
authorAkira Hatanaka <ahatanaka@apple.com>
Tue, 23 Apr 2019 23:52:02 +0000 (23:52 +0000)
committerAkira Hatanaka <ahatanaka@apple.com>
Tue, 23 Apr 2019 23:52:02 +0000 (23:52 +0000)
recursively captured.

Under ARC, a block variable is zero-initialized when it is recursively
captured by the block literal initializer.

rdar://problem/11022762

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@359049 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/AnalysisBasedWarnings.cpp
test/FixIt/fixit-recursive-block.c

index 58253ef53c90d037bf955de75e9bf1aa653d8e44..0e69ca9c3dec1310b42228a7ae2071e7e24419e7 100644 (file)
@@ -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<
index d4aa701867f1bd9474ce10fcc0154b472828a1ef..7afe44658edeac306844dc8d7f99fc501ead4bfb 100644 (file)
@@ -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);
   }
index 3793f825f6ee35c6c2cce7d748a060282c6e164c..fec5b8028f907cc217a1a52ad0c635c3499168cf 100644 (file)
@@ -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 "