Skip to content

Commit

Permalink
Only use elimPtrTo on old LLVMs for invoke/call/callbr
Browse files Browse the repository at this point in the history
See `Note [Pointers and pointee types]` for the rationale. See also #177.
  • Loading branch information
RyanGlScott committed May 4, 2023
1 parent 3c24c4e commit 62ad50c
Showing 1 changed file with 8 additions and 20 deletions.
28 changes: 8 additions & 20 deletions src/Data/LLVM/BitCode/IR/Function.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 62ad50c

Please sign in to comment.