Skip to content

Commit

Permalink
parseAtomicRMW: Don't inspect pointee type of argument on recent LLVMs
Browse files Browse the repository at this point in the history
Recent versions of the `FUNC_CODE_INST_ATOMICRMW` instruction code directly
store the type corresponding to the pointer argument, which avoids the need to
pattern-match on the pointer type.  This is required to support opaque
pointers. See #177.

Older versions of the instruction (`FUNC_CODE_INST_ATOMICRMW_OLD`) do not store
this type directly, so there were have no choice but to inspect the pointee
type using `elimPtrTo`.
  • Loading branch information
RyanGlScott committed May 4, 2023
1 parent 62ad50c commit 9310823
Showing 1 changed file with 21 additions and 23 deletions.
44 changes: 21 additions & 23 deletions src/Data/LLVM/BitCode/IR/Function.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1137,29 +1137,27 @@ parseAtomicRMW old t r d = do
-- TODO: parse sync scope (ssid)
(ptr, ix0) <- getValueTypePair t r 0

(val, ix1) <- case typedType ptr of
PtrTo ty@(PrimType prim) -> do

-- Catch pointers of the wrong type
when (case prim of
Integer _ -> False
FloatType _ -> False
_ -> True) $
fail $ "Expected pointer to integer or float, found " ++ show ty

if old
then -- FUNC_CODE_INST_ATOMICRMW_OLD
do typed <- getValue t ty =<< parseField r ix0 numeric
if ty /= (typedType typed)
then fail $ unlines $ [ "Wrong type of value retrieved from value table"
, "Expected: " ++ show (ty)
, "Got: " ++ show (typedType typed)
]
else pure (typed, ix0 + 1)
else -- FUNC_CODE_INST_ATOMICRMW
getValueTypePair t r ix0

ty -> fail $ "Expected pointer to integer or float, found " ++ show ty
(val, ix1) <-
if old
then -- FUNC_CODE_INST_ATOMICRMW_OLD
do ty <- Assert.elimPtrTo "atomicrmw instruction not headed by pointer" (typedType ptr)
typed <- getValue t ty =<< parseField r ix0 numeric
if ty /= (typedType typed)
then fail $ unlines $ [ "Wrong type of value retrieved from value table"
, "Expected: " ++ show (ty)
, "Got: " ++ show (typedType typed)
]
else pure (typed, ix0 + 1)
else -- FUNC_CODE_INST_ATOMICRMW
getValueTypePair t r ix0

-- Catch incorrect operand types
let valTy = typedType val
unless (case valTy of
PrimType (Integer _) -> True
PrimType (FloatType _) -> True
_ -> False) $
fail $ "Expected integer or float operand, found " ++ show valTy

-- TODO: enable this assertion. Is getTypeValuePair returning the wrong value?
-- when (length (recordFields r) /= ix1 + 4) $ do
Expand Down

0 comments on commit 9310823

Please sign in to comment.