kripken/emscripten — Issue #108: Runtime errors usind std::vector
Author: Edrom01
Created: 2011-10-28 12:39:06+00:00
State: open

Hi, I have strange runtime results when using std::vector.

My code is simple:

```
struct S {
int a;
float b;
};

void foo(int a, float b)
{
}

int main ( int argc, char *argv[] )
{
std::vector ar;
S s;

s.a = 123;
s.b = 123.456f;
ar.push_back(s);

s.a = 0;
s.b = 100.1f;
ar.push_back(s);

foo(ar[0].a, ar[0].b);
foo(ar[1].a, ar[1].b);
}
```

In javascript, the vars in the foo function will display wrong values:

123 and 0.

then 0 and 0.

Maybe some useful info, the method vertor::push_back generate a JS code using llvm_uadd_with_overflow_i32() function.
This function is not translated by emscripten, i have to write it myself like this:

```
create_uadd: function(r) {
this.f0 = r;
this.f1 = 0;
},

llvm_uadd_with_overflow_i32__deps: ['create_uadd'],
llvm_uadd_with_overflow_i32: function(p1, p2) {
return new _create_uadd(p1+p2);
},
```