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 <wine.dev@web.de>
This commit is contained in:
Detlef Riekenberg 2022-04-10 00:55:11 +02:00
parent 8759b2581d
commit b3bebdb20a

View file

@ -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;