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.
This commit is contained in:
Petr Skocik 2018-11-29 10:15:25 +01:00
parent e0012c2767
commit 9d44b02a49
2 changed files with 13 additions and 0 deletions

View File

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

View File

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