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

Undefined behavior in DataDepGraph: nodes_ = (GraphNode **)insts_ #94

Open
Quincunx271 opened this issue Jun 11, 2020 · 2 comments
Open
Labels
bug Something isn't working

Comments

@Quincunx271
Copy link
Member

C++ does not have covariant array types. That line of code is equivalent to nodes_ = reinterpret_cast<GraphNode**>(insts_), which is undefined behavior. It happens to work in our case, though.

In C++, covariant array types are not a thing. insts_ has type SchedInstruction** and SchedInstruction inherits from GraphNode, but that doesn't mean this is okay. The fact that we had to reinterpret_cast makes it clear that this is not okay.

In fact, we should go through the code and remove all uses of C-style casts, as C-style casts are bad practice in C++ because they are one of several different casts, including a potential reinterpret_cast, and every sane cast can be done without a C-style cast.


In this case, the solution is to remove the nodes_ member variable entirely and instead directly access insts_.

@Quincunx271 Quincunx271 added the bug Something isn't working label Jun 11, 2020
@vangthao95
Copy link
Member

I have only taken a quick look but if we can safely remove nodes_ and use insts_ instead then I agree we should remove it. Not sure why we have two pointers to essentially the same thing.

@Quincunx271
Copy link
Member Author

Quincunx271 commented Jun 23, 2020

It turns out this is less simple that I realized. nodes_ is in a parent class, namely DirAcycGraph, meaning we can't simply get rid of it, but must provide a way for the parent class to access it.

Although, DirAcycGraph's only subclass is DataDepGraph

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants