@@ -196,13 +196,14 @@ int main(int argc, const char **argv) {
196
196
197
197
auto reportError = [argv](Error E) {
198
198
logAllUnhandledErrors (std::move (E), WithColor::error (errs (), argv[0 ]));
199
- exit ( 1 ) ;
199
+ return 1 ;
200
200
};
201
201
202
202
auto doWork = [&](std::function<llvm::Error ()> Work) {
203
203
if (llvm::Error Err = Work ()) {
204
- reportError (std::move (Err));
204
+ return reportError (std::move (Err));
205
205
}
206
+ return 0 ;
206
207
};
207
208
208
209
auto warningOS = [argv]() -> raw_ostream & {
@@ -223,14 +224,14 @@ int main(int argc, const char **argv) {
223
224
if (!Objcopy)
224
225
Objcopy = sys::findProgramByName (" llvm-objcopy" );
225
226
if (!Objcopy)
226
- reportError (createStringError (Objcopy. getError (),
227
- " unable to find 'llvm-objcopy' in path" ));
227
+ return reportError (createStringError (
228
+ Objcopy. getError (), " unable to find 'llvm-objcopy' in path" ));
228
229
else
229
230
BundlerConfig.ObjcopyPath = *Objcopy;
230
231
231
232
if (InputFileNames.getNumOccurrences () != 0 &&
232
233
InputFileNamesDeprecatedOpt.getNumOccurrences () != 0 ) {
233
- reportError (createStringError (
234
+ return reportError (createStringError (
234
235
errc::invalid_argument,
235
236
" -inputs and -input cannot be used together, use only -input instead" ));
236
237
}
@@ -246,9 +247,9 @@ int main(int argc, const char **argv) {
246
247
247
248
if (OutputFileNames.getNumOccurrences () != 0 &&
248
249
OutputFileNamesDeprecatedOpt.getNumOccurrences () != 0 ) {
249
- reportError (createStringError (errc::invalid_argument,
250
- " -outputs and -output cannot be used "
251
- " together, use only -output instead" ));
250
+ return reportError (createStringError (errc::invalid_argument,
251
+ " -outputs and -output cannot be used "
252
+ " together, use only -output instead" ));
252
253
}
253
254
254
255
if (OutputFileNamesDeprecatedOpt.size ()) {
@@ -262,77 +263,77 @@ int main(int argc, const char **argv) {
262
263
263
264
if (ListBundleIDs) {
264
265
if (Unbundle) {
265
- reportError (
266
+ return reportError (
266
267
createStringError (errc::invalid_argument,
267
268
" -unbundle and -list cannot be used together" ));
268
269
}
269
270
if (InputFileNames.size () != 1 ) {
270
- reportError (createStringError (errc::invalid_argument,
271
- " only one input file supported for -list" ));
271
+ return reportError (createStringError (
272
+ errc::invalid_argument, " only one input file supported for -list" ));
272
273
}
273
274
if (OutputFileNames.size ()) {
274
- reportError (createStringError (errc::invalid_argument,
275
- " -outputs option is invalid for -list" ));
275
+ return reportError (createStringError (
276
+ errc::invalid_argument, " -outputs option is invalid for -list" ));
276
277
}
277
278
if (TargetNames.size ()) {
278
- reportError (createStringError (errc::invalid_argument,
279
- " -targets option is invalid for -list" ));
279
+ return reportError (createStringError (
280
+ errc::invalid_argument, " -targets option is invalid for -list" ));
280
281
}
281
282
282
- doWork ([&]() { return OffloadBundler::ListBundleIDsInFile (
283
- InputFileNames.front (),
284
- BundlerConfig); } );
285
- return 0 ;
283
+ return doWork ([&]() {
284
+ return OffloadBundler::ListBundleIDsInFile ( InputFileNames.front (),
285
+ BundlerConfig );
286
+ }) ;
286
287
}
287
288
288
289
if (BundlerConfig.CheckInputArchive ) {
289
290
if (!Unbundle) {
290
- reportError (createStringError (errc::invalid_argument,
291
- " -check-input-archive cannot be used while "
292
- " bundling" ));
291
+ return reportError (createStringError (
292
+ errc::invalid_argument, " -check-input-archive cannot be used while "
293
+ " bundling" ));
293
294
}
294
295
if (Unbundle && BundlerConfig.FilesType != " a" ) {
295
- reportError (createStringError (errc::invalid_argument,
296
- " -check-input-archive can only be used for "
297
- " unbundling archives (-type=a)" ));
296
+ return reportError (createStringError (
297
+ errc::invalid_argument, " -check-input-archive can only be used for "
298
+ " unbundling archives (-type=a)" ));
298
299
}
299
300
}
300
301
301
302
if (OutputFileNames.size () == 0 ) {
302
- reportError (
303
+ return reportError (
303
304
createStringError (errc::invalid_argument, " no output file specified!" ));
304
305
}
305
306
306
307
if (TargetNames.getNumOccurrences () == 0 ) {
307
- reportError (createStringError (
308
+ return reportError (createStringError (
308
309
errc::invalid_argument,
309
310
" for the --targets option: must be specified at least once!" ));
310
311
}
311
312
312
313
if (Unbundle) {
313
314
if (InputFileNames.size () != 1 ) {
314
- reportError (createStringError (
315
+ return reportError (createStringError (
315
316
errc::invalid_argument,
316
317
" only one input file supported in unbundling mode" ));
317
318
}
318
319
if (OutputFileNames.size () != TargetNames.size ()) {
319
- reportError (createStringError (errc::invalid_argument,
320
- " number of output files and targets should "
321
- " match in unbundling mode" ));
320
+ return reportError (createStringError (
321
+ errc::invalid_argument, " number of output files and targets should "
322
+ " match in unbundling mode" ));
322
323
}
323
324
} else {
324
325
if (BundlerConfig.FilesType == " a" ) {
325
- reportError (createStringError (errc::invalid_argument,
326
- " Archive files are only supported "
327
- " for unbundling" ));
326
+ return reportError (createStringError (errc::invalid_argument,
327
+ " Archive files are only supported "
328
+ " for unbundling" ));
328
329
}
329
330
if (OutputFileNames.size () != 1 ) {
330
- reportError ( createStringError (
331
- errc::invalid_argument,
332
- " only one output file supported in bundling mode" ));
331
+ return reportError (
332
+ createStringError ( errc::invalid_argument,
333
+ " only one output file supported in bundling mode" ));
333
334
}
334
335
if (InputFileNames.size () != TargetNames.size ()) {
335
- reportError (createStringError (
336
+ return reportError (createStringError (
336
337
errc::invalid_argument,
337
338
" number of input files and targets should match in bundling mode" ));
338
339
}
@@ -349,9 +350,9 @@ int main(int argc, const char **argv) {
349
350
// Standardize target names to include env field
350
351
std::vector<std::string> StandardizedTargetNames;
351
352
for (StringRef Target : TargetNames) {
352
- if (ParsedTargets.contains (Target)) {
353
- reportError (createStringError (errc::invalid_argument,
354
- " Duplicate targets are not allowed" ));
353
+ if (! ParsedTargets.insert (Target). second ) {
354
+ return reportError (createStringError (
355
+ errc::invalid_argument, " Duplicate targets are not allowed" ));
355
356
}
356
357
ParsedTargets.insert (Target);
357
358
@@ -369,7 +370,7 @@ int main(int argc, const char **argv) {
369
370
Msg << " , unknown offloading kind '" << OffloadInfo.OffloadKind << " '" ;
370
371
if (!TripleIsValid)
371
372
Msg << " , unknown target triple '" << OffloadInfo.Triple .str () << " '" ;
372
- reportError (createStringError (errc::invalid_argument, Msg.str ()));
373
+ return reportError (createStringError (errc::invalid_argument, Msg.str ()));
373
374
}
374
375
375
376
TargetIDs[OffloadInfo.OffloadKind .str () + " -" + OffloadInfo.Triple .str ()]
@@ -396,7 +397,7 @@ int main(int argc, const char **argv) {
396
397
Msg << " Cannot bundle inputs with conflicting targets: '"
397
398
<< TargetID.first + " -" + ConflictingTID->first << " ' and '"
398
399
<< TargetID.first + " -" + ConflictingTID->second << " '" ;
399
- reportError (createStringError (errc::invalid_argument, Msg.str ()));
400
+ return reportError (createStringError (errc::invalid_argument, Msg.str ()));
400
401
}
401
402
}
402
403
@@ -409,14 +410,14 @@ int main(int argc, const char **argv) {
409
410
// treat missing host triple as error if we do unbundling.
410
411
if ((Unbundle && HostTargetNum > 1 ) ||
411
412
(!Unbundle && HostTargetNum != 1 && !BundlerConfig.AllowNoHost )) {
412
- reportError (createStringError (errc::invalid_argument,
413
- " expecting exactly one host target but got " +
414
- Twine (HostTargetNum)));
413
+ return reportError (createStringError (
414
+ errc::invalid_argument,
415
+ " expecting exactly one host target but got " + Twine (HostTargetNum)));
415
416
}
416
417
417
418
OffloadBundler Bundler (BundlerConfig);
418
419
419
- doWork ([&]() {
420
+ return doWork ([&]() {
420
421
if (Unbundle) {
421
422
if (BundlerConfig.FilesType == " a" )
422
423
return Bundler.UnbundleArchive ();
@@ -425,5 +426,4 @@ int main(int argc, const char **argv) {
425
426
} else
426
427
return Bundler.BundleFiles ();
427
428
});
428
- return 0 ;
429
429
}
0 commit comments