| 775 | |
| 776 | @only_wasm2js('tests signed vs unsigned values') |
| 777 | def test_unsigned(self): |
| 778 | src = ''' |
| 779 | #include <stdio.h> |
| 780 | const signed char cvals[2] = { -1, -2 }; // compiler can store this as a string, so -1 becomes \\FF, and needs re-signing |
| 781 | int main() |
| 782 | { |
| 783 | { |
| 784 | unsigned char x = 200; |
| 785 | printf("*%d*\\n", x); |
| 786 | unsigned char y = -22; |
| 787 | printf("*%d*\\n", y); |
| 788 | } |
| 789 | |
| 790 | int varey = 100; |
| 791 | unsigned int MAXEY = -1, MAXEY2 = -77; |
| 792 | printf("*%u,%d,%u*\\n", MAXEY, varey >= MAXEY, MAXEY2); // 100 >= -1? not in unsigned! |
| 793 | |
| 794 | int y = cvals[0]; |
| 795 | printf("*%d,%d,%d,%d*\\n", cvals[0], cvals[0] < 0, y, y < 0); |
| 796 | y = cvals[1]; |
| 797 | printf("*%d,%d,%d,%d*\\n", cvals[1], cvals[1] < 0, y, y < 0); |
| 798 | |
| 799 | // zext issue - see mathop in jsifier |
| 800 | unsigned char x8 = -10; |
| 801 | unsigned long hold = 0; |
| 802 | hold += x8; |
| 803 | int y32 = hold+50; |
| 804 | printf("*%lu,%d*\\n", hold, y32); |
| 805 | |
| 806 | // Comparisons |
| 807 | x8 = 0; |
| 808 | for (int i = 0; i < 254; i++) x8++; // make it an actual 254 in JS - not a -2 |
| 809 | printf("*%d,%d*\\n", x8+1 == 0xff, x8+1 != 0xff); // 0xff may be '-1' in the bitcode |
| 810 | |
| 811 | return 0; |
| 812 | } |
| 813 | ''' |
| 814 | self.do_run(src, '*4294967295,0,4294967219*\n*-1,1,-1,1*\n*-2,1,-2,1*\n*246,296*\n*1,0*') |
| 815 | |
| 816 | src = ''' |
| 817 | #include <stdio.h> |
| 818 | int main() |
| 819 | { |
| 820 | { |
| 821 | unsigned char x; |
| 822 | unsigned char *y = &x; |
| 823 | *y = -1; |
| 824 | printf("*%d*\\n", x); |
| 825 | } |
| 826 | { |
| 827 | unsigned short x; |
| 828 | unsigned short *y = &x; |
| 829 | *y = -1; |
| 830 | printf("*%d*\\n", x); |
| 831 | } |
| 832 | /*{ // This case is not checked. The hint for unsignedness is just the %u in printf, and we do not analyze that |
| 833 | unsigned int x; |
| 834 | unsigned int *y = &x; |