From b3bebdb20a8910597955f849791f578d42ef178e Mon Sep 17 00:00:00 2001 From: Detlef Riekenberg Date: Sun, 10 Apr 2022 00:55:11 +0200 Subject: [PATCH] libtcc: Allow more values for the -std= option With this code, we can compile more projects, who expect gcc or clang as compiler. (-std=gnu11 used in Makefiles) As a further extension, it would be easy to disable gcc extensions Signed-off-by: Detlef Riekenberg --- libtcc.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/libtcc.c b/libtcc.c index b6dbb013..5fb793e0 100644 --- a/libtcc.c +++ b/libtcc.c @@ -1565,6 +1565,23 @@ static const TCCOption tcc_options[] = { { NULL, 0, 0 }, }; +typedef struct stdvalue { + uint32_t cversion; + const char * name; +} stdvalue; + +/* accepted values for the -std= option */ +static const stdvalue std_values[] = { + { 199901, "c99" }, + { 201112, "c11" }, + { 201710, "c17" }, + { 202000, "c2x" }, + { 199901, "gnu99" }, + { 201112, "gnu11" }, + { 201710, "gnu17" }, + { 202000, "gnu2x" } +}; + typedef struct FlagDef { uint16_t offset; uint16_t flags; @@ -1835,8 +1852,21 @@ reparse: s->static_link = 1; break; case TCC_OPTION_std: - if (strcmp(optarg, "=c11") == 0) - s->cversion = 201112; + x = 0; + if (*optarg == '=') { + do { + if (strcmp(std_values[x].name, &optarg[1]) == 0) { + x = std_values[x].cversion; + } + else + ++x; + } while (x < (sizeof(std_values)/sizeof(stdvalue))); + } + if (x > (sizeof(std_values)/sizeof(stdvalue))) + s->cversion = x; + else + goto unsupported_option; + break; case TCC_OPTION_shared: x = TCC_OUTPUT_DLL;