From 2c0ccd045514ae4dc951fb45b7c29216ba109bf7 Mon Sep 17 00:00:00 2001 From: Steve Naroff Date: Thu, 30 Apr 2009 16:01:26 +0000 Subject: [PATCH] Warn about invalid return statements by default. This fixes 10A345: Clang does not warm about mismatched returns (void return from a bool function) Will implement -Wreturn-type, -Wno-return-type in another commit. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70492 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticSemaKinds.td | 2 +- test/Analysis/null-deref-ps.c | 4 ++-- test/Sema/return.c | 9 +++++++++ 3 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 test/Sema/return.c diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 3a33a0678e..6448e65bab 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -1604,7 +1604,7 @@ def err_first_argument_to_va_arg_not_of_type_va_list : Error< 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">; diff --git a/test/Analysis/null-deref-ps.c b/test/Analysis/null-deref-ps.c index bd63c7edf0..2b0ed0aadb 100644 --- a/test/Analysis/null-deref-ps.c +++ b/test/Analysis/null-deref-ps.c @@ -69,7 +69,7 @@ int f4_b() { *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 @@ int* f10(int* p, signed char x, int y) { // 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; diff --git a/test/Sema/return.c b/test/Sema/return.c new file mode 100644 index 0000000000..b32b2e9eeb --- /dev/null +++ b/test/Sema/return.c @@ -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}} +} + -- 2.50.1