summaryrefslogtreecommitdiff
path: root/testsuite
diff options
context:
space:
mode:
authornineonine <mail4chemik@gmail.com>2022-11-10 21:03:11 -0800
committerMarge Bot <ben+marge-bot@smart-cactus.org>2022-11-23 12:47:11 -0500
commit99aca26b652603bc62953157a48e419f737d352d (patch)
treee50cb238a39bbbd7fe4d9d32b1af8ed290236433 /testsuite
parentb5c714545abc5f75a1ffdcc39b4bfdc7cd5e64b4 (diff)
downloadhaskell-99aca26b652603bc62953157a48e419f737d352d.tar.gz
CApiFFI: add ConstPtr for encoding const-qualified pointer return types (#22043)
Previously, when using `capi` calling convention in foreign declarations, code generator failed to handle const-cualified pointer return types. This resulted in CC toolchain throwing `-Wincompatible-pointer-types-discards-qualifiers` warning. `Foreign.C.Types.ConstPtr` newtype was introduced to handle these cases - special treatment was put in place to generate appropritetly qualified C wrapper that no longer triggers the above mentioned warning. Fixes #22043
Diffstat (limited to 'testsuite')
-rw-r--r--testsuite/tests/ffi/should_compile/T22034.h2
-rw-r--r--testsuite/tests/ffi/should_compile/T22034.hs10
-rw-r--r--testsuite/tests/ffi/should_compile/T22034_c.c9
-rw-r--r--testsuite/tests/ffi/should_compile/all.T1
4 files changed, 22 insertions, 0 deletions
diff --git a/testsuite/tests/ffi/should_compile/T22034.h b/testsuite/tests/ffi/should_compile/T22034.h
new file mode 100644
index 0000000000..26c49d3a38
--- /dev/null
+++ b/testsuite/tests/ffi/should_compile/T22034.h
@@ -0,0 +1,2 @@
+const int *foo();
+const double *bar;
diff --git a/testsuite/tests/ffi/should_compile/T22034.hs b/testsuite/tests/ffi/should_compile/T22034.hs
new file mode 100644
index 0000000000..8c065c3ea1
--- /dev/null
+++ b/testsuite/tests/ffi/should_compile/T22034.hs
@@ -0,0 +1,10 @@
+{-# LANGUAGE CApiFFI #-}
+module T22034 where
+
+import Foreign.C.Types
+
+foreign import capi "T22034.h foo"
+ c_foo :: IO (ConstPtr CInt)
+
+foreign import capi "T22034.h value bar"
+ c_bar :: ConstPtr CDouble
diff --git a/testsuite/tests/ffi/should_compile/T22034_c.c b/testsuite/tests/ffi/should_compile/T22034_c.c
new file mode 100644
index 0000000000..e70b5a978f
--- /dev/null
+++ b/testsuite/tests/ffi/should_compile/T22034_c.c
@@ -0,0 +1,9 @@
+#include <stdlib.h>
+
+const int * foo() {
+ int *x = malloc(sizeof(int));
+ *x = 42;
+ return x;
+}
+
+const int *bar = 0;
diff --git a/testsuite/tests/ffi/should_compile/all.T b/testsuite/tests/ffi/should_compile/all.T
index d8afeb9f7b..532f5c3854 100644
--- a/testsuite/tests/ffi/should_compile/all.T
+++ b/testsuite/tests/ffi/should_compile/all.T
@@ -43,3 +43,4 @@ test(
],
)
test('T15531', normal, compile, ['-Wall'])
+test('T22034', [omit_ways(['ghci'])], compile, [''])