Skip to content

Inconsistent Cmm argument handling in 64-bit/32-bit architecture

Consider the following program:

{-# LANGUAGE GHCForeignImportPrim, MagicHash, UnliftedFFITypes #-}
{-# OPTIONS_GHC -ddump-to-file -ddump-cmm-raw #-}

module Wolf where

import GHC.Exts

foreign import prim "foo"
  c_foo :: Any -> Int# -> Int#

When using a GHC targetting 64-bit platform to compile it and check the raw Cmm dump, in c_foo_entry the arguments to be passed to foo is assigned in R1, R2. But when using a GHC targetting 32-bit platform, the first argument is assigned to R1, but the second argument is passed on the stack. I confirmed this is the case for wasm32, and @bgamari confirmed this is the case for i386 as well.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information