From fdc18d307aafce6e8833b0eb26c1313da88cfc9a Mon Sep 17 00:00:00 2001 From: matthias Date: Mon, 10 Jul 2017 17:44:53 +0200 Subject: mutiples fix for _Generic * check that _Generic don't match unsigned char * with char * this case is usefull as with -funsigned-char, 'char *' are unsigned * change VT_LONG so it's now a qualifier VT_LONG are never use for code generation, but only durring parsing state, in _Generic we need to be able to make diference between 'long' and 'long long' So VT_LONG is now use as a type qualifier, it's old behaviour is still here, but we can keep trace of what was a long and what wasn't * add TOK_CLONG and TOK_CULONG tcc was directly converting value like '7171L' into TOK_CLLONG or TOK_CINT depending of the machine architecture. because of that, we was unable to make diference between a long and a long long, which doesn't work with _Generic. So now 7171L is a TOK_CLONG, and we can handle _Generic properly * check that _Generic can make diference between long and long long * uncomment "type match twice" as it should now pass tests on any platforms * add inside_generic global the point of this variable is to use VT_LONG in comparaison only when we are evaluating a _Generic. problem is with my lastest patchs tcc can now make the diference between a 'long long' and a 'long', but in 64 bit stddef.h typedef uint64_t as typedef signed long long int int64_t and stdint.h as unsigned long int, so tcc break when stdint.h and stddef.h are include together. Another solution woud be to modifie include/stddef.h so it define uint64_t as unsigned long int when processor is 64 bit, but this could break some legacy code, so for now, VT_LONG are use only inside generc. * check that _Generic parse first argument correctly * check that _Generic evaluate correctly exresion like "f() / 2" --- tests/tests2/94_generic.c | 16 +++++++++++++--- tests/tests2/94_generic.expect | 5 ++++- 2 files changed, 17 insertions(+), 4 deletions(-) (limited to 'tests/tests2') diff --git a/tests/tests2/94_generic.c b/tests/tests2/94_generic.c index fad028b..4f989f0 100644 --- a/tests/tests2/94_generic.c +++ b/tests/tests2/94_generic.c @@ -20,6 +20,8 @@ int b_f() return 10; } +typedef int int_type1; + #define gen_sw(a) _Generic(a, const char *: 1, default: 8, int: 123); int main() @@ -28,24 +30,32 @@ int main() struct b titi; const int * const ptr; const char *ti; + int_type1 i2; i = _Generic(a, int: a_f, const int: b_f)(); printf("%d\n", i); + i = _Generic(a, int: a_f() / 2, const int: b_f() / 2); + printf("%d\n", i); i = _Generic(ptr, int *:1, int * const:2, default:20); printf("%d\n", i); i = gen_sw(a); printf("%d\n", i); i = _Generic(titi, struct a:1, struct b:2, default:20); printf("%d\n", i); + i = _Generic(i2, char: 1, int : 0); + printf("%d\n", i); i = _Generic(a, char:1, int[4]:2, default:5); printf("%d\n", i); i = _Generic(17, int :1, int **:2); printf("%d\n", i); - i = _Generic(17L, int :1, long :2); + i = _Generic(17L, int :1, long :2, long long : 3); printf("%d\n", i); - i = _Generic("17, io", const char *:1, char *:3, const int :2); + i = _Generic("17, io", char *: 3, const char *: 1); printf("%d\n", i); - i = _Generic(ti, const char *:1, char *:3, const int :2); + i = _Generic(ti, const unsigned char *:1, const char *:4, char *:3, + const signed char *:2); printf("%d\n", i); + printf("%s\n", _Generic(i + 2L, long: "long", int: "int", + long long: "long long")); return 0; } diff --git a/tests/tests2/94_generic.expect b/tests/tests2/94_generic.expect index 254a84e..b75a7d1 100644 --- a/tests/tests2/94_generic.expect +++ b/tests/tests2/94_generic.expect @@ -1,9 +1,12 @@ 20 +10 20 123 2 +0 5 1 2 3 -1 +4 +long -- cgit v1.3.1