[cfe-commits] r61187 - in /cfe/trunk: include/clang/Basic/DiagnosticKinds.def lib/Sema/SemaStmt.cpp test/Parser/objc-try-catch-1.m test/Sema/function-return.c test/Sema/function.c test/Sema/implicit-decl.c
Chris Lattner
sabre at nondot.org
Wed Dec 17 18:01:18 PST 2008
Author: lattner
Date: Wed Dec 17 20:01:17 2008
New Revision: 61187
URL: http://llvm.org/viewvc/llvm-project?rev=61187&view=rev
Log:
Merge function-return.c into function.c
Fix PR2790 by making a warning an EXTWARN instead of EXTENSION.
Add a new EXTENSION warning for "return (some void expression);"
Removed:
cfe/trunk/test/Sema/function-return.c
Modified:
cfe/trunk/include/clang/Basic/DiagnosticKinds.def
cfe/trunk/lib/Sema/SemaStmt.cpp
cfe/trunk/test/Parser/objc-try-catch-1.m
cfe/trunk/test/Sema/function.c
cfe/trunk/test/Sema/implicit-decl.c
Modified: cfe/trunk/include/clang/Basic/DiagnosticKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticKinds.def?rev=61187&r1=61186&r2=61187&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticKinds.def Wed Dec 17 20:01:17 2008
@@ -1597,8 +1597,10 @@
"non-void %select{function|method}1 %0 should return a value")
DIAG(ext_return_missing_expr, EXTENSION,
"non-void %select{function|method}1 %0 should return a value")
-DIAG(ext_return_has_expr, EXTENSION,
+DIAG(ext_return_has_expr, EXTWARN,
"void %select{function|method}1 %0 should not return a value")
+DIAG(ext_return_has_void_expr, EXTENSION,
+ "void %select{function|method}1 %0 should not return void expression")
DIAG(err_shufflevector_non_vector, ERROR,
"first two arguments to __builtin_shufflevector must be vectors")
Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=61187&r1=61186&r2=61187&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Wed Dec 17 20:01:17 2008
@@ -759,13 +759,14 @@
if (FnRetType->isVoidType()) {
if (RetValExp) {// C99 6.8.6.4p1 (ext_ since GCC warns)
- if (FunctionDecl *FD = getCurFunctionDecl())
- Diag(ReturnLoc, diag::ext_return_has_expr)
- << FD->getIdentifier() << 0/*function*/<< RetValExp->getSourceRange();
- else
- Diag(ReturnLoc, diag::ext_return_has_expr)
- << getCurMethodDecl()->getDeclName() << 1 /*method*/
- << RetValExp->getSourceRange();
+ unsigned D = diag::ext_return_has_expr;
+ if (RetValExp->getType()->isVoidType())
+ D = diag::ext_return_has_void_expr;
+ NamedDecl *CurDecl = getCurFunctionOrMethodDecl();
+
+ Diag(ReturnLoc, D)
+ << CurDecl->getDeclName() << isa<ObjCMethodDecl>(CurDecl)
+ << RetValExp->getSourceRange();
}
return new ReturnStmt(ReturnLoc, RetValExp);
}
Modified: cfe/trunk/test/Parser/objc-try-catch-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/objc-try-catch-1.m?rev=61187&r1=61186&r2=61187&view=diff
==============================================================================
--- cfe/trunk/test/Parser/objc-try-catch-1.m (original)
+++ cfe/trunk/test/Parser/objc-try-catch-1.m Wed Dec 17 20:01:17 2008
@@ -60,6 +60,6 @@
@try {
// Do something
} @catch (...) {}
- return 0;
+ return;
}
Removed: cfe/trunk/test/Sema/function-return.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/function-return.c?rev=61186&view=auto
==============================================================================
--- cfe/trunk/test/Sema/function-return.c (original)
+++ cfe/trunk/test/Sema/function-return.c (removed)
@@ -1,10 +0,0 @@
-// RUN: clang %s -fsyntax-only -verify -pedantic
-// PR2790
-
-void f1() {
- return 0; // expected-warning {{void function 'f1' should not return a value}}
-}
-
-int f2() {
- return; // expected-warning {{non-void function 'f2' should return a value}}
-}
Modified: cfe/trunk/test/Sema/function.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/function.c?rev=61187&r1=61186&r2=61187&view=diff
==============================================================================
--- cfe/trunk/test/Sema/function.c (original)
+++ cfe/trunk/test/Sema/function.c Wed Dec 17 20:01:17 2008
@@ -32,3 +32,10 @@
// PR3208
void t12(int) {} // expected-error{{parameter name omitted}}
+// PR2790
+void t13() {
+ return 0; // expected-warning {{void function 't13' should not return a value}}
+}
+int t14() {
+ return; // expected-warning {{non-void function 't14' should return a value}}
+}
Modified: cfe/trunk/test/Sema/implicit-decl.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/implicit-decl.c?rev=61187&r1=61186&r2=61187&view=diff
==============================================================================
--- cfe/trunk/test/Sema/implicit-decl.c (original)
+++ cfe/trunk/test/Sema/implicit-decl.c Wed Dec 17 20:01:17 2008
@@ -9,7 +9,7 @@
int32_t compCount = 0;
if (_CFCalendarDecomposeAbsoluteTimeV(compDesc, vector, compCount)) { // expected-note {{previous implicit declaration is here}}
}
- return ((void *)0);
+ return ((void *)0); // expected-warning {{void function 'func' should not return a value}}
}
Boolean _CFCalendarDecomposeAbsoluteTimeV(const char *componentDesc, int32_t **vector, int32_t count) { // expected-error{{conflicting types for '_CFCalendarDecomposeAbsoluteTimeV'}}
return 0;
More information about the cfe-commits
mailing list