Skip to content

Commit

Permalink
Merge pull request #322 from GaloisInc/vr/fix-gep
Browse files Browse the repository at this point in the history
fix confusion between GEP base type and return type
  • Loading branch information
Ptival authored Oct 18, 2024
2 parents 359da26 + c636f42 commit 7948b66
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/Reopt/CFG/LLVM.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1167,17 +1167,21 @@ bvSubPtrPtr x y = do

-- | This emits a getElementPointer in the special case where the value argument is a pointer.
llvmGEPFromPtr ::
HasCallStack =>
L.Type ->
Int ->
L.Typed L.Value ->
BBLLVM arch (L.Typed L.Value)
llvmGEPFromPtr pointeeType ofs ptrV = do
let pointerType = L.PtrTo pointeeType
llvmGEPFromPtr returnType ofs ptrV = do
let
pointeeType =
case L.typedType ptrV of
L.PtrTo ty -> ty
ty -> error $ "llvmGEPFromPtr: expecter pointer type, got: " <> show ty
zeroV = L.Typed (L.iT 32) (L.int 0)
ofsV = L.Typed (L.iT 32) (L.int ofs)
-- https://llvm.org/docs/GetElementPtr.html#what-is-the-first-index-of-the-gep-instruction
L.Typed pointerType <$> evalInstr (L.GEP False pointeeType ptrV [zeroV, ofsV])
L.Typed returnType <$> evalInstr (L.GEP False pointeeType ptrV [zeroV, ofsV])

-- | Truncate and log.
llvmTrunc ::
Expand Down

0 comments on commit 7948b66

Please sign in to comment.