mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
ReadOnlyGlobalVariables: don't convert external global vars to lets
Because we don't know if external variables will be written Fixes a miscompile rdar://109476745
This commit is contained in:
@@ -35,7 +35,8 @@ let readOnlyGlobalVariablesPass = ModulePass(name: "read-only-global-variables")
|
||||
}
|
||||
|
||||
for g in moduleContext.globalVariables {
|
||||
if !g.isPossiblyUsedExternally,
|
||||
if !g.isAvailableExternally,
|
||||
!g.isPossiblyUsedExternally,
|
||||
!g.isLet,
|
||||
!writtenGlobals.contains(g) {
|
||||
g.setIsLet(to: true, moduleContext)
|
||||
|
||||
@@ -35,6 +35,14 @@ final public class GlobalVariable : CustomStringConvertible, HasShortDescription
|
||||
return bridged.isPossiblyUsedExternally()
|
||||
}
|
||||
|
||||
/// True, if the linkage of the global indicates that it has a definition outside the
|
||||
/// current compilation unit.
|
||||
///
|
||||
/// For example, `public_external` linkage.
|
||||
public var isAvailableExternally: Bool {
|
||||
return bridged.isAvailableExternally()
|
||||
}
|
||||
|
||||
public var staticInitValue: SingleValueInstruction? {
|
||||
bridged.getStaticInitializerValue().instruction as? SingleValueInstruction
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user