Skip to content

Commit

Permalink
Catch "divide by zero" in more places in the primitive evaluator
Browse files Browse the repository at this point in the history
  • Loading branch information
leonschoorl authored and kleinreact committed Oct 7, 2024
1 parent 9e6c916 commit d4975ff
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions clash-ghc/src-ghc/Clash/GHC/Evaluator/Primitive.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1493,7 +1493,7 @@ ghcPrimStep tcm isSubj pInfo tys args mach = case primName pInfo of
_ -> Nothing

"GHC.Classes.divInt#" | Just (i,j) <- intLiterals args
-> reduce (integerToIntLiteral (i `div` j))
-> reduce $ catchDivByZero (integerToIntLiteral (i `div` j))

-- modInt# :: Int# -> Int# -> Int#
"GHC.Classes.modInt#"
Expand Down Expand Up @@ -2015,13 +2015,13 @@ ghcPrimStep tcm isSubj pInfo tys args mach = case primName pInfo of
| Just (i,j) <- naturalLiterals args
->
let nTy = snd (splitFunForallTy ty) in
reduce (checkNaturalRange2 nTy i j quot)
reduce $ catchDivByZero (checkNaturalRange2 nTy i j quot)

"GHC.Num.Natural.naturalRem"
| Just (i,j) <- naturalLiterals args
->
let nTy = snd (splitFunForallTy ty) in
reduce (checkNaturalRange2 nTy i j rem)
reduce $ catchDivByZero (checkNaturalRange2 nTy i j rem)
#endif

#if MIN_VERSION_base(4,15,0)
Expand Down Expand Up @@ -2421,26 +2421,26 @@ ghcPrimStep tcm isSubj pInfo tys args mach = case primName pInfo of
| [ DC intDc [Left (Literal (IntLiteral i))]
, DC _ [Left (Literal (IntLiteral j))]
] <- args
-> reduce (App (Data intDc) (Literal (IntLiteral (i `quot` j))))
-> reduce $ catchDivByZero (App (Data intDc) (Literal (IntLiteral (i `quot` j))))

"GHC.Base.remInt"
| [ DC intDc [Left (Literal (IntLiteral i))]
, DC _ [Left (Literal (IntLiteral j))]
] <- args
-> reduce (App (Data intDc) (Literal (IntLiteral (i `rem` j))))
-> reduce $ catchDivByZero (App (Data intDc) (Literal (IntLiteral (i `rem` j))))

"GHC.Base.divInt"
| [ DC intDc [Left (Literal (IntLiteral i))]
, DC _ [Left (Literal (IntLiteral j))]
] <- args
-> reduce (App (Data intDc) (Literal (IntLiteral (i `div` j))))
-> reduce $ catchDivByZero (App (Data intDc) (Literal (IntLiteral (i `div` j))))


"GHC.Base.modInt"
| [ DC intDc [Left (Literal (IntLiteral i))]
, DC _ [Left (Literal (IntLiteral j))]
] <- args
-> reduce (App (Data intDc) (Literal (IntLiteral (i `mod` j))))
-> reduce $ catchDivByZero (App (Data intDc) (Literal (IntLiteral (i `mod` j))))

"Clash.Class.BitPack.Internal.packDouble#" -- :: Double -> BitVector 64
| [DC _ [Left arg]] <- args
Expand Down

0 comments on commit d4975ff

Please sign in to comment.