| 726 | |
| 727 | @only_wasm2js('tests 64-bit alignment of structs') |
| 728 | def test_align64(self): |
| 729 | src = r''' |
| 730 | #include <stdio.h> |
| 731 | |
| 732 | // inspired by poppler |
| 733 | |
| 734 | enum Type { |
| 735 | A = 10, |
| 736 | B = 20 |
| 737 | }; |
| 738 | |
| 739 | struct Object { |
| 740 | Type type; |
| 741 | union { |
| 742 | int intg; |
| 743 | double real; |
| 744 | char *name; |
| 745 | }; |
| 746 | }; |
| 747 | |
| 748 | struct Principal { |
| 749 | double x; |
| 750 | Object a; |
| 751 | double y; |
| 752 | }; |
| 753 | |
| 754 | int main(int argc, char **argv) { |
| 755 | int base = argc-1; |
| 756 | Object o[10]; |
| 757 | printf("%zu,%zu\n", sizeof(Object), sizeof(Principal)); |
| 758 | printf("%ld,%ld,%ld,%ld\n", (long)&o[base].type - (long)o, (long)&o[base].intg - (long)o, (long)&o[base].real - (long)o, (long)&o[base].name - (long)o); |
| 759 | printf("%ld,%ld,%ld,%ld\n", (long)&o[base+1].type - (long)o, (long)&o[base+1].intg - (long)o, (long)&o[base+1].real - (long)o, (long)&o[base+1].name - (long)o); |
| 760 | Principal p, q; |
| 761 | p.x = p.y = q.x = q.y = 0; |
| 762 | p.a.type = A; |
| 763 | p.a.real = 123.456; |
| 764 | *(&q.a) = p.a; |
| 765 | printf("%.2f,%d,%.2f,%.2f : %.2f,%d,%.2f,%.2f\n", p.x, p.a.type, p.a.real, p.y, q.x, q.a.type, q.a.real, q.y); |
| 766 | return 0; |
| 767 | } |
| 768 | ''' |
| 769 | |
| 770 | self.do_run(src, '''16,32 |
| 771 | 0,8,8,8 |
| 772 | 16,24,24,24 |
| 773 | 0.00,10,123.46,0.00 : 0.00,10,123.46,0.00 |
| 774 | ''') |
| 775 | |
| 776 | @only_wasm2js('tests signed vs unsigned values') |
| 777 | def test_unsigned(self): |