[4.0] IRGen: Fix linkage for shared declarations #12164
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.
They need external linkage not linkonce_odr which can only be used by defintions
not declarations. This got exposed by clang imported protocol witness table declarations. They get assigned shared linkage since they are potentially not unique.
Explanation: There are situations where we end up with a SIL declaration of a protocol witness table that has shared linkage. We will unconditionally assign llvm’s linkonce_odr linkage to shared definitions and declarations. However, only definitions are allowed with this linkage. Instead we should use external linkage for such declarations.
This situation can arise under optimized incremental compilation when there are two files. One contains a protocol defintion that extends a clang importer synthesized protocol and another file that uses that protocol.
Scope of Issue: Compiler error when one uses incremental compilation with a definition of a hashable protocol conformance to a NS_OPTION type in one file and the use of the NS_OPTION type hashable conformance in another file. This is an older bug that has been around since at least last year.
Risk: Low. We are changing the linkage of a declaration from linkonce (which crashes) to a declaration with external linkage. What can at most happen is that we change an compiler error into a linker error (because the declaration is not satisfied by a definition somewhere else).
Testing: Added swift regression test
rdar://26563441