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

Get pointer type in absence of getPtrElementType #1439

Closed
Qcloud1223 opened this issue Apr 18, 2024 · 2 comments
Closed

Get pointer type in absence of getPtrElementType #1439

Qcloud1223 opened this issue Apr 18, 2024 · 2 comments

Comments

@Qcloud1223
Copy link
Contributor

Hi,

In early version of SVF, I have the following code (details trimmed for brevity) to find the memory a pointer points to:

void checkFieldRecursively(SVFIR *pag, Andersen *ander, NodeID head)
{
    auto currPtrType = SVFUtil::dyn_cast<SVFPointerType>(pag->getGNode(head)->getType());
    if (currPtrType->getPtrElementType()->isPointerTy()) {
        /* point to objects at the next layer */
        auto currPts = ander->getPts(head);
        for (auto cpit : currPts) {
            checkFieldRecursively(pag, ander, cpit);
        }
    }
}

In this case, I can get set of objects that can be pointed to by a multi-level pointer.
For example, for int **a, it might points to int *aa, *bb. And they might point to int aaa1, aaa2 and int bbb1, bbb2, respectively.

In this case, by recursively checking a PointerType, eventually a non-pointer can be met and then I can get a full set of non-pointer objects that might be pointed to by a pointer at arbitrary level.

However, in #1323, SVFPointerType no longer has method getPtrElementType. This invalidates the code snippet above. I though inferObjType might help, but it deals with raw LLVM types so really confused me.

My question is: How can I get pointer type in absence of getPtrElementType? If not, is there a new interface to achieve the same thing as above, i.e., get all objects (ObjVar) pointed to by a multi-level pointer?

@jumormt
Copy link
Contributor

jumormt commented Apr 18, 2024

Hello @Qcloud1223 ,

getPtrElementType is removed because now all pointers are opaque (https://llvm.org/docs/OpaquePointers.html). However, all memory objects are typed. You can always check whether the SVFVar is an object variable and its type.

@Qcloud1223
Copy link
Contributor Author

@jumormt Thanks for your reply!

I think the update in LLVM and SVF makes sense. Since the memory pointed to will always have type info, it's not necessary to keep another copy in the pointer.

Even in the use case above, the users should only be interested in whether an SVFVar is pointer or not: if a node is still pointer, the users should still find its PTS and this process will eventually reach object variable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants