mirror of https://github.com/rui314/chibicc
Add usual arithmetic conversion for function pointer
This commit is contained in:
parent
c5953ba132
commit
53e81033ce
|
@ -1,5 +1,7 @@
|
||||||
#include "test.h"
|
#include "test.h"
|
||||||
|
|
||||||
|
static int ret10(void) { return 10; }
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
ASSERT((long)-5, -10 + (long)5);
|
ASSERT((long)-5, -10 + (long)5);
|
||||||
ASSERT((long)-15, -10 - (long)5);
|
ASSERT((long)-15, -10 - (long)5);
|
||||||
|
@ -23,6 +25,8 @@ int main() {
|
||||||
ASSERT(0, ({ char x[3]; x[0]=0; x[1]=1; x[2]=2; char *y=x+1; y[-1]; }));
|
ASSERT(0, ({ char x[3]; x[0]=0; x[1]=1; x[2]=2; char *y=x+1; y[-1]; }));
|
||||||
ASSERT(5, ({ struct t {char a;} x, y; x.a=5; y=x; y.a; }));
|
ASSERT(5, ({ struct t {char a;} x, y; x.a=5; y=x; y.a; }));
|
||||||
|
|
||||||
|
ASSERT(10, (1 ? ret10 : (void *)0)());
|
||||||
|
|
||||||
printf("OK\n");
|
printf("OK\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
5
type.c
5
type.c
|
@ -77,6 +77,11 @@ static Type *get_common_type(Type *ty1, Type *ty2) {
|
||||||
if (ty1->base)
|
if (ty1->base)
|
||||||
return pointer_to(ty1->base);
|
return pointer_to(ty1->base);
|
||||||
|
|
||||||
|
if (ty1->kind == TY_FUNC)
|
||||||
|
return pointer_to(ty1);
|
||||||
|
if (ty2->kind == TY_FUNC)
|
||||||
|
return pointer_to(ty2);
|
||||||
|
|
||||||
if (ty1->kind == TY_DOUBLE || ty2->kind == TY_DOUBLE)
|
if (ty1->kind == TY_DOUBLE || ty2->kind == TY_DOUBLE)
|
||||||
return ty_double;
|
return ty_double;
|
||||||
if (ty1->kind == TY_FLOAT || ty2->kind == TY_FLOAT)
|
if (ty1->kind == TY_FLOAT || ty2->kind == TY_FLOAT)
|
||||||
|
|
Loading…
Reference in New Issue