[SIL] Make @_silgen_name and @_cdecl functions immune to some optimizations (#12696)

@_silgen_name and @_cdecl functions are assumed to be referenced from
C code. Public and internal functions marked as such must not be deleted
by the optimizer, and their C symbols must be public or hidden respectively.

rdar://33924873, SR-6209
This commit is contained in:
Greg Parker
2017-11-01 01:41:05 -07:00
committed by GitHub
parent c89e49091a
commit d6e1866344
7 changed files with 79 additions and 25 deletions

View File

@@ -96,7 +96,8 @@ SILFunction::SILFunction(SILModule &Module, SILLinkage Linkage, StringRef Name,
Serialized(isSerialized), Thunk(isThunk),
ClassSubclassScope(unsigned(classSubclassScope)), GlobalInitFlag(false),
InlineStrategy(inlineStrategy), Linkage(unsigned(Linkage)),
KeepAsPublic(false), EffectsKindAttr(E), EntryCount(entryCount) {
HasCReferences(false), KeepAsPublic(false), EffectsKindAttr(E),
EntryCount(entryCount) {
if (InsertBefore)
Module.functions.insert(SILModule::iterator(InsertBefore), this);
else
@@ -445,13 +446,15 @@ bool SILFunction::hasValidLinkageForFragileRef() const {
return hasPublicVisibility(getLinkage());
}
/// Helper method which returns true if the linkage of the SILFunction
/// indicates that the objects definition might be required outside the
/// current SILModule.
bool
SILFunction::isPossiblyUsedExternally() const {
return swift::isPossiblyUsedExternally(getLinkage(),
getModule().isWholeModule());
auto linkage = getLinkage();
// Hidden functions may be referenced by other C code in the linkage unit.
if (linkage == SILLinkage::Hidden && hasCReferences())
return true;
return swift::isPossiblyUsedExternally(linkage, getModule().isWholeModule());
}
bool SILFunction::isExternallyUsedSymbol() const {