// Some tests for C-- // Written by Laurent Prosperi, ENS Cachan, in 2015. #ifndef MCC #include #include #endif #define NULL 0 int global_3; int global_4; int* global_5; int* global_6; int test_expr(){ int i,j,k,l; int e1,e2,e3,e4,e5,e6,e7,e8,e9; int* tab; int l1, l2; int a, b; a=587; b=-158; i=156; j=129; k=11; l=-1; e1=-(i*j+k-l+2+10/2); e2=-5*(i+j+k-l)*(l*5+3)+(k/11); e3=(e1*e2+l-k+8)*7-6; e4 = e2-(e2++); e5 = e3-(e3--); e6 = (++i)-(--i); e9 = (i++)-(i--); e7 = ~k; e8 = e1 % ( l+k ); tab = malloc( 8*8); tab[0]=e1; tab[1]=e2; tab[4]= (tab[0]+e3-tab[1]*5) + tab[0] % 3; tab[6]= 1; tab[5]= ~(tab[4]*tab[6]); tab[7]= (5*tab[0] + (tab[3] = e3)); l1 = ((0 == 0) < 56 ) <= e8; l2 = 4 == (((e2 == e1) < e4 ) <= e8); j= ((a+b)<5) ? (l1+l2+e6+e7+e3+e2) : (l1*l2+(e6-1)*e7*e3-e2); ///e6-1 compence la différence entre gcc et mcc k= ((a+b)<5) ? (l1+l2-e6*e7+e3+e2) : (l1*l2+(e6-1)*e7*e3-e2-9*e4+e5); global_1 = j+k*2; printf("global_1 = %d\n", global_1); printf("e1 %s\n", (-20143==e1) ? "pass" : "failed"); printf("e1 th=%d, value=%d\n", -20143, e1); printf("----------------------\n"); printf("e2 %s\n", (2972==e2) ? "pass" : "failed"); printf("e2 th=%d, value=%d\n", 2972, e2); printf("----------------------\n"); printf("e3 %s\n", (-418914006==e3) ? "pass" : "failed"); printf("e3 th=%d, value=%d\n", -418914006, e3); printf("----------------------\n"); printf("e4 %s\n", (1==e4) ? "pass" : "failed"); printf("e4 th=%d, value=%d\n", 1, e4); printf("----------------------\n"); printf("e5 %s\n", (-1==e5) ? "pass" : "failed"); printf("e5 th=%d, value=%d\n", -1, e5); printf("----------------------\n"); printf("e6 %s\n", (1==e6) ? "pass" : "failed"); ///D'après gcc ça fait 0, sémantique c-- => 1 printf("e6 th=%d, value=%d\n", 1, e6); printf("----------------------\n"); printf("e7 %s\n", (-12==e7) ? "pass" : "failed"); printf("e7 th=%d, value=%d\n", -12, e7); printf("----------------------\n"); printf("e8 %s\n", (-3==e8) ? "pass" : "failed"); printf("e8 th=%d, value=%d\n", -3, e8); printf("----------------------\n"); printf("e9 %s\n", (-1==e9) ? "pass" : "failed"); printf("e9 th=%d, value=%d\n", -1, e9); printf("----------------------\n"); printf("tab[0] %s\n", (-20143==tab[0]) ? "pass" : "failed"); printf("tab[0] th=%d, value=%d\n", -20143, tab[0]); printf("----------------------\n"); printf("tab[1] %s\n", (2972==tab[1]) ? "pass" : "failed"); printf("tab[1] th=%d, value=%d\n", 2972, tab[1]); printf("----------------------\n"); printf("tab[2] %s\n", (0==tab[2]) ? "pass" : "failed"); printf("tab[2] th=%d, value=%d\n", 0, tab[2]); printf("----------------------\n"); printf("tab[3] %s\n", (-418914006==tab[3]) ? "pass" : "failed"); printf("tab[3] th=%d, value=%d\n", -418914006, tab[3]); printf("----------------------\n"); printf("tab[4] %s\n", (-418949010==tab[4]) ? "pass" : "failed"); printf("tab[4] th=%d, value=%d\n", -418949010, tab[4]); printf("----------------------\n"); printf("tab[5] %s\n", (418949009==tab[5]) ? "pass" : "failed"); printf("tab[5] th=%d, value=%d\n", 418949009, tab[5]); printf("----------------------\n"); printf("tab[7] %s\n", (-419014721==tab[7]) ? "pass" : "failed"); printf("tab[7] th=%d, value=%d\n", -419014721, tab[7]); printf("----------------------\n"); printf("l1 %s\n", (0==l1) ? "pass" : "failed"); printf("l1 th=%d, value=%d\n", 0, l1); printf("----------------------\n"); printf("l2 %s\n", (0==l2) ? "pass" : "failed"); printf("l2 th=%d, value=%d\n", 0, l2); printf("----------------------\n"); printf("j %s\n", (-2972==j) ? "pass" : "failed"); printf("j th=%d, value=%d\n", -2972, j); printf("----------------------\n"); printf("k %s\n", (-2982==k) ? "pass" : "failed"); printf("k th=%d, value=%d\n", -2982, k); printf("----------------------\n"); free( tab ); return 56; } int test_code(){ int i,j,k,l; int a,b,c,d; int x,y,z; a=0; b=0; c=0; d=0; i=156; j=129; k=11; l=-1; printf("global_1 = %d\n", global_1); global_2 = i+k-1; printf("global_1 = %d\n", global_1); global_1--; printf("global_1 = %d\n", global_1); if( (i+j-3)<10 ){ x=50; while(0