@@ -1086,7 +1086,7 @@ static void printASTValidationError(
1086
1086
llvm::raw_ostream &errs,
1087
1087
const swift::serialization::ValidationInfo &ast_info,
1088
1088
const swift::serialization::ExtendedValidationInfo &ext_ast_info,
1089
- Module & module , StringRef module_buf, bool invalid_name,
1089
+ StringRef module_name , StringRef module_buf, bool invalid_name,
1090
1090
bool invalid_size) {
1091
1091
const char *error = getImportFailureString (ast_info.status );
1092
1092
errs << " AST validation error" ;
@@ -1111,9 +1111,9 @@ static void printASTValidationError(
1111
1111
- SDK path: {7}
1112
1112
- Clang Importer Options:
1113
1113
)" ,
1114
- ast_info.name , module . GetSpecificationDescription () , error,
1115
- ast_info.targetTriple , ast_info.shortVersion , ast_info. bytes ,
1116
- module_buf. size (), ext_ast_info.getSDKPath ());
1114
+ ast_info.name , module_name , error, ast_info. targetTriple ,
1115
+ ast_info.shortVersion , ast_info.bytes , module_buf. size () ,
1116
+ ext_ast_info.getSDKPath ());
1117
1117
for (StringRef ExtraOpt : ext_ast_info.getExtraClangImporterOptions ())
1118
1118
LLDB_LOG (log, " -- {0}" , ExtraOpt);
1119
1119
}
@@ -1171,21 +1171,16 @@ static std::string GetPluginServerForSDK(llvm::StringRef sdk_path) {
1171
1171
// / invocation with the concatenated search paths from the blobs.
1172
1172
// / \returns true if an error was encountered.
1173
1173
static bool DeserializeAllCompilerFlags (swift::CompilerInvocation &invocation,
1174
- Module &module ,
1174
+ llvm::StringRef module_name,
1175
+ llvm::ArrayRef<StringRef> buffers,
1176
+ const PathMappingList &path_map,
1175
1177
bool discover_implicit_search_paths,
1176
1178
const std::string &m_description,
1177
1179
llvm::raw_ostream &error,
1178
1180
bool &got_serialized_options,
1179
1181
bool &found_swift_modules) {
1180
1182
bool found_validation_errors = false ;
1181
1183
got_serialized_options = false ;
1182
- auto ast_file_datas = module .GetASTData (eLanguageTypeSwift);
1183
- LOG_PRINTF (GetLog (LLDBLog::Types), " Found %d AST file data entries." ,
1184
- (int )ast_file_datas.size ());
1185
-
1186
- // If no N_AST symbols exist, this is not an error.
1187
- if (ast_file_datas.empty ())
1188
- return false ;
1189
1184
1190
1185
auto &search_path_options = invocation.getSearchPathOptions ();
1191
1186
auto get_override_server = [&](llvm::StringRef plugin_path) -> std::string {
@@ -1258,9 +1253,7 @@ static bool DeserializeAllCompilerFlags(swift::CompilerInvocation &invocation,
1258
1253
1259
1254
// An AST section consists of one or more AST modules, optionally
1260
1255
// with headers. Iterate over all AST modules.
1261
- for (auto ast_file_data_sp : ast_file_datas) {
1262
- llvm::StringRef buf ((const char *)ast_file_data_sp->GetBytes (),
1263
- ast_file_data_sp->GetByteSize ());
1256
+ for (auto buf : buffers) {
1264
1257
swift::serialization::ValidationInfo info;
1265
1258
for (; !buf.empty (); buf = buf.substr (info.bytes )) {
1266
1259
llvm::SmallVector<swift::serialization::SearchPath> searchPaths;
@@ -1275,8 +1268,8 @@ static bool DeserializeAllCompilerFlags(swift::CompilerInvocation &invocation,
1275
1268
if (invalid_ast || invalid_size || invalid_name) {
1276
1269
// Validation errors are diagnosed, but not fatal for the context.
1277
1270
found_validation_errors = true ;
1278
- printASTValidationError (error, info, extended_validation_info, module ,
1279
- buf, invalid_name, invalid_size);
1271
+ printASTValidationError (error, info, extended_validation_info,
1272
+ module_name, buf, invalid_name, invalid_size);
1280
1273
// If there's a size error, quit the loop early, otherwise try the next.
1281
1274
if (invalid_size)
1282
1275
break ;
@@ -1288,8 +1281,7 @@ static bool DeserializeAllCompilerFlags(swift::CompilerInvocation &invocation,
1288
1281
1289
1282
auto remap = [&](const std::string &path) {
1290
1283
ConstString remapped;
1291
- if (module .GetSourceMappingList ().RemapPath (ConstString (path),
1292
- remapped))
1284
+ if (path_map.RemapPath (ConstString (path), remapped))
1293
1285
return remapped.GetStringRef ().str ();
1294
1286
return path;
1295
1287
};
@@ -1881,13 +1873,28 @@ SwiftASTContext::CreateInstance(lldb::LanguageType language, Module &module,
1881
1873
llvm::raw_svector_ostream errs (error);
1882
1874
// Implicit search paths will be discoverd by ValidateSecionModules().
1883
1875
bool discover_implicit_search_paths = false ;
1884
- if (DeserializeAllCompilerFlags (swift_ast_sp->GetCompilerInvocation (),
1885
- module , discover_implicit_search_paths,
1886
- m_description, errs, got_serialized_options,
1887
- found_swift_modules)) {
1888
- // Validation errors are not fatal for the context.
1889
- swift_ast_sp->AddDiagnostic (eDiagnosticSeverityError, errs.str ());
1890
- }
1876
+
1877
+ auto ast_file_datas = module .GetASTData (eLanguageTypeSwift);
1878
+ std::string module_name = module .GetSpecificationDescription ();
1879
+ LOG_PRINTF (GetLog (LLDBLog::Types), " Found %d AST file data entries in %s." ,
1880
+ (int )ast_file_datas.size (), module_name.c_str ());
1881
+ std::vector<llvm::StringRef> buffers;
1882
+ for (auto &data : ast_file_datas)
1883
+ if (data)
1884
+ buffers.push_back (
1885
+ StringRef ((const char *)data->GetBytes (), data->GetByteSize ()));
1886
+
1887
+ // If no N_AST symbols exist, this is not an error.
1888
+ if (!buffers.empty ())
1889
+ if (DeserializeAllCompilerFlags (
1890
+ swift_ast_sp->GetCompilerInvocation (),
1891
+ module_name, buffers,
1892
+ module .GetSourceMappingList (), discover_implicit_search_paths,
1893
+ m_description, errs, got_serialized_options,
1894
+ found_swift_modules)) {
1895
+ // Validation errors are not fatal for the context.
1896
+ swift_ast_sp->AddDiagnostic (eDiagnosticSeverityError, errs.str ());
1897
+ }
1891
1898
1892
1899
llvm::StringRef serialized_triple =
1893
1900
swift_ast_sp->GetCompilerInvocation ().getTargetTriple ();
@@ -2194,13 +2201,27 @@ static void ProcessModule(
2194
2201
llvm::SmallString<0 > error;
2195
2202
llvm::raw_svector_ostream errs (error);
2196
2203
swift::CompilerInvocation invocation;
2197
- if (DeserializeAllCompilerFlags (
2198
- invocation, *module_sp, discover_implicit_search_paths, m_description,
2199
- errs, got_serialized_options, found_swift_modules)) {
2200
- // TODO: After removing DeserializeAllCompilerFlags from
2201
- // CreateInstance(per-Module), errs will need to be
2202
- // collected here and surfaced.
2203
- }
2204
+
2205
+ auto ast_file_datas = module_sp->GetASTData (eLanguageTypeSwift);
2206
+ std::string module_name = module_sp->GetSpecificationDescription ();
2207
+ LOG_PRINTF (GetLog (LLDBLog::Types), " Found %d AST file data entries in %s." ,
2208
+ (int )ast_file_datas.size (), module_name.c_str ());
2209
+ std::vector<llvm::StringRef> buffers;
2210
+ for (auto &data : ast_file_datas)
2211
+ if (data)
2212
+ buffers.push_back (
2213
+ StringRef ((const char *)data->GetBytes (), data->GetByteSize ()));
2214
+
2215
+ // If no N_AST symbols exist, this is not an error.
2216
+ if (!buffers.empty ())
2217
+ if (DeserializeAllCompilerFlags (
2218
+ invocation, module_name, buffers, module_sp->GetSourceMappingList (),
2219
+ discover_implicit_search_paths, m_description, errs,
2220
+ got_serialized_options, found_swift_modules)) {
2221
+ // TODO: After removing DeserializeAllCompilerFlags from
2222
+ // CreateInstance(per-Module), errs will need to be
2223
+ // collected here and surfaced.
2224
+ }
2204
2225
2205
2226
// Copy the interesting deserialized flags to the out parameters.
2206
2227
const auto &opts = invocation.getSearchPathOptions ();
0 commit comments