mirror of
https://github.com/frida/tinycc
synced 2025-01-01 17:44:26 +03:00
Fix function to pointer conversion
This snippet is valid: void foo(void); ... foo + 42 ... the function designator is converted to pointer to function implicitely. gen_op didn't do that and bailed out.
This commit is contained in:
parent
e034853b38
commit
662338f116
13
tccgen.c
13
tccgen.c
@ -1926,6 +1926,7 @@ ST_FUNC void gen_op(int op)
|
||||
int u, t1, t2, bt1, bt2, t;
|
||||
CType type1;
|
||||
|
||||
redo:
|
||||
t1 = vtop[-1].type.t;
|
||||
t2 = vtop[0].type.t;
|
||||
bt1 = t1 & VT_BTYPE;
|
||||
@ -1933,6 +1934,18 @@ ST_FUNC void gen_op(int op)
|
||||
|
||||
if (bt1 == VT_STRUCT || bt2 == VT_STRUCT) {
|
||||
tcc_error("operation on a struct");
|
||||
} else if (bt1 == VT_FUNC || bt2 == VT_FUNC) {
|
||||
if (bt2 == VT_FUNC) {
|
||||
mk_pointer(&vtop->type);
|
||||
gaddrof();
|
||||
}
|
||||
if (bt1 == VT_FUNC) {
|
||||
vswap();
|
||||
mk_pointer(&vtop->type);
|
||||
gaddrof();
|
||||
vswap();
|
||||
}
|
||||
goto redo;
|
||||
} else if (bt1 == VT_PTR || bt2 == VT_PTR) {
|
||||
/* at least one operand is a pointer */
|
||||
/* relationnal op: must be both pointers */
|
||||
|
@ -1847,6 +1847,7 @@ void funcptr_test()
|
||||
int dummy;
|
||||
void (*func)(int);
|
||||
} st1;
|
||||
long diff;
|
||||
|
||||
printf("funcptr:\n");
|
||||
func = #
|
||||
@ -1862,6 +1863,12 @@ void funcptr_test()
|
||||
printf("sizeof2 = %d\n", sizeof funcptr_test);
|
||||
printf("sizeof3 = %d\n", sizeof(&funcptr_test));
|
||||
printf("sizeof4 = %d\n", sizeof &funcptr_test);
|
||||
a = 0;
|
||||
func = num + a;
|
||||
diff = func - num;
|
||||
func(42);
|
||||
(func + diff)(42);
|
||||
(num + a)(43);
|
||||
}
|
||||
|
||||
void lloptest(long long a, long long b)
|
||||
|
Loading…
Reference in New Issue
Block a user