From: Chris Lattner Date: Thu, 18 Dec 2008 02:01:17 +0000 (+0000) Subject: Merge function-return.c into function.c X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=65ce04bef06696379682410f399f37b43996d824;p=clang 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);" git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@61187 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticKinds.def b/include/clang/Basic/DiagnosticKinds.def index 1417b8acbd..38d084fc99 100644 --- a/include/clang/Basic/DiagnosticKinds.def +++ b/include/clang/Basic/DiagnosticKinds.def @@ -1597,8 +1597,10 @@ DIAG(warn_return_missing_expr, WARNING, "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") diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp index 21f897f639..0604470c1d 100644 --- a/lib/Sema/SemaStmt.cpp +++ b/lib/Sema/SemaStmt.cpp @@ -759,13 +759,14 @@ Sema::ActOnReturnStmt(SourceLocation ReturnLoc, ExprTy *rex) { 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(CurDecl) + << RetValExp->getSourceRange(); } return new ReturnStmt(ReturnLoc, RetValExp); } diff --git a/test/Parser/objc-try-catch-1.m b/test/Parser/objc-try-catch-1.m index d8264fabbe..2e3c5b14a3 100644 --- a/test/Parser/objc-try-catch-1.m +++ b/test/Parser/objc-try-catch-1.m @@ -60,6 +60,6 @@ void noTwoTokenLookAheadRequiresABitOfFancyFootworkInTheParser() { @try { // Do something } @catch (...) {} - return 0; + return; } diff --git a/test/Sema/function-return.c b/test/Sema/function-return.c deleted file mode 100644 index 8af074e0a0..0000000000 --- a/test/Sema/function-return.c +++ /dev/null @@ -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}} -} diff --git a/test/Sema/function.c b/test/Sema/function.c index f2aa8d9216..de970a09b3 100644 --- a/test/Sema/function.c +++ b/test/Sema/function.c @@ -32,3 +32,10 @@ void t11(){t10(1);} // 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}} +} diff --git a/test/Sema/implicit-decl.c b/test/Sema/implicit-decl.c index 099cf9d20e..91f5dd103f 100644 --- a/test/Sema/implicit-decl.c +++ b/test/Sema/implicit-decl.c @@ -9,7 +9,7 @@ void func() { 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;