Skip to content

[WIP] Pointee inference 2#164

Open
KevinLeeFM wants to merge 3 commits intoseahorn:mainfrom
KevinLeeFM:pointee-reference-2
Open

[WIP] Pointee inference 2#164
KevinLeeFM wants to merge 3 commits intoseahorn:mainfrom
KevinLeeFM:pointee-reference-2

Conversation

@KevinLeeFM
Copy link

This branch is a draft.

Let me know if I'm on the right track.

Currently the feature is very barebone but will try to be test- and result-driven, so I'm not expanding its functionalities until there's sufficient evidence it is recovering precision. Currently repairing the test suite for LLVM 15 to allow this.

return origins;
}

// Given an origin value, return the possible candidate pointee type for ptr.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please move new type inference from DsaLocal.cc file so that it is easier to see what changed and what is old.

Create 2 PRs. One PR with the original adaptation for LLVM15, and a separate PR for type inference. The type inference PR should be relative to the first PR so that it only includes the new type inference stuff.

This will be much easier to review


// Given a pointer value, yield all instructions/values that define or use it.
static llvm::SmallVector<const Value *, 8>
findPointerOrigins(const Value *ptr) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems like a very strange function. It converts an iterator into a vector.

This is usually not needed. If needed, there are simple one-line ways to do it No need for a function.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides converting the iterator to a vector, it also pushes in the origin of the pointer. If this doesn't warrant a function, I'll think of another way to iterate the origin and users.

Copy link

@1arie1 1arie1 Jul 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chatgpt suggests the following improvement

llvm::SmallVector<const llvm::Value *, 8> findPointerOrigins(const llvm::Value *ptr) {
  llvm::SmallVector<const llvm::Value *, 8> origins;
  origins.push_back(ptr);
  llvm::append_range(origins, ptr->users());
  return origins;
}```

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

however, with this is, it is a bit strange that the pointer and its uses are all placed into one vector. It is not clear how the vector will be processed later. If the vector is a todo list, then it would make more sense to allocate it outside of the function.

}

// Given an origin value, return the possible candidate pointee type for ptr.
// - If analysis is inconclusive or ambiguous, return nullptr
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment says 'return nullptr', but the function does not return a ptr

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixing for the next push. Forgot to remove the comment after API change.


// Given an origin value, return the possible candidate pointee type for ptr.
// - If analysis is inconclusive or ambiguous, return nullptr
static SmallPtrSet<Type *, 2> getPointeeTypesFromOrigin(const Value *ptr,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please write a more detailed spec for this function. I can't tell what it supposed to do exactly from the source. Makes hard to comment on whether it is appropriate.

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

Successfully merging this pull request may close these issues.

2 participants