diff options
-rw-r--r-- | src/analyzer.js | 3 | ||||
-rwxr-xr-x | tests/runner.py | 47 |
2 files changed, 50 insertions, 0 deletions
diff --git a/src/analyzer.js b/src/analyzer.js index 1c53b76c..adc615fb 100644 --- a/src/analyzer.js +++ b/src/analyzer.js @@ -223,6 +223,9 @@ function analyzer(data, sidePass) { for (var i = 0; i < item.params.length; i++) { if (item.params[i].type == 'i64') item.params[i].type = 'i32'; } + } else if (item.intertype == 'inttoptr') { + var input = item.params[0]; + if (input.type == 'i64') input.type = 'i32'; // inttoptr can only care about 32 bits anyhow since pointers are 32-bit } if (isIllegalType(item.valueType) || isIllegalType(item.type)) { isIllegal = true; diff --git a/tests/runner.py b/tests/runner.py index f06e1b62..71035b02 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -6308,6 +6308,53 @@ int main(int argc, char **argv) { self.do_run(src, '789:123.46\n0:100.1') + def test_reinterpreted_ptrs(self): + if self.emcc_args is None: return self.skip('needs emcc and libc') + + src = r''' +#include <stdio.h> + +class Foo { +private: + float bar; +public: + int baz; + + Foo(): bar(0), baz(4711) {}; + + int getBar() const; +}; + +int Foo::getBar() const { + return this->bar; +}; + +const Foo *magic1 = reinterpret_cast<Foo*>(0xDEAD111F); +const Foo *magic2 = reinterpret_cast<Foo*>(0xDEAD888F); + +static void runTest() { + + const Foo *a = new Foo(); + const Foo *b = a; + + if (a->getBar() == 0) { + if (a->baz == 4712) + b = magic1; + else + b = magic2; + } + + printf("%s\n", (b == magic1 ? "magic1" : (b == magic2 ? "magic2" : "neither"))); +}; + +extern "C" { + int main(int argc, char **argv) { + runTest(); + } +} +''' + self.do_run(src, 'magic2') + def test_jansson(self): return self.skip('currently broken') |