summaryrefslogtreecommitdiff
path: root/testsuite/tests/ffi
diff options
context:
space:
mode:
Diffstat (limited to 'testsuite/tests/ffi')
-rw-r--r--testsuite/tests/ffi/should_run/PrimFFIInt8.hs28
-rw-r--r--testsuite/tests/ffi/should_run/PrimFFIInt8.stdout1
-rw-r--r--testsuite/tests/ffi/should_run/PrimFFIInt8_c.c7
-rw-r--r--testsuite/tests/ffi/should_run/PrimFFIWord8.hs28
-rw-r--r--testsuite/tests/ffi/should_run/PrimFFIWord8.stdout1
-rw-r--r--testsuite/tests/ffi/should_run/PrimFFIWord8_c.c7
-rw-r--r--testsuite/tests/ffi/should_run/all.T4
7 files changed, 76 insertions, 0 deletions
diff --git a/testsuite/tests/ffi/should_run/PrimFFIInt8.hs b/testsuite/tests/ffi/should_run/PrimFFIInt8.hs
new file mode 100644
index 0000000000..4124e074aa
--- /dev/null
+++ b/testsuite/tests/ffi/should_run/PrimFFIInt8.hs
@@ -0,0 +1,28 @@
+{-# LANGUAGE ForeignFunctionInterface #-}
+{-# LANGUAGE MagicHash #-}
+{-# LANGUAGE UnliftedFFITypes #-}
+
+module Main where
+
+import GHC.Exts
+
+foreign import ccall "add_all_int8"
+ add_all_int8
+ :: Int8# -> Int8# -> Int8# -> Int8# -> Int8#
+ -> Int8# -> Int8# -> Int8# -> Int8# -> Int8#
+ -> Int8#
+
+main :: IO ()
+main = do
+ let a = narrowInt8# 0#
+ b = narrowInt8# 1#
+ c = narrowInt8# 2#
+ d = narrowInt8# 3#
+ e = narrowInt8# 4#
+ f = narrowInt8# 5#
+ g = narrowInt8# 6#
+ h = narrowInt8# 7#
+ i = narrowInt8# 8#
+ j = narrowInt8# 9#
+ x = I# (extendInt8# (add_all_int8 a b c d e f g h i j))
+ print x
diff --git a/testsuite/tests/ffi/should_run/PrimFFIInt8.stdout b/testsuite/tests/ffi/should_run/PrimFFIInt8.stdout
new file mode 100644
index 0000000000..ea90ee3198
--- /dev/null
+++ b/testsuite/tests/ffi/should_run/PrimFFIInt8.stdout
@@ -0,0 +1 @@
+45
diff --git a/testsuite/tests/ffi/should_run/PrimFFIInt8_c.c b/testsuite/tests/ffi/should_run/PrimFFIInt8_c.c
new file mode 100644
index 0000000000..dc51687530
--- /dev/null
+++ b/testsuite/tests/ffi/should_run/PrimFFIInt8_c.c
@@ -0,0 +1,7 @@
+#include <stdint.h>
+
+int8_t add_all_int8(
+ int8_t a, int8_t b, int8_t c, int8_t d, int8_t e,
+ int8_t f, int8_t g, int8_t h, int8_t i, int8_t j) {
+ return a + b + c + d + e + f + g + h + i + j;
+}
diff --git a/testsuite/tests/ffi/should_run/PrimFFIWord8.hs b/testsuite/tests/ffi/should_run/PrimFFIWord8.hs
new file mode 100644
index 0000000000..87e46636d1
--- /dev/null
+++ b/testsuite/tests/ffi/should_run/PrimFFIWord8.hs
@@ -0,0 +1,28 @@
+{-# LANGUAGE ForeignFunctionInterface #-}
+{-# LANGUAGE MagicHash #-}
+{-# LANGUAGE UnliftedFFITypes #-}
+
+module Main where
+
+import GHC.Exts
+
+foreign import ccall "add_all_word8"
+ add_all_word8
+ :: Word8# -> Word8# -> Word8# -> Word8# -> Word8#
+ -> Word8# -> Word8# -> Word8# -> Word8# -> Word8#
+ -> Word8#
+
+main :: IO ()
+main = do
+ let a = narrowWord8# 0##
+ b = narrowWord8# 1##
+ c = narrowWord8# 2##
+ d = narrowWord8# 3##
+ e = narrowWord8# 4##
+ f = narrowWord8# 5##
+ g = narrowWord8# 6##
+ h = narrowWord8# 7##
+ i = narrowWord8# 8##
+ j = narrowWord8# 9##
+ x = W# (extendWord8# (add_all_word8 a b c d e f g h i j))
+ print x
diff --git a/testsuite/tests/ffi/should_run/PrimFFIWord8.stdout b/testsuite/tests/ffi/should_run/PrimFFIWord8.stdout
new file mode 100644
index 0000000000..ea90ee3198
--- /dev/null
+++ b/testsuite/tests/ffi/should_run/PrimFFIWord8.stdout
@@ -0,0 +1 @@
+45
diff --git a/testsuite/tests/ffi/should_run/PrimFFIWord8_c.c b/testsuite/tests/ffi/should_run/PrimFFIWord8_c.c
new file mode 100644
index 0000000000..535ed4185c
--- /dev/null
+++ b/testsuite/tests/ffi/should_run/PrimFFIWord8_c.c
@@ -0,0 +1,7 @@
+#include <stdint.h>
+
+uint8_t add_all_word8(
+ uint8_t a, uint8_t b, uint8_t c, uint8_t d, uint8_t e,
+ uint8_t f, uint8_t g, uint8_t h, uint8_t i, uint8_t j) {
+ return a + b + c + d + e + f + g + h + i + j;
+}
diff --git a/testsuite/tests/ffi/should_run/all.T b/testsuite/tests/ffi/should_run/all.T
index fd0af7ebc3..9223b3d1b3 100644
--- a/testsuite/tests/ffi/should_run/all.T
+++ b/testsuite/tests/ffi/should_run/all.T
@@ -188,3 +188,7 @@ test('ffi023', [ omit_ways(['ghci']),
test('T12134', [omit_ways(['ghci'])], compile_and_run, ['T12134_c.c'])
test('T12614', [omit_ways(['ghci'])], compile_and_run, ['T12614_c.c'])
+
+test('PrimFFIInt8', [omit_ways(['ghci'])], compile_and_run, ['PrimFFIInt8_c.c'])
+
+test('PrimFFIWord8', [omit_ways(['ghci'])], compile_and_run, ['PrimFFIWord8_c.c'])