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

CFGWalker with Single-thread failed #6557

Closed
XMadrid opened this issue Apr 28, 2024 · 4 comments · Fixed by #6573
Closed

CFGWalker with Single-thread failed #6557

XMadrid opened this issue Apr 28, 2024 · 4 comments · Fixed by #6573

Comments

@XMadrid
Copy link
Contributor

XMadrid commented Apr 28, 2024

When use CFGWalker to walk module with single thread, get a double-free fault.

I found we introduced two varaible: BasicBlock* exit = nullptr; and bool hasSyntheticExit = false; in src/cfg/cfg-traversal.h. And did not reset them in doWalkFunction.
In this case, the two variables from the previous function will still be used when we walk the subsequent function.

@kripken
Copy link
Member

kripken commented Apr 29, 2024

In general we do not reset such global state in those classes. Typically they are used with isFunctionParallel = true in which case a new instance is created each time (even in a single-threaded build, we should be creating new instances even if they do not actually run in parallel, for compatibility).

If you use them in a non-parallel way then I can see how there would be a problem, and this is in cfg-walker.h so it does imply that all users should be aware of this, which is kind of annoying, sorry about that. To improve this perhaps we could mark the class as function-parallel, though we'd need to check if we have any other uses in the codebase.

Alternatively we could reset those fields, but that would just add code size and work for a situation that function-parallel code is meant to avoid, so I'd lean against that.

@XMadrid
Copy link
Contributor Author

XMadrid commented May 6, 2024

Before this PR #6079, we can use CFGWalker with isFunctionParallel = False. I think we should keep the forward compatibility.

In fact, it may not be reset. In src/cfg/cfg-traversal.h line 548 - 577 :

  void doWalkFunction(Function* func) {
    basicBlocks.clear();
    debugIds.clear();
+  exit = nullptr;                          // It is similar to how we handle basicBlocks, debugIds and entry.
+  hasSyntheticExit = false;       

    startBasicBlock();
    entry = currBasicBlock;
    ...
  }

@kripken
Copy link
Member

kripken commented May 7, 2024

I see, thanks @XMadrid . Yes, I guess that would be more consistent. Would you like to open a PR with it?

@XMadrid
Copy link
Contributor Author

XMadrid commented May 8, 2024

Sure. I will do this.

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 a pull request may close this issue.

2 participants