add option -Wreturn-type
authorMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Mon, 2 Jun 2008 11:32:06 +0000 (11:32 +0000)
committerMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Mon, 2 Jun 2008 11:32:06 +0000 (11:32 +0000)
[r19923]

ast2firm.c
warning.c
warning.h

index fe849fe..c09a7c5 100644 (file)
@@ -38,6 +38,7 @@
 #include "diagnostic.h"
 #include "lang_features.h"
 #include "types.h"
+#include "warning.h"
 #include "driver/firm_opt.h"
 #include "driver/firm_cmdline.h"
 
@@ -4974,9 +4975,11 @@ static void create_function(declaration_t *declaration)
                                in[0] = new_Const(mode, get_mode_null(mode));
                        } else {
                                in[0] = new_Unknown(mode);
-                               warningf(&declaration->source_position, "missing return statement at end of non-void function '%Y'",
-                                       declaration->symbol);
-
+                               if(warning.return_type) {
+                                       warningf(&declaration->source_position,
+                                               "missing return statement at end of non-void function '%Y'",
+                                               declaration->symbol);
+                               }
                        }
                        ret = new_Return(get_store(), 1, in);
                }
index c93ed20..42b47b4 100644 (file)
--- a/warning.c
+++ b/warning.c
@@ -46,7 +46,8 @@ warning_t warning = {
        .unused_label                  = false,
        .unused_parameter              = false,
        .unused_value                  = true,
-       .unused_variable               = false
+       .unused_variable               = false,
+       .return_type                   = true
 };
 
 void set_warning_opt(const char *const opt)
@@ -85,6 +86,7 @@ void set_warning_opt(const char *const opt)
                SET(unused_parameter)
                SET(unused_value)
                SET(unused_variable)
+               SET(return_type)
        }
        OPT("attribute",                     attribute)
        OPT("char-subscripts",               char_subscripts)
@@ -135,6 +137,7 @@ void set_warning_opt(const char *const opt)
        OPT("unused-parameter",              unused_parameter)
        OPT("unused-value",                  unused_value)
        OPT("unused-variable",               unused_variable)
+       OPT("return-type",                   return_type)
 #undef OPT
 #undef SET
 #undef OPT_X
index 3b3f22f..ef5596a 100644 (file)
--- a/warning.h
+++ b/warning.h
@@ -104,6 +104,9 @@ typedef struct warning_t {
 #if 0 // TODO
        bool write_strings:1;                 /**< Give string constants the type 'const char[LENGTH]' so that copying the address of one into a 'char *' pointer will get a warning */
 #endif
+       bool return_type:1;                   /**< Warn whenever a function is defined with a return-type that
+                                                  defaults to `int'.  Also warn about any `return' statement with no
+                                                  return-value in a function whose return-type is not `void'. */
 } warning_t;
 
 extern warning_t warning;