From 62ad50c1316ad2e0b4bdcde1fefc08158c60bce1 Mon Sep 17 00:00:00 2001 From: Ryan Scott Date: Sat, 22 Apr 2023 20:41:29 -0400 Subject: [PATCH] Only use `elimPtrTo` on old LLVMs for `invoke`/`call`/`callbr` See `Note [Pointers and pointee types]` for the rationale. See also #177. --- src/Data/LLVM/BitCode/IR/Function.hs | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/src/Data/LLVM/BitCode/IR/Function.hs b/src/Data/LLVM/BitCode/IR/Function.hs index fd5fc3d1..4a1e9312 100644 --- a/src/Data/LLVM/BitCode/IR/Function.hs +++ b/src/Data/LLVM/BitCode/IR/Function.hs @@ -539,13 +539,9 @@ parseFunctionBlockEntry _ t d (fromEntry -> Just r) = case recordCode r of (f,ix') <- getValueTypePair t r ix - -- NOTE: mbFTy should be the same as the type of f - calleeTy <- Assert.elimPtrTo "Callee is not a pointer" (typedType f) - fty <- case mbFTy of - Just ty | calleeTy == ty -> return ty - | otherwise -> fail "Explicit invoke type does not match callee" - Nothing -> return calleeTy + Just ty -> return ty + Nothing -> Assert.elimPtrTo "Callee is not a pointer" (typedType f) (ret,as,va) <- elimFunTy fty `mplus` fail "invalid INVOKE record" @@ -714,14 +710,10 @@ parseFunctionBlockEntry _ t d (fromEntry -> Just r) = case recordCode r of (Typed opTy fn, ix2) <- getValueTypePair t r ix1 `mplus` fail "Invalid record" - op <- Assert.elimPtrTo "Callee is not a pointer type" opTy - fnty <- case mbFnTy of - Just ty | ty == op -> return op - | otherwise -> fail "Explicit call type does not match \ - \pointee type of callee operand" - - Nothing -> + Just ty -> return ty + Nothing -> do + op <- Assert.elimPtrTo "Callee is not a pointer type" opTy case op of FunTy{} -> return op _ -> fail "Callee is not of pointer to function type" @@ -987,14 +979,10 @@ parseFunctionBlockEntry _ t d (fromEntry -> Just r) = case recordCode r of (Typed opTy fn, ix2) <- getValueTypePair t r ix1 `mplus` fail "Invalid callbr record" - op <- Assert.elimPtrTo "callbr callee is not a pointer type" opTy - fnty <- case mbFnTy of - Just ty | ty == op -> return op - | otherwise -> fail "Explicit call type does not match \ - \pointee type of callee operand" - - Nothing -> + Just ty -> return ty + Nothing -> do + op <- Assert.elimPtrTo "callbr callee is not a pointer type" opTy case op of FunTy{} -> return op _ -> fail "Callee is not of pointer to function type"