Skip to content

Commit be6e66a

Browse files
authored
Test funcptr import type (#4913)
* add a test for a function pointer from js being called, when there is also a call to it that due to asm.js ffi reasons has a different type
1 parent 97eed0f commit be6e66a

File tree

4 files changed

+42
-0
lines changed

4 files changed

+42
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <stdio.h>
2+
3+
extern "C" {
4+
float floaty(float f32, int i32, double f64);
5+
float floatyAlone(float f32, int i32, double f64);
6+
}
7+
8+
int main()
9+
{
10+
// call it once normally. the asm.js ffi will force it to be an f64
11+
printf("|%f|\n", floaty(12.34f, 1, 100.32));
12+
{
13+
// call it using a function pointer, which will need to be f32
14+
auto* fp = floaty;
15+
volatile auto vfp = fp;
16+
printf("|%f|\n", vfp(12.34f, 1, 100.32));
17+
}
18+
{
19+
// no other call for this one
20+
auto* fp = floatyAlone;
21+
volatile auto vfp = fp;
22+
printf("|%f|\n", vfp(12.34f, 1, 100.32));
23+
}
24+
return 0;
25+
}
26+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
mergeInto(LibraryManager.library, {
2+
floaty: function(x, y, z) {
3+
return -x + y;
4+
},
5+
floatyAlone: function(x, y, z) {
6+
return x - y;
7+
}
8+
});
9+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
|-11.340000|
2+
|-11.340000|
3+
|11.340000|

tests/test_core.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4768,6 +4768,10 @@ def test_unicode_js_library(self):
47684768
self.emcc_args += ['--js-library', path_from_root('tests', 'unicode_library.js')]
47694769
self.do_run(open(os.path.join(self.get_dir(), 'main.cpp'), 'r').read(), u'Unicode snowman \u2603 says hello!')
47704770

4771+
def test_funcptr_import_type(self):
4772+
self.emcc_args += ['--js-library', path_from_root('tests', 'core', 'test_funcptr_import_type.js'), '-std=c++11']
4773+
self.do_run_in_out_file_test('tests', 'core', 'test_funcptr_import_type')
4774+
47714775
def test_constglobalunion(self):
47724776
self.emcc_args += ['-s', 'EXPORT_ALL=1']
47734777

0 commit comments

Comments
 (0)