I would try with ASAN and probably also UBSAN first (see https://emscripten.org/docs/debugging/Sanitizers.html), and see if they trigger somewhere. I'd guess that some unrelated code goes haywire and overwrites the memory locations where _x and _y are stored with garbage. Strange that this doesn't happen with tmp, but maybe since tmp is also a static variable it might change the layout of the static variable storage area in a way that the memory corruption plays out differently.
Are you able to compile and test the code natively? Memory corruption problems are sometimes easier to debug there. On Wednesday, 11 November 2020 at 00:12:11 UTC+1 [email protected] wrote: > I just refactored some old C code of mine. Surprisingly the updated code > failed in a very unexpected manner that I still don't understand. I > narrowed the problem down and here is what the relevant code looks like: > > static uint8_t _x, _y; // ... _x and _y get both initialized and updated > elsewhere > void setOutput(uint8_t val) { ...}void someFunction() { > static uint8_t tmp; > ... > swich(..) { > case foo: { > // tmp = _x & _y; > setOutput( _x & _y); > } > ... > } > } > > The code fails because the _x & _y expression suddenly passes total > garbage > to the setOutput() function. Originally I had used the commented tmp > assignment > and then used tmp as an argument for that call - and that functions > correctly. > > However what I find most puzzling is this: simply uncommenting the "tmp" > assignment - without even using tmp later) makes the problem > disappear...WTF?! > > I am still using an older Emscripten version 1.38 and the effect is there > regardless if I compile to WASM or asm.js and whether or not I am using > different optimizer options or the closure compiler. > > Any ideas what is going on here? Is this some kind of known bug or some C > feature that I am not aware of.. > -- You received this message because you are subscribed to the Google Groups "emscripten-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/899b5d75-fac2-4770-bf17-5ed573d77eaen%40googlegroups.com.
