[cfe-commits] r70492 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td test/Analysis/null-deref-ps.c test/Sema/return.c

Steve Naroff snaroff at apple.com
Thu Apr 30 09:01:26 PDT 2009


Author: snaroff
Date: Thu Apr 30 11:01:26 2009
New Revision: 70492

URL: http://llvm.org/viewvc/llvm-project?rev=70492&view=rev
Log:
Warn about invalid return statements by default.

This fixes <rdar://problem/6839489> 10A345: Clang does not warm about mismatched returns (void return from a bool function)
 
Will implement -Wreturn-type, -Wno-return-type in another commit.

Added:
    cfe/trunk/test/Sema/return.c
Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/test/Analysis/null-deref-ps.c

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=70492&r1=70491&r2=70492&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Apr 30 11:01:26 2009
@@ -1604,7 +1604,7 @@
 
 def warn_return_missing_expr : Warning<
   "non-void %select{function|method}1 %0 should return a value">;
-def ext_return_missing_expr : Extension<
+def ext_return_missing_expr : ExtWarn<
   "non-void %select{function|method}1 %0 should return a value">;
 def ext_return_has_expr : ExtWarn<
   "void %select{function|method}1 %0 should not return a value">;

Modified: cfe/trunk/test/Analysis/null-deref-ps.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/null-deref-ps.c?rev=70492&r1=70491&r2=70492&view=diff

==============================================================================
--- cfe/trunk/test/Analysis/null-deref-ps.c (original)
+++ cfe/trunk/test/Analysis/null-deref-ps.c Thu Apr 30 11:01:26 2009
@@ -69,7 +69,7 @@
     *p = 5; // no-warning
     p = 0;
   }
-  else return;
+  else return; // expected-warning {{non-void function 'f4_b' should return a value}}
 
   *p += 10; // expected-warning{{Dereference of null pointer}}
 }
@@ -160,7 +160,7 @@
   // This tests that our symbolication worked, and that we correctly test
   // x against 0 (with the same bitwidth).
   if (!x) {
-    if (!p) return;
+    if (!p) return; // expected-warning {{non-void function 'f10' should return a value}}
     *p = 10;
   }
   else p = 0;

Added: cfe/trunk/test/Sema/return.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/return.c?rev=70492&view=auto

==============================================================================
--- cfe/trunk/test/Sema/return.c (added)
+++ cfe/trunk/test/Sema/return.c Thu Apr 30 11:01:26 2009
@@ -0,0 +1,9 @@
+// RUN: clang-cc %s -fsyntax-only -verify
+
+// clang emits the following warning by default.
+// With GCC, -pedantic, -Wreturn-type or -Wall are required to produce the 
+// following warning.
+int t14() {
+  return; // expected-warning {{non-void function 't14' should return a value}}
+}
+





More information about the cfe-commits mailing list