From 9d44b02a492ddbe3f68ec950cda8b3ca3871f163 Mon Sep 17 00:00:00 2001 From: Petr Skocik Date: Thu, 29 Nov 2018 10:15:25 +0100 Subject: [PATCH] Fix the fix on type combining (e0012c2) char **argv; _Generic(argv, char**: (void)0); _Generic(0?(char const*)0:argv[0], char const*: (void)0); _Generic(argv, char**: (void)0); would fail because the type of argv would get modified by the ternary. Now allocate a separate type on the value stack to prevent this error. --- tccgen.c | 6 ++++++ tests/tests2/94_generic.c | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/tccgen.c b/tccgen.c index 404ed7e1..cccd88b4 100644 --- a/tccgen.c +++ b/tccgen.c @@ -5627,6 +5627,12 @@ static void expr_cond(void) if(!compare_types(pointed_type(&type1), pointed_type(&type2),1/*unqualif*/)) tcc_warning("pointer type mismatch in conditional expression\n"); } + { /*copy the pointer target symbol*/ + Sym *s; + s = sym_push(SYM_FIELD, pointed_type(&type), 0, -1); + type.t = VT_PTR | (type.t & VT_STORAGE); + type.ref = s; + } /*qualifs combine*/ pointed_type(&type)->t |= 0 |(pointed_type(&type1)->t&(VT_CONSTANT|VT_VOLATILE)) diff --git a/tests/tests2/94_generic.c b/tests/tests2/94_generic.c index 5f857670..ac366503 100644 --- a/tests/tests2/94_generic.c +++ b/tests/tests2/94_generic.c @@ -95,5 +95,12 @@ int main() (void)(sizeof(struct { int x:_Generic( 0?(int (*)[4])0 : (int (*)[])0, int (*)[4]:+1, int (*)[5]:(void)0); })); (void)(sizeof(struct { int x:_Generic( 0?(int (*)[])0 : (int (*)[4])0, int (*)[4]:+1, int (*)[5]:(void)0); })); + { + char **argv; + _Generic(argv, char**: (void)0); + _Generic(0?(char const*)0:argv[0], char const*: (void)0); + _Generic(argv, char**: (void)0); + } + return 0; }