summaryrefslogtreecommitdiff
path: root/testsuite/tests/ffi/should_run/2917a.hs
diff options
context:
space:
mode:
authorDavid Terei <davidterei@gmail.com>2011-07-20 11:09:03 -0700
committerDavid Terei <davidterei@gmail.com>2011-07-20 11:26:35 -0700
commit16514f272fb42af6e9c7674a9bd6c9dce369231f (patch)
treee4f332b45fe65e2a7a2451be5674f887b42bf199 /testsuite/tests/ffi/should_run/2917a.hs
parentebd422aed41048476aa61dd4c520d43becd78682 (diff)
downloadhaskell-16514f272fb42af6e9c7674a9bd6c9dce369231f.tar.gz
Move tests from tests/ghc-regress/* to just tests/*
Diffstat (limited to 'testsuite/tests/ffi/should_run/2917a.hs')
-rw-r--r--testsuite/tests/ffi/should_run/2917a.hs42
1 files changed, 42 insertions, 0 deletions
diff --git a/testsuite/tests/ffi/should_run/2917a.hs b/testsuite/tests/ffi/should_run/2917a.hs
new file mode 100644
index 0000000000..cdfaabcd2a
--- /dev/null
+++ b/testsuite/tests/ffi/should_run/2917a.hs
@@ -0,0 +1,42 @@
+import Foreign
+import Control.Monad
+
+-- check that all pointers returned by allocaBytes and mallocBytes are
+-- 16-byte aligned
+main = do
+ sequence [ allocaBytes x $ return | x <- [1..500] ] >>= check 16
+ (replicateM 500 (alloca $ return) :: IO [Ptr Align32]) >>= check 32
+ (replicateM 500 (alloca $ return) :: IO [Ptr Align64]) >>= check 64
+ (replicateM 500 (alloca $ return) :: IO [Ptr Align128]) >>= check 128
+ (replicateM 500 (alloca $ return) :: IO [Ptr Align256]) >>= check 256
+ -- mapM mallocBytes [1..500] >>= check 16
+
+check :: Int -> [Ptr a] -> IO ()
+check align xs = do
+ let bad = [ p | p <- xs, (p `minusPtr` nullPtr) .&. (align-1) /= 0 ]
+ when (not $ null bad) $
+ putStrLn ("FAIL: " ++ show align ++ " " ++ show bad)
+
+data Align32 = Align32
+
+instance Storable Align32 where
+ sizeOf _ = 32
+ alignment _ = 32
+
+data Align64 = Align64
+
+instance Storable Align64 where
+ sizeOf _ = 64
+ alignment _ = 64
+
+data Align128 = Align128
+
+instance Storable Align128 where
+ sizeOf _ = 128
+ alignment _ = 128
+
+data Align256 = Align256
+
+instance Storable Align256 where
+ sizeOf _ = 256
+ alignment _ = 256