[cfe-commits] r152271 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/AnalysisBasedWarnings.cpp test/FixIt/fixit-recursive-block.c
Fariborz Jahanian
fjahanian at apple.com
Wed Mar 7 16:22:50 PST 2012
Author: fjahanian
Date: Wed Mar 7 18:22:50 2012
New Revision: 152271
URL: http://llvm.org/viewvc/llvm-project?rev=152271&view=rev
Log:
improve on diagnostic and provide a fixit hint when
an uninitialized block variable is being called inside the
block literal. // rdar://10817031
Added:
cfe/trunk/test/FixIt/fixit-recursive-block.c
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=152271&r1=152270&r2=152271&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Mar 7 18:22:50 2012
@@ -1143,6 +1143,11 @@
def warn_maybe_uninit_var_captured_by_block : Warning<
"variable %0 may be uninitialized when captured by block">,
InGroup<UninitializedMaybe>, DefaultIgnore;
+def warn_uninit_byref_blockvar_captured_by_block : Warning<
+ "block pointer variable %0 is uninitialized when captured by block">,
+ InGroup<Uninitialized>, DefaultIgnore;
+def note_block_var_fixit_add_initialization : Note<
+ "consider using a '__block' variable %0 to silence this warning">;
def note_var_fixit_add_initialization : Note<
"initialize the variable %0 to silence this warning">;
def err_init_incomplete_type : Error<"initialization of incomplete type %0">;
Modified: cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp?rev=152271&r1=152270&r2=152271&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp (original)
+++ cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp Wed Mar 7 18:22:50 2012
@@ -425,17 +425,24 @@
}
static bool SuggestInitializationFixit(Sema &S, const VarDecl *VD) {
+ QualType VariableTy = VD->getType().getCanonicalType();
+ if (VariableTy->isBlockPointerType() &&
+ !VD->hasAttr<BlocksAttr>()) {
+ S.Diag(VD->getLocation(), diag::note_block_var_fixit_add_initialization) << VD->getDeclName()
+ << FixItHint::CreateInsertion(VD->getLocation(), "__block ");
+ return true;
+ }
+
// Don't issue a fixit if there is already an initializer.
if (VD->getInit())
return false;
-
+
// Suggest possible initialization (if any).
- QualType VariableTy = VD->getType().getCanonicalType();
const char *Init = S.getFixItZeroInitializerForType(VariableTy);
if (!Init)
return false;
-
SourceLocation Loc = S.PP.getLocForEndOfToken(VD->getLocEnd());
+
S.Diag(Loc, diag::note_var_fixit_add_initialization) << VD->getDeclName()
<< FixItHint::CreateInsertion(Loc, Init);
return true;
@@ -489,10 +496,15 @@
}
} else {
const BlockExpr *BE = cast<BlockExpr>(E);
- S.Diag(BE->getLocStart(),
- isAlwaysUninit ? diag::warn_uninit_var_captured_by_block
- : diag::warn_maybe_uninit_var_captured_by_block)
- << VD->getDeclName();
+ if (VD->getType()->isBlockPointerType() &&
+ !VD->hasAttr<BlocksAttr>())
+ S.Diag(BE->getLocStart(), diag::warn_uninit_byref_blockvar_captured_by_block)
+ << VD->getDeclName();
+ else
+ S.Diag(BE->getLocStart(),
+ isAlwaysUninit ? diag::warn_uninit_var_captured_by_block
+ : diag::warn_maybe_uninit_var_captured_by_block)
+ << VD->getDeclName();
}
// Report where the variable was declared when the use wasn't within
Added: cfe/trunk/test/FixIt/fixit-recursive-block.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/FixIt/fixit-recursive-block.c?rev=152271&view=auto
==============================================================================
--- cfe/trunk/test/FixIt/fixit-recursive-block.c (added)
+++ cfe/trunk/test/FixIt/fixit-recursive-block.c Wed Mar 7 18:22:50 2012
@@ -0,0 +1,12 @@
+// 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
+
+// rdar://10817031
+
+int main() {
+ void (^arc_fail)() = ^() { // expected-warning {{block pointer variable 'arc_fail' is uninitialized when captured by block}} \
+ // expected-note {{consider using a '__block' variable 'arc_fail' to silence this warning}}
+ arc_fail(); // BOOM
+ };
+}
+// CHECK: {7:12-7:12}:"__block "
More information about the cfe-commits
mailing list