Break when app and extapi module have a match #1281
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As name from app and extapi modules can only have exactly one match, we can break after find it.
The benefit is not limited to performance.
Take a look at the loop of the second break:
fun
is casted out ofappfunc
fromfunDefs
, which is the function list of app module.Then,
fun->eraseFromParent()
remove that function from the function list. This is ultimately alist->remove()
operation, see: https://github.com/llvm/llvm-project/blob/main/llvm/lib/IR/Function.cpp#L389This operation will release the object of
fun
, and alsoappfunc
, so when we still try to compareappfunc
withowfunc
, the behavior is undefined.I received a SIGSEGV at line 960 (original version) after thousands of calls to
appfunc->getName()
after the first match. Both the bc file and extapi are quite large so I prefer not pasting it here. Also since this issue ismalloc
-related, it's not easy to provide a stable yet minimal reproducible example, but I think describing it already makes much sense.