Skip to content

SIL: fix some memory leaks and add verification for leaked instructions #33888

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

Merged
merged 8 commits into from
Sep 11, 2020

Conversation

eeckstein
Copy link
Contributor

@eeckstein eeckstein commented Sep 10, 2020

Fixing some memory leaks:

1. related to zombie functions

The leak happened in this scenario:

  1. A function becomes dead and gets deleted (which means: it gets added to the zombie-list)
  2. A function with the same name is created again. This can happen with specializations.

In such a case we just removed the zombie function from the zombie-list without deleting it.
But we cannot delete zombie functions, because they might still be referenced by metadata, like debug-info.

Therefore the right fix is to resurrect the zombie function if a new function is created with the same name.

2. Let SILGlobalVariables be destroyed

Instructions of the static initializer block were not be freed.

3. Leaks in SILParser

Also: check for leaked instructions in the SILVerifier and in the SILModule destructor.

rdar://problem/66931238

@eeckstein
Copy link
Contributor Author

@swift-ci test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - d26d7b612165e35cba7949917b2db05dcdb69ee0

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - d26d7b612165e35cba7949917b2db05dcdb69ee0

@eeckstein
Copy link
Contributor Author

@swift-ci test

1 similar comment
@eeckstein
Copy link
Contributor Author

@swift-ci test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 6894a0884f2a7286ca6ad45c55db02eaa525dee4

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 6894a0884f2a7286ca6ad45c55db02eaa525dee4

The leak happened in this scenario:
1. A function becomes dead and gets deleted (which means: it gets added to the zombie-list)
2. A function with the same name is created again. This can happen with specializations.

In such a case we just removed the zombie function from the zombie-list without deleting it.
But we cannot delete zombie functions, because they might still be referenced by metadata, like debug-info.

Therefore the right fix is to resurrect the zombie function if a new function is created with the same name.

rdar://problem/66931238
… SILModule.

It's not needed because the names are stored in the ZombieFunctionTable anyway (this table was added later).
This fixes a memory leak: instructions of the static initializer block were not be freed.

rdar://problem/66931238
* Leaks due to forwarding values
* Leaks due to abort on errors

rdar://problem/66931238
All instructions after an "unreachable" were not added to the function anyway and were leaking.
…option

It had no effect, because such SIL is never generated anyway.
@eeckstein
Copy link
Contributor Author

@swift-ci test

1 similar comment
@eeckstein
Copy link
Contributor Author

@swift-ci test

@eeckstein eeckstein merged commit 9fb7769 into swiftlang:master Sep 11, 2020
@eeckstein eeckstein deleted the fix-leaks branch September 11, 2020 12:27
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