Add usual arithmetic conversion for function pointer

This commit is contained in:
Rui Ueyama 2020-09-02 20:11:28 +09:00
parent c5953ba132
commit 53e81033ce
2 changed files with 9 additions and 0 deletions

View File

@ -1,5 +1,7 @@
#include "test.h"
static int ret10(void) { return 10; }
int main() {
ASSERT((long)-5, -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(5, ({ struct t {char a;} x, y; x.a=5; y=x; y.a; }));
ASSERT(10, (1 ? ret10 : (void *)0)());
printf("OK\n");
return 0;
}

5
type.c
View File

@ -77,6 +77,11 @@ static Type *get_common_type(Type *ty1, Type *ty2) {
if (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)
return ty_double;
if (ty1->kind == TY_FLOAT || ty2->kind == TY_FLOAT)