[cfe-commits] r152047 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaExpr.cpp test/Sema/block-missing-return-type-warning.c test/Sema/warn-unused-parameters.c
Fariborz Jahanian
fjahanian at apple.com
Mon Mar 5 11:34:00 PST 2012
Author: fjahanian
Date: Mon Mar 5 13:34:00 2012
New Revision: 152047
URL: http://llvm.org/viewvc/llvm-project?rev=152047&view=rev
Log:
patch to optionally warn for block implementations without explicit
return types that return non-void values. // rdar://10735698
Added:
cfe/trunk/test/Sema/block-missing-return-type-warning.c
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/Sema/warn-unused-parameters.c
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=152047&r1=152046&r2=152047&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Mar 5 13:34:00 2012
@@ -4953,6 +4953,10 @@
" or pick a deployment target that supports them">;
def err_block_returning_array_function : Error<
"block cannot return %select{array|function}0 type %1">;
+def warn_block_missing_return_type : Warning<
+ "block literal is missing explicit return type and "
+ "returns non-void values">,
+ InGroup<DiagGroup<"block-missing-explicit-return-type">>, DefaultIgnore;
// Builtin annotation string.
def err_builtin_annotation_not_string_constant : Error<
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=152047&r1=152046&r2=152047&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon Mar 5 13:34:00 2012
@@ -8902,7 +8902,12 @@
ExprCleanupObjects.push_back(Result->getBlockDecl());
ExprNeedsCleanups = true;
}
-
+
+ if (BSI->TheDecl->blockMissingReturnType() &&
+ !RetTy->isDependentType() &&
+ !Context.getCanonicalType(RetTy)->isVoidType())
+ Diag(CaretLoc, diag::warn_block_missing_return_type);
+
return Owned(Result);
}
Added: cfe/trunk/test/Sema/block-missing-return-type-warning.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/block-missing-return-type-warning.c?rev=152047&view=auto
==============================================================================
--- cfe/trunk/test/Sema/block-missing-return-type-warning.c (added)
+++ cfe/trunk/test/Sema/block-missing-return-type-warning.c Mon Mar 5 13:34:00 2012
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify -fblocks -Wblock-missing-explicit-return-type
+// rdar://10735698
+
+int f;
+int main() {
+ int (^bar)() = ^{ if (f) return 'a'; // expected-warning {{block literal is missing explicit return type and returns non-void values}}
+ else return 10;
+ };
+
+ void (^bar1)() = ^{ f = 100; };
+
+ void (^bar2)() = ^(void){ f = 100; };
+
+ int (^bar3)() = ^ int { if (f) return 'a';
+ else return 10;
+ };
+
+}
Modified: cfe/trunk/test/Sema/warn-unused-parameters.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-unused-parameters.c?rev=152047&r1=152046&r2=152047&view=diff
==============================================================================
--- cfe/trunk/test/Sema/warn-unused-parameters.c (original)
+++ cfe/trunk/test/Sema/warn-unused-parameters.c Mon Mar 5 13:34:00 2012
@@ -24,7 +24,7 @@
// RUN: %clang_cc1 -fblocks -fsyntax-only -Weverything %s 2>&1 | FileCheck -check-prefix=CHECK-everything %s
// RUN: %clang_cc1 -fblocks -fsyntax-only -Weverything -Werror %s 2>&1 | FileCheck -check-prefix=CHECK-everything-error %s
// RUN: %clang_cc1 -fblocks -fsyntax-only -Weverything -Wno-unused %s 2>&1 | FileCheck -check-prefix=CHECK-everything-no-unused %s
-// CHECK-everything: 6 warnings generated
-// CHECK-everything-error: 5 errors generated
-// CHECK-everything-no-unused: 5 warnings generated
+// CHECK-everything: 7 warnings generated
+// CHECK-everything-error: 6 errors generated
+// CHECK-everything-no-unused: 6 warnings generated
More information about the cfe-commits
mailing list