]> granicus.if.org Git - clang/commitdiff
Merge function-return.c into function.c
authorChris Lattner <sabre@nondot.org>
Thu, 18 Dec 2008 02:01:17 +0000 (02:01 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 18 Dec 2008 02:01:17 +0000 (02:01 +0000)
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

include/clang/Basic/DiagnosticKinds.def
lib/Sema/SemaStmt.cpp
test/Parser/objc-try-catch-1.m
test/Sema/function-return.c [deleted file]
test/Sema/function.c
test/Sema/implicit-decl.c

index 1417b8acbdeb964ca81e25a626436cd90b97d75a..38d084fc99cc7d204c4dee2c9bc62739c5c7df9f 100644 (file)
@@ -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")
index 21f897f639b4f9eed12852a7a4bdad1579478ac8..0604470c1dcda53cd3310e84d5b716240a30c913 100644 (file)
@@ -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<ObjCMethodDecl>(CurDecl)
+        << RetValExp->getSourceRange();
     }
     return new ReturnStmt(ReturnLoc, RetValExp);
   }
index d8264fabbe36142b91ee5b0ee37059ad1f6d285d..2e3c5b14a336a5ae02790be59c2d5ac860a3ce58 100644 (file)
@@ -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 (file)
index 8af074e..0000000
+++ /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}}
-}
index f2aa8d92162d298424da564910744117908cff2f..de970a09b352f2f5f1be20514676a2d502f342a1 100644 (file)
@@ -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}}
+}
index 099cf9d20ea6cc515c55f513a91119ff93106c4e..91f5dd103f637d6c20156895058d514e966cfe3b 100644 (file)
@@ -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;