From 7ae35bf1bb21858c369ab09f5562ecd30847f669 Mon Sep 17 00:00:00 2001 From: Michael Matz Date: Mon, 17 Oct 2016 20:50:54 +0200 Subject: [PATCH] Handle multiple -O options the last one wins, i.e. "-O2 -O0" does _not_ set __OPTIMIZ__. --- libtcc.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/libtcc.c b/libtcc.c index 58dddb9e..68c3f9d0 100644 --- a/libtcc.c +++ b/libtcc.c @@ -1657,6 +1657,7 @@ PUB_FUNC int tcc_parse_args(TCCState *s, int argc, char **argv) int optind = 0; int run = 0; int x; + int last_o = -1; CString linker_arg; /* collect -Wl options */ char buf[1024]; @@ -1887,9 +1888,7 @@ reparse: tcc_warning("unsupported language '%s'", optarg); break; case TCC_OPTION_O: - x = atoi(optarg); - if (x > 0) - tcc_define_symbol(s, "__OPTIMIZE__", NULL); + last_o = atoi(optarg); break; case TCC_OPTION_mms_bitfields: s->ms_bitfields = 1; @@ -1908,6 +1907,9 @@ unsupported_option: } } + if (last_o > 0) + tcc_define_symbol(s, "__OPTIMIZE__", NULL); + if (linker_arg.size) { r = linker_arg.data; goto arg_err;