mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
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:
@@ -53,6 +53,7 @@ struct SwiftModuleTraceInfo {
|
||||
std::string Path;
|
||||
bool IsImportedDirectly;
|
||||
bool SupportsLibraryEvolution;
|
||||
bool StrictMemorySafety;
|
||||
};
|
||||
|
||||
struct SwiftMacroTraceInfo {
|
||||
@@ -65,6 +66,7 @@ struct LoadedModuleTraceFormat {
|
||||
unsigned Version;
|
||||
Identifier Name;
|
||||
std::string Arch;
|
||||
bool StrictMemorySafety;
|
||||
std::vector<SwiftModuleTraceInfo> SwiftModules;
|
||||
std::vector<SwiftMacroTraceInfo> SwiftMacros;
|
||||
};
|
||||
@@ -80,6 +82,8 @@ template <> struct ObjectTraits<SwiftModuleTraceInfo> {
|
||||
out.mapRequired("isImportedDirectly", contents.IsImportedDirectly);
|
||||
out.mapRequired("supportsLibraryEvolution",
|
||||
contents.SupportsLibraryEvolution);
|
||||
out.mapRequired("strictMemorySafety",
|
||||
contents.StrictMemorySafety);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -104,6 +108,8 @@ template <> struct ObjectTraits<LoadedModuleTraceFormat> {
|
||||
|
||||
out.mapRequired("arch", contents.Arch);
|
||||
|
||||
out.mapRequired("strictMemorySafety", contents.StrictMemorySafety);
|
||||
|
||||
// The 'swiftmodules' key is kept for backwards compatibility.
|
||||
std::vector<std::string> moduleNames;
|
||||
for (auto &m : contents.SwiftModules)
|
||||
@@ -643,7 +649,8 @@ static void computeSwiftModuleTraceInfo(
|
||||
/*IsImportedDirectly=*/
|
||||
isImportedDirectly,
|
||||
/*SupportsLibraryEvolution=*/
|
||||
depMod->isResilient()});
|
||||
depMod->isResilient(),
|
||||
depMod->strictMemorySafety()});
|
||||
buffer.clear();
|
||||
|
||||
continue;
|
||||
@@ -782,8 +789,9 @@ bool swift::emitLoadedModuleTraceIfNeeded(ModuleDecl *mainModule,
|
||||
LoadedModuleTraceFormat trace = {
|
||||
/*version=*/LoadedModuleTraceFormat::CurrentVersion,
|
||||
/*name=*/mainModule->getName(),
|
||||
/*arch=*/ctxt.LangOpts.Target.getArchName().str(), swiftModules,
|
||||
swiftMacros};
|
||||
/*arch=*/ctxt.LangOpts.Target.getArchName().str(),
|
||||
mainModule ? mainModule->strictMemorySafety() : false,
|
||||
swiftModules, swiftMacros};
|
||||
|
||||
// raw_fd_ostream is unbuffered, and we may have multiple processes writing,
|
||||
// so first write to memory and then dump the buffer to the trace file.
|
||||
|
||||
Reference in New Issue
Block a user