From d57f872513dfd6ebded001e6b1f2a72a88ee03d5 Mon Sep 17 00:00:00 2001 From: Petr Skocik Date: Fri, 16 Mar 2018 00:26:16 +0100 Subject: [PATCH 2/4] patch type_to_str to handle complex function-ptr decls better Code like: #include int main() { _Generic(signal, int: 0); } should fail with error: type 'extern void (*(int, void (*)(int)))(int)' does not match any association not error: type 'extern void *(int)(int, void *(int))' does not match any association --- tccgen.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/tccgen.c b/tccgen.c index 5265e49..08cc5ec 100644 --- a/tccgen.c +++ b/tccgen.c @@ -19,7 +19,6 @@ */ #include "tcc.h" - /********************************************************/ /* global variables */ @@ -2934,17 +2933,26 @@ static void type_to_str(char *buf, int buf_size, break; case VT_FUNC: s = type->ref; - type_to_str(buf, buf_size, &s->type, varstr); - pstrcat(buf, buf_size, "("); + buf1[0]=0; + if(varstr&&*varstr&&'*'==*varstr){ + pstrcat(buf1, sizeof(buf1), "("); + pstrcat(buf1, sizeof(buf1), varstr); + pstrcat(buf1, sizeof(buf1), ")"); + } + pstrcat(buf1, buf_size, "("); sa = s->next; while (sa != NULL) { - type_to_str(buf1, sizeof(buf1), &sa->type, NULL); - pstrcat(buf, buf_size, buf1); + char buf2[256]; + type_to_str(buf2, sizeof(buf2), &sa->type, NULL); + pstrcat(buf1, sizeof(buf1), buf2); sa = sa->next; if (sa) - pstrcat(buf, buf_size, ", "); + pstrcat(buf1, sizeof(buf1), ", "); } - pstrcat(buf, buf_size, ")"); + if(s->f.func_type == FUNC_ELLIPSIS) + pstrcat(buf1, sizeof(buf1), ", ..."); + pstrcat(buf1, sizeof(buf1), ")"); + type_to_str(buf, buf_size, &s->type, buf1); goto no_var; case VT_PTR: s = type->ref; -- 2.15.1