emscripten icon indicating copy to clipboard operation
emscripten copied to clipboard

Windows: Problem with passing arguments by value

Open SigmundVik opened this issue 15 years ago • 2 comments

Running Emscripten with llvm 2.9 on my Windows system, test_raytrace fails with this output in src.cpp.o.js:

analyzer.js:285: TypeError: Cannot read property 'derivedTypes' of undefined
              if (!func.variables[item.value.ident].derivedTypes) {
                                                   ^

The problem seems to be related to Emscripten not understanding this llvm function signature:

define internal %struct.node_t* @_Z6createP6node_tii3v_tS1_d(%struct.node_t* %n, i32 %lvl, i32 %dist, %struct.v_t* byval align 4, %struct.v_t* byval align 4, double %r)

The complete llvm output can be found here (please note that I had to change iostream usage with printfs to make it compile): http://pastebin.com/7s7vV5xJ

If I pass the v_t structs by const reference instead of by value in the create() function the test passes. In this case the llvm function signature looks like this:

define internal %struct.node_t* @_Z6createP6node_tiiRK3v_tS3_d(%struct.node_t* %n, i32 %lvl, i32 %dist, %struct.v_t* %c, %struct.v_t* %d, double %r)

If I insert these lines before line 285 in analyzer.js:

print(JSON.stringify(item.value.ident));
print(JSON.stringify(func.variables));

I get that item.value.ident is "$0", and then there is this oddly looking entry in func.variables:

"4":{"ident":"4","type":"%struct.v_t*byvalalign","origin":"funcparam","lineNum":216,"uses":null}

I'm guessing the "4" here comes from the parameter declaration:

%struct.v_t* byval align 4

SigmundVik avatar May 06 '11 09:05 SigmundVik

This should be fixed by commit 123385f37719cd10b5dc. SiggyBar, can you please verify?

kripken avatar May 10 '11 14:05 kripken

Yes, commit 123385f37719cd10b5dc fixed this, thanks! Closing. (Urk, hit "Comment" instead of "Comment & Close", trying again!)

SigmundVik avatar May 10 '11 19:05 SigmundVik