Commit 0683f39
committed
[ClangImporter] Break cycle in IAM extensions
Under a set of circumstances that I cannot fully characterize, it was possible for `ClangImporter::Implementation::importDeclContextOf()` to end up recursing until stack overflow while trying to import a global as a member.
The cycle was caused by `addExtension()` using a newly-created extension’s lazy member loader to load its members before the extension had been added to ClangImporter’s `extensionPoints` table. Loading the members would try to import the IAM members again, which would cause `importDeclContextOf()` to try to create another extension to contain them, which `addExtension()` would force to load those members. Repeat until stack overflow.
I have fixed this bug by registering the extension in the `extensionPoints` map before its member loader is set. This ensures that if `importDeclContextOf()` gets called for any reason after that point, it will return the existing extension instead of creating a new one, avoiding the cycle.
Unfortunately, I was not able to figure out the exact conditions that were necessary to reproduce this bug, so I have not included a test. However, I have tested with the affected project locally and confirmed that this change lets it build. All existing tests pass.
Fixes rdar://120854030.1 parent 0842787 commit 0683f39
1 file changed
+5
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9043 | 9043 | | |
9044 | 9044 | | |
9045 | 9045 | | |
| 9046 | + | |
| 9047 | + | |
| 9048 | + | |
| 9049 | + | |
| 9050 | + | |
9046 | 9051 | | |
9047 | 9052 | | |
9048 | 9053 | | |
| |||
9052 | 9057 | | |
9053 | 9058 | | |
9054 | 9059 | | |
9055 | | - | |
9056 | | - | |
9057 | 9060 | | |
9058 | 9061 | | |
9059 | 9062 | | |
| |||
0 commit comments