r359049 - Improve -Wuninitialized warning under ARC for block variables that are

Akira Hatanaka via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 23 16:52:02 PDT 2019


Author: ahatanak
Date: Tue Apr 23 16:52:02 2019
New Revision: 359049

URL: http://llvm.org/viewvc/llvm-project?rev=359049&view=rev
Log:
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

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

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=359049&r1=359048&r2=359049&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Apr 23 16:52:02 2019
@@ -1911,8 +1911,8 @@ def note_var_declared_here : Note<"varia
 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<

Modified: cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp?rev=359049&r1=359048&r2=359049&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp (original)
+++ cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp Tue Apr 23 16:52:02 2019
@@ -998,7 +998,8 @@ static bool DiagnoseUninitializedUse(Sem
     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);
   }

Modified: cfe/trunk/test/FixIt/fixit-recursive-block.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/FixIt/fixit-recursive-block.c?rev=359049&r1=359048&r2=359049&view=diff
==============================================================================
--- cfe/trunk/test/FixIt/fixit-recursive-block.c (original)
+++ cfe/trunk/test/FixIt/fixit-recursive-block.c Tue Apr 23 16:52:02 2019
@@ -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 at -2 {{block pointer variable 'arc_fail' is null when captured by block}}
+#else
+// expected-warning at -4 {{block pointer variable 'arc_fail' is uninitialized when captured by block}}
+#endif
+// expected-note at -6 {{did you mean to use __block 'arc_fail'}}
        arc_fail(); // BOOM
     };
 }
-// CHECK: {7:12-7:12}:"__block "
+// CHECK: {8:12-8:12}:"__block "




More information about the cfe-commits mailing list