tccgen: gen_cast(): detect 'cast from void' error

This commit is contained in:
grischka 2021-01-26 22:25:53 +01:00
parent 72f1dea537
commit 97800177c9
3 changed files with 17 additions and 5 deletions

View File

@ -3695,6 +3695,12 @@ again:
df = is_float(dbt);
dbt_bt = dbt & VT_BTYPE;
sbt_bt = sbt & VT_BTYPE;
if (dbt_bt == VT_VOID)
goto done;
if (sbt_bt == VT_VOID) {
error:
cast_error(&vtop->type, type);
}
c = (vtop->r & (VT_VALMASK | VT_LVAL | VT_SYM)) == VT_CONST;
#if !defined TCC_IS_NATIVE && !defined TCC_IS_NATIVE_387
@ -3791,11 +3797,9 @@ again:
ds = btype_size(dbt_bt);
ss = btype_size(sbt_bt);
if (ds == 0 || ss == 0) {
if (dbt_bt == VT_VOID)
goto done;
cast_error(&vtop->type, type);
}
if (ds == 0 || ss == 0)
goto error;
if (IS_ENUM(type->t) && type->ref->c < 0)
tcc_error("cast to incomplete type");

View File

@ -394,4 +394,9 @@ struct S2 {
#elif defined test_conflicting_array_definition
extern int array[2];
int array[] = { 1, 2, 3 };
#elif defined test_cast_from_void
void v() {}
int f() { return v(); }
#endif

View File

@ -186,3 +186,6 @@ bar : 3 ; 3
[test_conflicting_array_definition]
60_errors_and_warnings.c:396: error: incompatible types for redefinition of 'array'
[test_cast_from_void]
60_errors_and_warnings.c:400: error: cannot convert 'void' to 'int'