[GHC] #12614: Integer division can overwrite other arguments to foreign call

#12614: Integer division can overwrite other arguments to foreign call
-------------------------------------+-------------------------------------
Reporter: jscholl | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 8.0.1
(NCG) |
Keywords: integer | Operating System: Unknown/Multiple
division |
Architecture: x86_64 | Type of failure: Incorrect result
(amd64) | at runtime
Test Case: | Blocked By:
Blocking: | Related Tickets:
Differential Rev(s): | Wiki Page:
-------------------------------------+-------------------------------------
If you call a foreign function, GHC can generate incorrect code while
passing the arguments to the function, overwriting the 3rd argument if a
later argument contains an integer division.
Main.hs:
{{{
{-# LANGUAGE ForeignFunctionInterface #-}
module Main where
{-# NOINLINE foo #-}
foo :: Int -> IO ()
foo x = c_foo 0 0 x $ x + x `quot` 10
foreign import ccall "foo" c_foo :: Int -> Int -> Int -> Int -> IO ()
main :: IO ()
main = do
foo 202
foo 203
foo 204
}}}
foo.c:
{{{
#include

#12614: Integer division can overwrite other arguments to foreign call -------------------------------------+------------------------------------- Reporter: jscholl | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler (NCG) | Version: 8.0.1 Resolution: | Keywords: integer | division Operating System: Unknown/Multiple | Architecture: x86_64 Type of failure: Incorrect result | (amd64) at runtime | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by hsyl20): This looks very similar to #11792. Isn't the foreign call unsafe in your test case? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12614#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12614: Integer division can overwrite other arguments to foreign call -------------------------------------+------------------------------------- Reporter: jscholl | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler (NCG) | Version: 8.0.1 Resolution: | Keywords: integer | division Operating System: Unknown/Multiple | Architecture: x86_64 Type of failure: Incorrect result | (amd64) at runtime | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by jscholl): You are right, it is most likely the same root cause. But no, the foreign call is not unsafe as far as I understand (the default is safe, right?). Also if I change it to an explicit safe or unsafe call the behavior is unchanged, so this does not seem to be a factor in this case. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12614#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12614: Integer division can overwrite other arguments to foreign call -------------------------------------+------------------------------------- Reporter: jscholl | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler (NCG) | Version: 8.0.1 Resolution: | Keywords: integer | division Operating System: Unknown/Multiple | Architecture: x86_64 Type of failure: Incorrect result | (amd64) at runtime | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by hsyl20): I have fixed both this issue and #11792 in Phab:D2263. I have added your failing example (extended to test pushed args) as a test too. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12614#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12614: Integer division can overwrite other arguments to foreign call -------------------------------------+------------------------------------- Reporter: jscholl | Owner: Type: bug | Status: patch Priority: high | Milestone: 8.0.2 Component: Compiler (NCG) | Version: 8.0.1 Resolution: | Keywords: integer | division Operating System: Unknown/Multiple | Architecture: x86_64 Type of failure: Incorrect result | (amd64) at runtime | Test Case: Blocked By: | Blocking: Related Tickets: #11792 | Differential Rev(s): Phab:D2263 Wiki Page: | -------------------------------------+------------------------------------- Changes (by hsyl20): * status: new => patch * cc: hsyl20 (added) * differential: => Phab:D2263 * related: => #11792 * priority: normal => high * milestone: => 8.0.2 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12614#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12614: Integer division can overwrite other arguments to foreign call
-------------------------------------+-------------------------------------
Reporter: jscholl | Owner:
Type: bug | Status: patch
Priority: high | Milestone: 8.0.2
Component: Compiler (NCG) | Version: 8.0.1
Resolution: | Keywords: integer
| division
Operating System: Unknown/Multiple | Architecture: x86_64
Type of failure: Incorrect result | (amd64)
at runtime | Test Case:
Blocked By: | Blocking:
Related Tickets: #11792 | Differential Rev(s): Phab:D2263
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Ben Gamari

#12614: Integer division can overwrite other arguments to foreign call -------------------------------------+------------------------------------- Reporter: jscholl | Owner: Type: bug | Status: merge Priority: high | Milestone: 8.0.2 Component: Compiler (NCG) | Version: 8.0.1 Resolution: | Keywords: integer | division Operating System: Unknown/Multiple | Architecture: x86_64 Type of failure: Incorrect result | (amd64) at runtime | Test Case: Blocked By: | Blocking: Related Tickets: #11792 | Differential Rev(s): Phab:D2263 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: patch => merge -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12614#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12614: Integer division can overwrite other arguments to foreign call -------------------------------------+------------------------------------- Reporter: jscholl | Owner: Type: bug | Status: closed Priority: high | Milestone: 8.0.2 Component: Compiler (NCG) | Version: 8.0.1 Resolution: fixed | Keywords: integer | division Operating System: Unknown/Multiple | Architecture: x86_64 Type of failure: Incorrect result | (amd64) at runtime | Test Case: Blocked By: | Blocking: Related Tickets: #11792 | Differential Rev(s): Phab:D2263 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: merge => closed * resolution: => fixed Comment: Comment:5 merged to `ghc-8.0` as aec4a514857d051f5eeb15b9cbc8e6dd29850c5f -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12614#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC