From 93108238c6ca5a41cd463129e10019e71fc48f1d Mon Sep 17 00:00:00 2001 From: Ryan Scott Date: Sat, 22 Apr 2023 20:49:03 -0400 Subject: [PATCH] parseAtomicRMW: Don't inspect pointee type of argument on recent LLVMs 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`. --- src/Data/LLVM/BitCode/IR/Function.hs | 44 +++++++++++++--------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/src/Data/LLVM/BitCode/IR/Function.hs b/src/Data/LLVM/BitCode/IR/Function.hs index 4a1e9312..9edf7241 100644 --- a/src/Data/LLVM/BitCode/IR/Function.hs +++ b/src/Data/LLVM/BitCode/IR/Function.hs @@ -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