Skip to content

Support opaque pointers in llvm_fresh_expanded_val #1879

Open
@RyanGlScott

Description

@RyanGlScott

I have recently updated SAW to work with LLVM's opaque pointers, an LLVM language change that replaces pointers with explicit pointee types (e.g., i32*) with opaque pointers that lack pointee types. In an opaque pointer setting, all pointers have the type ptr, and LLVM determines how to interpret the underlying memory based on the types of instructions that the pointers are used in. For more information, see the following links:

While most parts of SAW now fully support opaque pointers, there is one part of SAW that cannot handle them at the moment: the llvm_fresh_expanded_val command. This can be seen by running the following SAW script (using #1878):

// test.c
void f(int* x) {}
// test.saw
let f_spec = do {
    val <- llvm_fresh_expanded_val (llvm_type "ptr");
    llvm_execute_func [val];
};

m <- llvm_load_module "test.bc";
ov <- llvm_verify m "f" [] false f_spec z3;
$ ~/Software/clang+llvm-16.0.0/bin/clang -g -c -emit-llvm test.c
$ ./bin/saw test.saw



[12:02:45.670] Loading file "/home/ryanglscott/Documents/Hacking/Haskell/saw-script/test.saw"
[12:02:45.673] Stack trace:
"llvm_verify" (/home/ryanglscott/Documents/Hacking/Haskell/saw-script/test.saw:8:7-8:18)
llvm_fresh_expanded_var: PtrOpaque not supported

It's not clear to me what the right behavior should be for fresh opaque pointers. There is already a case for non-opaque pointers:

Crucible.PtrType symTy ->
case Crucible.asMemType symTy of
Right memTy -> constructFreshPointer (symTypeAlias symTy) loc memTy
Left err -> throwCrucibleSetup loc $ unlines
[ "lhs not a valid pointer type: " ++ show symTy
, "Details:"
, err
]

This case will construct a SAW allocation using the same machinery as the llvm_fresh_pointer command. This command relies on knowing what the pointer's pointee type is, however, and we don't have access to pointee types for opaque pointers.

One possibility is to just return a null pointer when making a fresh opaque pointer. This would work, but it would be noticeably different from how non-opaque pointers are treated, which could be confusing.

For now, I am going to make calling llvm_fresh_expanded_val on an opaque pointer an error. We can revisit this if someone expresses a desire for it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs designTechnical design work is needed for issue to progresssubsystem: crucible-llvmIssues related to LLVM bitcode verification with crucible-llvmtech debtIssues that document or involve technical debttype: enhancementIssues describing an improvement to an existing feature or capability

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions