Add module trace information for strict memory safety

Extend the module trace format with a field indicating whether a given
module, or any module it depends on, was compiled with strict memory
safety enabled. This separate output from the compiler can be used as
part of an audit to determine what parts of Swift programs are built
with strict memory safety checking enabled.
This commit is contained in:
Doug Gregor
2024-12-24 12:27:35 -08:00
parent 92fbedcbc0
commit d593442cc4
15 changed files with 85 additions and 8 deletions

View File

@@ -726,7 +726,7 @@ protected:
HasAnyUnavailableDuringLoweringValues : 1
);
SWIFT_INLINE_BITFIELD(ModuleDecl, TypeDecl, 1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+8,
SWIFT_INLINE_BITFIELD(ModuleDecl, TypeDecl, 1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+8,
/// If the module is compiled as static library.
StaticLibrary : 1,
@@ -792,7 +792,10 @@ protected:
AllowNonResilientAccess : 1,
/// Whether this module has been built with -package-cmo.
SerializePackageEnabled : 1
SerializePackageEnabled : 1,
/// Whether this module has enabled strict memory safety checking.
StrictMemorySafety : 1
);
SWIFT_INLINE_BITFIELD(PrecedenceGroupDecl, Decl, 1+2,

View File

@@ -830,6 +830,15 @@ public:
Bits.ModuleDecl.IsConcurrencyChecked = value;
}
/// Whether this module has enable strict memory safety checking.
bool strictMemorySafety() const {
return Bits.ModuleDecl.StrictMemorySafety;
}
void setStrictMemorySafety(bool value = true) {
Bits.ModuleDecl.StrictMemorySafety = value;
}
bool isObjCNameLookupCachePopulated() const {
return Bits.ModuleDecl.ObjCNameLookupCachePopulated;
}

View File

@@ -149,6 +149,7 @@ class ExtendedValidationInfo {
unsigned HasCxxInteroperability : 1;
unsigned AllowNonResilientAccess: 1;
unsigned SerializePackageEnabled: 1;
unsigned StrictMemorySafety: 1;
} Bits;
public:
ExtendedValidationInfo() : Bits() {}
@@ -246,6 +247,13 @@ public:
void setIsConcurrencyChecked(bool val = true) {
Bits.IsConcurrencyChecked = val;
}
bool strictMemorySafety() const {
return Bits.StrictMemorySafety;
}
void setStrictMemorySafety(bool val = true) {
Bits.StrictMemorySafety = val;
}
bool hasCxxInteroperability() const { return Bits.HasCxxInteroperability; }
void setHasCxxInteroperability(bool val) {
Bits.HasCxxInteroperability = val;