Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix confusion between GEP base type and return type #322

Merged
merged 1 commit into from
Oct 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading