Skip to content

ClangImporter: Use a separate CompilerInstance for canReadPCH #28125

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

Conversation

dexonsmith
Copy link
Contributor

ClangImporter::canReadPCH has been trying to reset the main
CompilerInstance back to as if it hadn't run, but there's a long tail of
potential memory corruption here. One example is that it's reusing
HeaderSearch, but HeaderSearch contains a ModuleMap whose
SourceLocations will point into the soon-to-be-released ASTContext on
the stack. Instead, just use a separate CompilerInstnace, like the rest
of the ClangImporter does when it needs a different ASTContext.

This fixes a few potential memory corruption bugs, and it may be
related to the persistent "missing submodule X" problems hitting Linux
bots.

Note: assigning to myself while I run tests. I'll add reviewers when ready.

@dexonsmith dexonsmith self-assigned this Nov 7, 2019
@dexonsmith
Copy link
Contributor Author

@swift-ci please test

@dexonsmith
Copy link
Contributor Author

@swift-ci please smoke-test

@dexonsmith
Copy link
Contributor Author

@swift-ci smoke test

@swift-ci
Copy link
Contributor

swift-ci commented Nov 7, 2019

Build failed
Swift Test OS X Platform
Git Sha - 6121bea8e78aad50a8dfed2e12d65a901a4199df

@dexonsmith dexonsmith force-pushed the clang-importer/separate-compiler-instance-for-can-read-pch branch from 6121bea to d06b335 Compare November 7, 2019 03:41
@dexonsmith
Copy link
Contributor Author

@swift-ci smoke test

@dexonsmith
Copy link
Contributor Author

@swift-ci please smoke test

@swift-ci
Copy link
Contributor

swift-ci commented Nov 7, 2019

Build failed
Swift Test Linux Platform
Git Sha - 6121bea8e78aad50a8dfed2e12d65a901a4199df

@dexonsmith dexonsmith force-pushed the clang-importer/separate-compiler-instance-for-can-read-pch branch from d06b335 to 930ee29 Compare November 7, 2019 07:00
@dexonsmith
Copy link
Contributor Author

@swift-ci smoke-test

@dexonsmith
Copy link
Contributor Author

@swift-ci smoke test

@dexonsmith
Copy link
Contributor Author

@swift-ci please smoke test

@dexonsmith
Copy link
Contributor Author

@swift-ci smoke test osx

1 similar comment
@dexonsmith
Copy link
Contributor Author

@swift-ci smoke test osx

@dexonsmith
Copy link
Contributor Author

@swift-ci please smoke-test osx

@dexonsmith
Copy link
Contributor Author

@swift-ci smoke test osx

@dexonsmith
Copy link
Contributor Author

@swift-ci smoke test

@dexonsmith
Copy link
Contributor Author

@swift-ci smoke test osx

@dexonsmith
Copy link
Contributor Author

@swift-ci test

@dexonsmith
Copy link
Contributor Author

@swift-ci please test

@dexonsmith
Copy link
Contributor Author

@swift-ci smoke test osx

@dexonsmith
Copy link
Contributor Author

@swift-ci test osx

@swift-ci
Copy link
Contributor

swift-ci commented Nov 7, 2019

Build failed
Swift Test Linux Platform
Git Sha - 930ee29de95871f02e381b1b613f40dc7180340a

@dexonsmith dexonsmith force-pushed the clang-importer/separate-compiler-instance-for-can-read-pch branch from 930ee29 to b45a599 Compare November 7, 2019 07:51
@dexonsmith
Copy link
Contributor Author

@swift-ci test

@dexonsmith
Copy link
Contributor Author

@swift-ci smoke test

@dexonsmith
Copy link
Contributor Author

@swift-ci please smoke test

@dexonsmith
Copy link
Contributor Author

@swift-ci please test

@dexonsmith
Copy link
Contributor Author

@swift-ci smoke test osx

@swift-ci
Copy link
Contributor

swift-ci commented Nov 7, 2019

Build failed
Swift Test Linux Platform
Git Sha - b45a59940303a9c2e7ab771f45bab42f366340ab

@swift-ci
Copy link
Contributor

swift-ci commented Nov 7, 2019

Build failed
Swift Test OS X Platform
Git Sha - 6121bea8e78aad50a8dfed2e12d65a901a4199df

@shahmishal
Copy link
Member

@swift-ci test osx

@shahmishal
Copy link
Member

@swift-ci test

@swift-ci
Copy link
Contributor

swift-ci commented Nov 7, 2019

Build failed
Swift Test Linux Platform
Git Sha - b45a59940303a9c2e7ab771f45bab42f366340ab

@swift-ci
Copy link
Contributor

swift-ci commented Nov 7, 2019

Build failed
Swift Test OS X Platform
Git Sha - b45a59940303a9c2e7ab771f45bab42f366340ab

@shahmishal
Copy link
Member

@swift-ci test macOS

@dexonsmith dexonsmith force-pushed the clang-importer/separate-compiler-instance-for-can-read-pch branch from b45a599 to 4fc9e97 Compare November 7, 2019 11:12
@dexonsmith
Copy link
Contributor Author

@swift-ci smoke test
@swift-ci test

@dexonsmith
Copy link
Contributor Author

@swift-ci smoke test

@dexonsmith
Copy link
Contributor Author

@swift-ci please test

@dexonsmith
Copy link
Contributor Author

@swift-ci please smoke test

@dexonsmith dexonsmith removed their assignment Nov 7, 2019
@dexonsmith
Copy link
Contributor Author

@brentdax @adrian-prantl, This is ready for review now. Let me know if you have any questions or concerns!

Copy link
Contributor

@adrian-prantl adrian-prantl left a comment

Choose a reason for hiding this comment

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

As far as I can tell, this looks safe to me.

ClangImporter::canReadPCH has been trying to reset the main
CompilerInstance back to as if it hadn't run, but there's a long tail of
potential memory corruption here.  One example is that it's reusing
HeaderSearch, but HeaderSearch contains a ModuleMap whose
SourceLocations will point into the soon-to-be-released ASTContext on
the stack.  Instead, just use a separate CompilerInstnace, like the rest
of the ClangImporter does when it needs a different ASTContext.

This fixes a few potential memory corruption bugs, and it *may* be
related to the persistent "missing submodule X" problems hitting Linux
bots.
@dexonsmith dexonsmith force-pushed the clang-importer/separate-compiler-instance-for-can-read-pch branch from 4fc9e97 to 178d209 Compare November 7, 2019 18:47
@dexonsmith
Copy link
Contributor Author

@swift-ci smoke test

@dexonsmith
Copy link
Contributor Author

@swift-ci smoke test linux

@dexonsmith dexonsmith merged commit a853d76 into swiftlang:master Nov 7, 2019
@dexonsmith dexonsmith deleted the clang-importer/separate-compiler-instance-for-can-read-pch branch November 7, 2019 20:36
@beccadax
Copy link
Contributor

beccadax commented Nov 8, 2019

I think this change makes sense. I'm a little concerned that it could end up performing more work and thus regressing performance, so I've created a revert PR so I can test its performance, but I don't plan to merge the revert.

@dexonsmith
Copy link
Contributor Author

I think this change makes sense. I'm a little concerned that it could end up performing more work and thus regressing performance, so I've created a revert PR so I can test its performance, but I don't plan to merge the revert.

Thanks Brent!

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.

5 participants