@@ -2877,105 +2877,13 @@ def test_legacy_stack_deps(self):
28772877 }''' )
28782878 self .do_runf ('main.c' , cflags = ['--js-library=lib.js' ])
28792879
2880- def test_nestedstructs (self ):
2881- src = r'''
2882- #include <stdio.h>
2883- #include "emscripten.h"
2884-
2885- struct base {
2886- int x;
2887- float y;
2888- union {
2889- int a;
2890- float b;
2891- };
2892- char c;
2893- };
2894-
2895- struct hashtableentry {
2896- int key;
2897- base data;
2898- };
2899-
2900- struct hashset {
2901- typedef hashtableentry entry;
2902- struct chain { entry elem; chain *next; };
2903- // struct chainchunk { chain chains[100]; chainchunk *next; };
2904- };
2905-
2906- struct hashtable : hashset {
2907- hashtable() {
2908- base b;
2909- entry e;
2910- chain c;
2911- printf("*%zu,%ld,%ld,%ld,%ld,%ld|%zu,%ld,%ld,%ld,%ld,%ld,%ld,%ld|%zu,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld*\n",
2912- sizeof(base),
2913- long(&b.x) - long(&b),
2914- long(&b.y) - long(&b),
2915- long(&b.a) - long(&b),
2916- long(&b.b) - long(&b),
2917- long(&b.c) - long(&b),
2918- sizeof(hashtableentry),
2919- long(&e.key) - long(&e),
2920- long(&e.data) - long(&e),
2921- long(&e.data.x) - long(&e),
2922- long(&e.data.y) - long(&e),
2923- long(&e.data.a) - long(&e),
2924- long(&e.data.b) - long(&e),
2925- long(&e.data.c) - long(&e),
2926- sizeof(hashset::chain),
2927- long(&c.elem) - long(&c),
2928- long(&c.next) - long(&c),
2929- long(&c.elem.key) - long(&c),
2930- long(&c.elem.data) - long(&c),
2931- long(&c.elem.data.x) - long(&c),
2932- long(&c.elem.data.y) - long(&c),
2933- long(&c.elem.data.a) - long(&c),
2934- long(&c.elem.data.b) - long(&c),
2935- long(&c.elem.data.c) - long(&c)
2936- );
2937- }
2938- };
2939-
2940- struct B { char buffer[62]; int last; char laster; char laster2; };
2941-
2942- struct Bits {
2943- unsigned short A : 1;
2944- unsigned short B : 1;
2945- unsigned short C : 1;
2946- unsigned short D : 1;
2947- unsigned short x1 : 1;
2948- unsigned short x2 : 1;
2949- unsigned short x3 : 1;
2950- unsigned short x4 : 1;
2951- };
2952-
2953- int main() {
2954- hashtable t;
2955-
2956- // Part 2 - the char[] should be compressed, BUT have a padding space at the end so the next
2957- // one is aligned properly. Also handle char; char; etc. properly.
2958- B b;
2959- printf("*%ld,%ld,%ld,%ld,%ld,%ld,%ld,%zu*\n", long(&b.buffer) - long(&b),
2960- long(&b.buffer[0]) - long(&b),
2961- long(&b.buffer[1]) - long(&b),
2962- long(&b.buffer[2]) - long(&b),
2963- long(&b.last) - long(&b),
2964- long(&b.laster) - long(&b),
2965- long(&b.laster2) - long(&b),
2966- sizeof(B));
2967-
2968- // Part 3 - bitfields, and small structures
2969- printf("*%zu*\n", sizeof(Bits));
2970- return 0;
2971- }
2972- '''
2880+ def test_nested_structs (self ):
29732881 # Bloated memory; same layout as C/C++
29742882 if self .is_wasm64 ():
29752883 expected = '*16,0,4,8,8,12|20,0,4,4,8,12,12,16|32,0,24,0,4,4,8,12,12,16*\n *0,0,1,2,64,68,69,72*\n *2*'
29762884 else :
29772885 expected = '*16,0,4,8,8,12|20,0,4,4,8,12,12,16|24,0,20,0,4,4,8,12,12,16*\n *0,0,1,2,64,68,69,72*\n *2*'
2978- self .do_run ( src , expected )
2886+ self .do_runf ( 'core/test_nested_structs.cpp' , expected )
29792887
29802888 def prep_dlfcn_main (self , libs = None ):
29812889 if libs is None :
0 commit comments