-fbail-on-werror option

This commit is contained in:
Wolfgang Bumiller 2012-12-27 12:46:36 +01:00
parent 24f3098418
commit 5cfd97c344
5 changed files with 167 additions and 157 deletions

View file

@ -384,6 +384,14 @@ void con_cprintmsg (void *ctx, int lvl, const char *msgtype, const char *msg, ..
size_t compile_errors = 0; size_t compile_errors = 0;
size_t compile_warnings = 0; size_t compile_warnings = 0;
size_t compile_Werrors = 0;
static lex_ctx first_werror;
void compile_show_werrors()
{
con_cprintmsg((void*)&first_werror, LVL_ERROR, "first warning", "was here");
}
void vcompile_error(lex_ctx ctx, const char *msg, va_list ap) void vcompile_error(lex_ctx ctx, const char *msg, va_list ap)
{ {
++compile_errors; ++compile_errors;
@ -400,6 +408,7 @@ void compile_error(lex_ctx ctx, const char *msg, ...)
bool GMQCC_WARN vcompile_warning(lex_ctx ctx, int warntype, const char *fmt, va_list ap) bool GMQCC_WARN vcompile_warning(lex_ctx ctx, int warntype, const char *fmt, va_list ap)
{ {
const char *msgtype = "warning";
int lvl = LVL_WARNING; int lvl = LVL_WARNING;
char warn_name[1024]; char warn_name[1024];
@ -410,16 +419,22 @@ bool GMQCC_WARN vcompile_warning(lex_ctx ctx, int warntype, const char *fmt, va_
warn_name[1] = 'W'; warn_name[1] = 'W';
(void)util_strtononcmd(opts_warn_list[warntype].name, warn_name+2, sizeof(warn_name)-2); (void)util_strtononcmd(opts_warn_list[warntype].name, warn_name+2, sizeof(warn_name)-2);
++compile_warnings;
if (OPTS_WERROR(warntype)) { if (OPTS_WERROR(warntype)) {
if (!compile_Werrors)
first_werror = ctx;
++compile_Werrors;
msgtype = "Werror";
if (OPTS_FLAG(BAIL_ON_WERROR)) {
msgtype = "error";
++compile_errors; ++compile_errors;
}
lvl = LVL_ERROR; lvl = LVL_ERROR;
} }
else
++compile_warnings;
con_vprintmsg_c(lvl, ctx.file, ctx.line, ((lvl == LVL_ERROR) ? "error" : "warning"), fmt, ap, warn_name); con_vprintmsg_c(lvl, ctx.file, ctx.line, msgtype, fmt, ap, warn_name);
return OPTS_WERROR(warntype); return OPTS_WERROR(warntype) && OPTS_FLAG(BAIL_ON_WERROR);
} }
bool GMQCC_WARN compile_warning(lex_ctx ctx, int warntype, const char *fmt, ...) bool GMQCC_WARN compile_warning(lex_ctx ctx, int warntype, const char *fmt, ...)

View file

@ -685,12 +685,14 @@ int con_out (const char *, ...);
/* error/warning interface */ /* error/warning interface */
extern size_t compile_errors; extern size_t compile_errors;
extern size_t compile_Werrors;
extern size_t compile_warnings; extern size_t compile_warnings;
void /********/ compile_error (lex_ctx ctx, /*LVL_ERROR*/ const char *msg, ...); void /********/ compile_error (lex_ctx ctx, /*LVL_ERROR*/ const char *msg, ...);
void /********/ vcompile_error (lex_ctx ctx, /*LVL_ERROR*/ const char *msg, va_list ap); void /********/ vcompile_error (lex_ctx ctx, /*LVL_ERROR*/ const char *msg, va_list ap);
bool GMQCC_WARN compile_warning (lex_ctx ctx, int warntype, const char *fmt, ...); bool GMQCC_WARN compile_warning (lex_ctx ctx, int warntype, const char *fmt, ...);
bool GMQCC_WARN vcompile_warning(lex_ctx ctx, int warntype, const char *fmt, va_list ap); bool GMQCC_WARN vcompile_warning(lex_ctx ctx, int warntype, const char *fmt, va_list ap);
void compile_show_werrors();
/*===================================================================*/ /*===================================================================*/
/*========================= assembler.c =============================*/ /*========================= assembler.c =============================*/

1
opts.c
View file

@ -59,6 +59,7 @@ static void opts_setdefault() {
opts_set(opts.flags, FTEPP, false); opts_set(opts.flags, FTEPP, false);
opts_set(opts.flags, FTEPP_PREDEFS, false); opts_set(opts.flags, FTEPP_PREDEFS, false);
opts_set(opts.flags, CORRECT_TERNARY, true); opts_set(opts.flags, CORRECT_TERNARY, true);
opts_set(opts.flags, BAIL_ON_WERROR, true);
} }
void opts_init(const char *output, int standard, size_t arraysize) { void opts_init(const char *output, int standard, size_t arraysize) {

View file

@ -45,6 +45,7 @@
GMQCC_DEFINE_FLAG(TRUE_EMPTY_STRINGS) GMQCC_DEFINE_FLAG(TRUE_EMPTY_STRINGS)
GMQCC_DEFINE_FLAG(FALSE_EMPTY_STRINGS) GMQCC_DEFINE_FLAG(FALSE_EMPTY_STRINGS)
GMQCC_DEFINE_FLAG(UTF8) GMQCC_DEFINE_FLAG(UTF8)
GMQCC_DEFINE_FLAG(BAIL_ON_WERROR)
#endif #endif
/* warning flags */ /* warning flags */

View file

@ -76,8 +76,6 @@ typedef struct {
size_t *_blocktypedefs; size_t *_blocktypedefs;
lex_ctx *_block_ctx; lex_ctx *_block_ctx;
size_t errors;
/* we store the '=' operator info */ /* we store the '=' operator info */
const oper_info *assign_op; const oper_info *assign_op;
@ -114,11 +112,8 @@ static ast_expression* parse_expression(parser_t *parser, bool stopatcomma);
static void parseerror(parser_t *parser, const char *fmt, ...) static void parseerror(parser_t *parser, const char *fmt, ...)
{ {
va_list ap; va_list ap;
parser->errors++;
va_start(ap, fmt); va_start(ap, fmt);
con_vprintmsg(LVL_ERROR, parser->lex->tok.ctx.file, parser->lex->tok.ctx.line, "parse error", fmt, ap); vcompile_error(parser->lex->tok.ctx, fmt, ap);
va_end(ap); va_end(ap);
} }
@ -992,11 +987,8 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
field->expression.next->expression.vtype == TYPE_FUNCTION && field->expression.next->expression.vtype == TYPE_FUNCTION &&
exprs[1]->expression.vtype == TYPE_FUNCTION) exprs[1]->expression.vtype == TYPE_FUNCTION)
{ {
if (parsewarning(parser, WARN_ASSIGN_FUNCTION_TYPES, (void)!parsewarning(parser, WARN_ASSIGN_FUNCTION_TYPES,
"invalid types in assignment: cannot assign %s to %s", ty2, ty1)) "invalid types in assignment: cannot assign %s to %s", ty2, ty1);
{
parser->errors++;
}
} }
else else
parseerror(parser, "invalid types in assignment: cannot assign %s to %s", ty2, ty1); parseerror(parser, "invalid types in assignment: cannot assign %s to %s", ty2, ty1);
@ -1026,11 +1018,8 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
exprs[0]->expression.vtype == TYPE_FUNCTION && exprs[0]->expression.vtype == TYPE_FUNCTION &&
exprs[1]->expression.vtype == TYPE_FUNCTION) exprs[1]->expression.vtype == TYPE_FUNCTION)
{ {
if (parsewarning(parser, WARN_ASSIGN_FUNCTION_TYPES, (void)!parsewarning(parser, WARN_ASSIGN_FUNCTION_TYPES,
"invalid types in assignment: cannot assign %s to %s", ty2, ty1)) "invalid types in assignment: cannot assign %s to %s", ty2, ty1);
{
parser->errors++;
}
} }
else else
parseerror(parser, "invalid types in assignment: cannot assign %s to %s", ty2, ty1); parseerror(parser, "invalid types in assignment: cannot assign %s to %s", ty2, ty1);
@ -1306,8 +1295,7 @@ static bool parser_close_call(parser_t *parser, shunt *sy)
params->exprs = NULL; params->exprs = NULL;
ast_delete(params); ast_delete(params);
} }
if (!ast_call_check_types(call)) (void)!ast_call_check_types(call);
parser->errors++;
} else { } else {
parseerror(parser, "invalid function call"); parseerror(parser, "invalid function call");
return false; return false;
@ -1873,12 +1861,10 @@ static bool parser_leaveblock(parser_t *parser)
ast_value *v = (ast_value*)e; ast_value *v = (ast_value*)e;
vec_pop(parser->_locals); vec_pop(parser->_locals);
if (ast_istype(e, ast_value) && !v->uses) { if (ast_istype(e, ast_value) && !v->uses) {
if (compile_warning(ast_ctx(v), WARN_UNUSED_VARIABLE, "unused variable: `%s`", v->name)) { if (compile_warning(ast_ctx(v), WARN_UNUSED_VARIABLE, "unused variable: `%s`", v->name))
parser->errors++;
rv = false; rv = false;
} }
} }
}
typedefs = vec_last(parser->_blocktypedefs); typedefs = vec_last(parser->_blocktypedefs);
while (vec_size(parser->_typedefs) != typedefs) { while (vec_size(parser->_typedefs) != typedefs) {
@ -4742,7 +4728,7 @@ bool parser_compile()
if (!parser_global_statement(parser)) { if (!parser_global_statement(parser)) {
if (parser->tok == TOKEN_EOF) if (parser->tok == TOKEN_EOF)
parseerror(parser, "unexpected eof"); parseerror(parser, "unexpected eof");
else if (!parser->errors) else if (compile_errors)
parseerror(parser, "there have been errors, bailing out"); parseerror(parser, "there have been errors, bailing out");
lex_close(parser->lex); lex_close(parser->lex);
parser->lex = NULL; parser->lex = NULL;
@ -4759,7 +4745,7 @@ bool parser_compile()
lex_close(parser->lex); lex_close(parser->lex);
parser->lex = NULL; parser->lex = NULL;
return !parser->errors; return !compile_errors;
} }
bool parser_compile_file(const char *filename) bool parser_compile_file(const char *filename)
@ -4844,8 +4830,11 @@ bool parser_finish(const char *output)
ir_builder *ir; ir_builder *ir;
bool retval = true; bool retval = true;
if (!parser->errors) if (compile_errors) {
{ con_out("*** there were compile errors\n");
return false;
}
ir = ir_builder_new("gmqcc_out"); ir = ir_builder_new("gmqcc_out");
if (!ir) { if (!ir) {
con_out("failed to allocate builder\n"); con_out("failed to allocate builder\n");
@ -4954,6 +4943,12 @@ bool parser_finish(const char *output)
} }
} }
if (compile_Werrors) {
con_out("*** there were warnings treated as errors\n");
compile_show_werrors();
retval = false;
}
if (retval) { if (retval) {
if (opts.dumpfin) if (opts.dumpfin)
ir_builder_dump(ir, con_out); ir_builder_dump(ir, con_out);
@ -4970,7 +4965,3 @@ bool parser_finish(const char *output)
ir_builder_delete(ir); ir_builder_delete(ir);
return retval; return retval;
} }
con_out("*** there were compile errors\n");
return false;
}