Coverage Report

Created: 2020-09-19 12:23

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/tools/clang-format/ClangFormat.cpp
Line
Count
Source (jump to first uncovered line)
1
//===-- clang-format/ClangFormat.cpp - Clang format tool ------------------===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
///
9
/// \file
10
/// This file implements a clang-format tool that automatically formats
11
/// (fragments of) C++ code.
12
///
13
//===----------------------------------------------------------------------===//
14
15
#include "clang/Basic/Diagnostic.h"
16
#include "clang/Basic/DiagnosticOptions.h"
17
#include "clang/Basic/FileManager.h"
18
#include "clang/Basic/SourceManager.h"
19
#include "clang/Basic/Version.h"
20
#include "clang/Format/Format.h"
21
#include "clang/Rewrite/Core/Rewriter.h"
22
#include "llvm/Support/CommandLine.h"
23
#include "llvm/Support/FileSystem.h"
24
#include "llvm/Support/InitLLVM.h"
25
#include "llvm/Support/Process.h"
26
27
using namespace llvm;
28
using clang::tooling::Replacements;
29
30
static cl::opt<bool> Help("h", cl::desc("Alias for -help"), cl::Hidden);
31
32
// Mark all our options with this category, everything else (except for -version
33
// and -help) will be hidden.
34
static cl::OptionCategory ClangFormatCategory("Clang-format options");
35
36
static cl::list<unsigned>
37
    Offsets("offset",
38
            cl::desc("Format a range starting at this byte offset.\n"
39
                     "Multiple ranges can be formatted by specifying\n"
40
                     "several -offset and -length pairs.\n"
41
                     "Can only be used with one input file."),
42
            cl::cat(ClangFormatCategory));
43
static cl::list<unsigned>
44
    Lengths("length",
45
            cl::desc("Format a range of this length (in bytes).\n"
46
                     "Multiple ranges can be formatted by specifying\n"
47
                     "several -offset and -length pairs.\n"
48
                     "When only a single -offset is specified without\n"
49
                     "-length, clang-format will format up to the end\n"
50
                     "of the file.\n"
51
                     "Can only be used with one input file."),
52
            cl::cat(ClangFormatCategory));
53
static cl::list<std::string>
54
    LineRanges("lines",
55
               cl::desc("<start line>:<end line> - format a range of\n"
56
                        "lines (both 1-based).\n"
57
                        "Multiple ranges can be formatted by specifying\n"
58
                        "several -lines arguments.\n"
59
                        "Can't be used with -offset and -length.\n"
60
                        "Can only be used with one input file."),
61
               cl::cat(ClangFormatCategory));
62
static cl::opt<std::string>
63
    Style("style", cl::desc(clang::format::StyleOptionHelpDescription),
64
          cl::init(clang::format::DefaultFormatStyle),
65
          cl::cat(ClangFormatCategory));
66
static cl::opt<std::string>
67
    FallbackStyle("fallback-style",
68
                  cl::desc("The name of the predefined style used as a\n"
69
                           "fallback in case clang-format is invoked with\n"
70
                           "-style=file, but can not find the .clang-format\n"
71
                           "file to use.\n"
72
                           "Use -fallback-style=none to skip formatting."),
73
                  cl::init(clang::format::DefaultFallbackStyle),
74
                  cl::cat(ClangFormatCategory));
75
76
static cl::opt<std::string> AssumeFileName(
77
    "assume-filename",
78
    cl::desc("Override filename used to determine the language.\n"
79
             "When reading from stdin, clang-format assumes this\n"
80
             "filename to determine the language."),
81
    cl::init("<stdin>"), cl::cat(ClangFormatCategory));
82
83
static cl::opt<bool> Inplace("i",
84
                             cl::desc("Inplace edit <file>s, if specified."),
85
                             cl::cat(ClangFormatCategory));
86
87
static cl::opt<bool> OutputXML("output-replacements-xml",
88
                               cl::desc("Output replacements as XML."),
89
                               cl::cat(ClangFormatCategory));
90
static cl::opt<bool>
91
    DumpConfig("dump-config",
92
               cl::desc("Dump configuration options to stdout and exit.\n"
93
                        "Can be used with -style option."),
94
               cl::cat(ClangFormatCategory));
95
static cl::opt<unsigned>
96
    Cursor("cursor",
97
           cl::desc("The position of the cursor when invoking\n"
98
                    "clang-format from an editor integration"),
99
           cl::init(0), cl::cat(ClangFormatCategory));
100
101
static cl::opt<bool> SortIncludes(
102
    "sort-includes",
103
    cl::desc("If set, overrides the include sorting behavior determined by the "
104
             "SortIncludes style flag"),
105
    cl::cat(ClangFormatCategory));
106
107
// using the full param name as Wno-error probably won't be a common use case in
108
// clang-format
109
static cl::opt<bool> AllowUnknownOptions(
110
    "Wno-error=unknown",
111
    cl::desc("If set, unknown format options are only warned about.\n"
112
             "This can be used to enable formatting, even if the\n"
113
             "configuration contains unknown (newer) options.\n"
114
             "Use with caution, as this might lead to dramatically\n"
115
             "differing format depending on an option being\n"
116
             "supported or not."),
117
    cl::init(false), cl::cat(ClangFormatCategory));
118
119
static cl::opt<bool>
120
    Verbose("verbose", cl::desc("If set, shows the list of processed files"),
121
            cl::cat(ClangFormatCategory));
122
123
// Use --dry-run to match other LLVM tools when you mean do it but don't
124
// actually do it
125
static cl::opt<bool>
126
    DryRun("dry-run",
127
           cl::desc("If set, do not actually make the formatting changes"),
128
           cl::cat(ClangFormatCategory));
129
130
// Use -n as a common command as an alias for --dry-run. (git and make use -n)
131
static cl::alias DryRunShort("n", cl::desc("Alias for --dry-run"),
132
                             cl::cat(ClangFormatCategory), cl::aliasopt(DryRun),
133
                             cl::NotHidden);
134
135
// Emulate being able to turn on/off the warning.
136
static cl::opt<bool>
137
    WarnFormat("Wclang-format-violations",
138
               cl::desc("Warnings about individual formatting changes needed. "
139
                        "Used only with --dry-run or -n"),
140
               cl::init(true), cl::cat(ClangFormatCategory), cl::Hidden);
141
142
static cl::opt<bool>
143
    NoWarnFormat("Wno-clang-format-violations",
144
                 cl::desc("Do not warn about individual formatting changes "
145
                          "needed. Used only with --dry-run or -n"),
146
                 cl::init(false), cl::cat(ClangFormatCategory), cl::Hidden);
147
148
static cl::opt<unsigned> ErrorLimit(
149
    "ferror-limit",
150
    cl::desc("Set the maximum number of clang-format errors to emit before "
151
             "stopping (0 = no limit). Used only with --dry-run or -n"),
152
    cl::init(0), cl::cat(ClangFormatCategory));
153
154
static cl::opt<bool>
155
    WarningsAsErrors("Werror",
156
                     cl::desc("If set, changes formatting warnings to errors"),
157
                     cl::cat(ClangFormatCategory));
158
159
static cl::opt<bool>
160
    ShowColors("fcolor-diagnostics",
161
               cl::desc("If set, and on a color-capable terminal controls "
162
                        "whether or not to print diagnostics in color"),
163
               cl::init(true), cl::cat(ClangFormatCategory), cl::Hidden);
164
165
static cl::opt<bool>
166
    NoShowColors("fno-color-diagnostics",
167
                 cl::desc("If set, and on a color-capable terminal controls "
168
                          "whether or not to print diagnostics in color"),
169
                 cl::init(false), cl::cat(ClangFormatCategory), cl::Hidden);
170
171
static cl::list<std::string> FileNames(cl::Positional, cl::desc("[<file> ...]"),
172
                                       cl::cat(ClangFormatCategory));
173
174
namespace clang {
175
namespace format {
176
177
static FileID createInMemoryFile(StringRef FileName, MemoryBuffer *Source,
178
                                 SourceManager &Sources, FileManager &Files,
179
70
                                 llvm::vfs::InMemoryFileSystem *MemFS) {
180
70
  MemFS->addFileNoOwn(FileName, 0, Source);
181
70
  auto File = Files.getFile(FileName);
182
70
  return Sources.createFileID(File ? *File : 
nullptr0
, SourceLocation(),
183
70
                              SrcMgr::C_User);
184
70
}
185
186
// Parses <start line>:<end line> input to a pair of line numbers.
187
// Returns true on error.
188
static bool parseLineRange(StringRef Input, unsigned &FromLine,
189
4
                           unsigned &ToLine) {
190
4
  std::pair<StringRef, StringRef> LineRange = Input.split(':');
191
4
  return LineRange.first.getAsInteger(0, FromLine) ||
192
4
         LineRange.second.getAsInteger(0, ToLine);
193
4
}
194
195
static bool fillRanges(MemoryBuffer *Code,
196
38
                       std::vector<tooling::Range> &Ranges) {
197
38
  IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem(
198
38
      new llvm::vfs::InMemoryFileSystem);
199
38
  FileManager Files(FileSystemOptions(), InMemoryFileSystem);
200
38
  DiagnosticsEngine Diagnostics(
201
38
      IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs),
202
38
      new DiagnosticOptions);
203
38
  SourceManager Sources(Diagnostics, Files);
204
38
  FileID ID = createInMemoryFile("<irrelevant>", Code, Sources, Files,
205
38
                                 InMemoryFileSystem.get());
206
38
  if (!LineRanges.empty()) {
207
3
    if (!Offsets.empty() || !Lengths.empty()) {
208
0
      errs() << "error: cannot use -lines with -offset/-length\n";
209
0
      return true;
210
0
    }
211
3
212
7
    
for (unsigned i = 0, e = LineRanges.size(); 3
i < e;
++i4
) {
213
4
      unsigned FromLine, ToLine;
214
4
      if (parseLineRange(LineRanges[i], FromLine, ToLine)) {
215
0
        errs() << "error: invalid <start line>:<end line> pair\n";
216
0
        return true;
217
0
      }
218
4
      if (FromLine > ToLine) {
219
0
        errs() << "error: start line should be less than end line\n";
220
0
        return true;
221
0
      }
222
4
      SourceLocation Start = Sources.translateLineCol(ID, FromLine, 1);
223
4
      SourceLocation End = Sources.translateLineCol(ID, ToLine, UINT_MAX);
224
4
      if (Start.isInvalid() || End.isInvalid())
225
0
        return true;
226
4
      unsigned Offset = Sources.getFileOffset(Start);
227
4
      unsigned Length = Sources.getFileOffset(End) - Offset;
228
4
      Ranges.push_back(tooling::Range(Offset, Length));
229
4
    }
230
3
    return false;
231
35
  }
232
35
233
35
  if (Offsets.empty())
234
32
    Offsets.push_back(0);
235
35
  if (Offsets.size() != Lengths.size() &&
236
34
      !(Offsets.size() == 1 && Lengths.empty())) {
237
0
    errs() << "error: number of -offset and -length arguments must match.\n";
238
0
    return true;
239
0
  }
240
71
  
for (unsigned i = 0, e = Offsets.size(); 35
i != e;
++i36
) {
241
36
    if (Offsets[i] >= Code->getBufferSize()) {
242
0
      errs() << "error: offset " << Offsets[i] << " is outside the file\n";
243
0
      return true;
244
0
    }
245
36
    SourceLocation Start =
246
36
        Sources.getLocForStartOfFile(ID).getLocWithOffset(Offsets[i]);
247
36
    SourceLocation End;
248
36
    if (i < Lengths.size()) {
249
2
      if (Offsets[i] + Lengths[i] > Code->getBufferSize()) {
250
0
        errs() << "error: invalid length " << Lengths[i]
251
0
               << ", offset + length (" << Offsets[i] + Lengths[i]
252
0
               << ") is outside the file.\n";
253
0
        return true;
254
0
      }
255
2
      End = Start.getLocWithOffset(Lengths[i]);
256
34
    } else {
257
34
      End = Sources.getLocForEndOfFile(ID);
258
34
    }
259
36
    unsigned Offset = Sources.getFileOffset(Start);
260
36
    unsigned Length = Sources.getFileOffset(End) - Offset;
261
36
    Ranges.push_back(tooling::Range(Offset, Length));
262
36
  }
263
35
  return false;
264
35
}
265
266
3
static void outputReplacementXML(StringRef Text) {
267
  // FIXME: When we sort includes, we need to make sure the stream is correct
268
  // utf-8.
269
3
  size_t From = 0;
270
3
  size_t Index;
271
7
  while ((Index = Text.find_first_of("\n\r<&", From)) != StringRef::npos) {
272
4
    outs() << Text.substr(From, Index - From);
273
4
    switch (Text[Index]) {
274
2
    case '\n':
275
2
      outs() << "&#10;";
276
2
      break;
277
0
    case '\r':
278
0
      outs() << "&#13;";
279
0
      break;
280
2
    case '<':
281
2
      outs() << "&lt;";
282
2
      break;
283
0
    case '&':
284
0
      outs() << "&amp;";
285
0
      break;
286
0
    default:
287
0
      llvm_unreachable("Unexpected character encountered!");
288
4
    }
289
4
    From = Index + 1;
290
4
  }
291
3
  outs() << Text.substr(From);
292
3
}
293
294
1
static void outputReplacementsXML(const Replacements &Replaces) {
295
3
  for (const auto &R : Replaces) {
296
3
    outs() << "<replacement "
297
3
           << "offset='" << R.getOffset() << "' "
298
3
           << "length='" << R.getLength() << "'>";
299
3
    outputReplacementXML(R.getReplacementText());
300
3
    outs() << "</replacement>\n";
301
3
  }
302
1
}
303
304
static bool
305
emitReplacementWarnings(const Replacements &Replaces, StringRef AssumedFileName,
306
2
                        const std::unique_ptr<llvm::MemoryBuffer> &Code) {
307
2
  if (Replaces.empty())
308
0
    return false;
309
2
310
2
  unsigned Errors = 0;
311
2
  if (WarnFormat && !NoWarnFormat) {
312
2
    llvm::SourceMgr Mgr;
313
2
    const char *StartBuf = Code->getBufferStart();
314
2
315
2
    Mgr.AddNewSourceBuffer(
316
2
        MemoryBuffer::getMemBuffer(StartBuf, AssumedFileName), SMLoc());
317
2
    for (const auto &R : Replaces) {
318
2
      SMDiagnostic Diag = Mgr.GetMessage(
319
2
          SMLoc::getFromPointer(StartBuf + R.getOffset()),
320
0
          WarningsAsErrors ? SourceMgr::DiagKind::DK_Error
321
2
                           : SourceMgr::DiagKind::DK_Warning,
322
2
          "code should be clang-formatted [-Wclang-format-violations]");
323
2
324
2
      Diag.print(nullptr, llvm::errs(), (ShowColors && !NoShowColors));
325
2
      if (ErrorLimit && 
++Errors >= ErrorLimit0
)
326
0
        break;
327
2
    }
328
2
  }
329
2
  return WarningsAsErrors;
330
2
}
331
332
static void outputXML(const Replacements &Replaces,
333
                      const Replacements &FormatChanges,
334
                      const FormattingAttemptStatus &Status,
335
                      const cl::opt<unsigned> &Cursor,
336
1
                      unsigned CursorPosition) {
337
1
  outs() << "<?xml version='1.0'?>\n<replacements "
338
1
            "xml:space='preserve' incomplete_format='"
339
1
         << (Status.FormatComplete ? "false" : 
"true"0
) << "'";
340
1
  if (!Status.FormatComplete)
341
0
    outs() << " line='" << Status.Line << "'";
342
1
  outs() << ">\n";
343
1
  if (Cursor.getNumOccurrences() != 0)
344
0
    outs() << "<cursor>" << FormatChanges.getShiftedCodePosition(CursorPosition)
345
0
           << "</cursor>\n";
346
1
347
1
  outputReplacementsXML(Replaces);
348
1
  outs() << "</replacements>\n";
349
1
}
350
351
// Returns true on error.
352
38
static bool format(StringRef FileName) {
353
38
  if (!OutputXML && 
Inplace37
&&
FileName == "-"5
) {
354
0
    errs() << "error: cannot use -i when reading from stdin.\n";
355
0
    return false;
356
0
  }
357
  // On Windows, overwriting a file with an open file mapping doesn't work,
358
  // so read the whole file into memory when formatting in-place.
359
38
  ErrorOr<std::unique_ptr<MemoryBuffer>> CodeOrErr =
360
38
      !OutputXML && 
Inplace37
?
MemoryBuffer::getFileAsStream(FileName)5
361
33
                            : MemoryBuffer::getFileOrSTDIN(FileName);
362
38
  if (std::error_code EC = CodeOrErr.getError()) {
363
0
    errs() << EC.message() << "\n";
364
0
    return true;
365
0
  }
366
38
  std::unique_ptr<llvm::MemoryBuffer> Code = std::move(CodeOrErr.get());
367
38
  if (Code->getBufferSize() == 0)
368
0
    return false; // Empty files are formatted correctly.
369
38
370
38
  StringRef BufStr = Code->getBuffer();
371
38
372
38
  const char *InvalidBOM = SrcMgr::ContentCache::getInvalidBOM(BufStr);
373
38
374
38
  if (InvalidBOM) {
375
0
    errs() << "error: encoding with unsupported byte order mark \""
376
0
           << InvalidBOM << "\" detected";
377
0
    if (FileName != "-")
378
0
      errs() << " in file '" << FileName << "'";
379
0
    errs() << ".\n";
380
0
    return true;
381
0
  }
382
38
383
38
  std::vector<tooling::Range> Ranges;
384
38
  if (fillRanges(Code.get(), Ranges))
385
0
    return true;
386
38
  StringRef AssumedFileName = (FileName == "-") ? 
AssumeFileName14
:
FileName24
;
387
38
  if (AssumedFileName.empty()) {
388
0
    llvm::errs() << "error: empty filenames are not allowed\n";
389
0
    return true;
390
0
  }
391
38
392
38
  llvm::Expected<FormatStyle> FormatStyle =
393
38
      getStyle(Style, AssumedFileName, FallbackStyle, Code->getBuffer(),
394
38
               nullptr, AllowUnknownOptions.getValue());
395
38
  if (!FormatStyle) {
396
3
    llvm::errs() << llvm::toString(FormatStyle.takeError()) << "\n";
397
3
    return true;
398
3
  }
399
35
400
35
  if (SortIncludes.getNumOccurrences() != 0)
401
3
    FormatStyle->SortIncludes = SortIncludes;
402
35
  unsigned CursorPosition = Cursor;
403
35
  Replacements Replaces = sortIncludes(*FormatStyle, Code->getBuffer(), Ranges,
404
35
                                       AssumedFileName, &CursorPosition);
405
35
  auto ChangedCode = tooling::applyAllReplacements(Code->getBuffer(), Replaces);
406
35
  if (!ChangedCode) {
407
0
    llvm::errs() << llvm::toString(ChangedCode.takeError()) << "\n";
408
0
    return true;
409
0
  }
410
  // Get new affected ranges after sorting `#includes`.
411
35
  Ranges = tooling::calculateRangesAfterReplacements(Replaces, Ranges);
412
35
  FormattingAttemptStatus Status;
413
35
  Replacements FormatChanges =
414
35
      reformat(*FormatStyle, *ChangedCode, Ranges, AssumedFileName, &Status);
415
35
  Replaces = Replaces.merge(FormatChanges);
416
35
  if (OutputXML || 
DryRun34
) {
417
3
    if (DryRun) {
418
2
      return emitReplacementWarnings(Replaces, AssumedFileName, Code);
419
1
    } else {
420
1
      outputXML(Replaces, FormatChanges, Status, Cursor, CursorPosition);
421
1
    }
422
32
  } else {
423
32
    IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem(
424
32
        new llvm::vfs::InMemoryFileSystem);
425
32
    FileManager Files(FileSystemOptions(), InMemoryFileSystem);
426
32
    DiagnosticsEngine Diagnostics(
427
32
        IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs),
428
32
        new DiagnosticOptions);
429
32
    SourceManager Sources(Diagnostics, Files);
430
32
    FileID ID = createInMemoryFile(AssumedFileName, Code.get(), Sources, Files,
431
32
                                   InMemoryFileSystem.get());
432
32
    Rewriter Rewrite(Sources, LangOptions());
433
32
    tooling::applyAllReplacements(Replaces, Rewrite);
434
32
    if (Inplace) {
435
3
      if (Rewrite.overwriteChangedFiles())
436
0
        return true;
437
29
    } else {
438
29
      if (Cursor.getNumOccurrences() != 0) {
439
2
        outs() << "{ \"Cursor\": "
440
2
               << FormatChanges.getShiftedCodePosition(CursorPosition)
441
2
               << ", \"IncompleteFormat\": "
442
1
               << (Status.FormatComplete ? "false" : "true");
443
2
        if (!Status.FormatComplete)
444
1
          outs() << ", \"Line\": " << Status.Line;
445
2
        outs() << " }\n";
446
2
      }
447
29
      Rewrite.getEditBuffer(ID).write(outs());
448
29
    }
449
32
  }
450
33
  return false;
451
35
}
452
453
} // namespace format
454
} // namespace clang
455
456
0
static void PrintVersion(raw_ostream &OS) {
457
0
  OS << clang::getClangToolFullVersion("clang-format") << '\n';
458
0
}
459
460
// Dump the configuration.
461
5
static int dumpConfig() {
462
5
  StringRef FileName;
463
5
  std::unique_ptr<llvm::MemoryBuffer> Code;
464
5
  if (FileNames.empty()) {
465
    // We can't read the code to detect the language if there's no
466
    // file name, so leave Code empty here.
467
0
    FileName = AssumeFileName;
468
5
  } else {
469
    // Read in the code in case the filename alone isn't enough to
470
    // detect the language.
471
5
    ErrorOr<std::unique_ptr<MemoryBuffer>> CodeOrErr =
472
5
        MemoryBuffer::getFileOrSTDIN(FileNames[0]);
473
5
    if (std::error_code EC = CodeOrErr.getError()) {
474
0
      llvm::errs() << EC.message() << "\n";
475
0
      return 1;
476
0
    }
477
5
    FileName = (FileNames[0] == "-") ? 
AssumeFileName0
: FileNames[0];
478
5
    Code = std::move(CodeOrErr.get());
479
5
  }
480
5
  llvm::Expected<clang::format::FormatStyle> FormatStyle =
481
5
      clang::format::getStyle(Style, FileName, FallbackStyle,
482
5
                              Code ? Code->getBuffer() : 
""0
);
483
5
  if (!FormatStyle) {
484
0
    llvm::errs() << llvm::toString(FormatStyle.takeError()) << "\n";
485
0
    return 1;
486
0
  }
487
5
  std::string Config = clang::format::configurationAsText(*FormatStyle);
488
5
  outs() << Config << "\n";
489
5
  return 0;
490
5
}
491
492
43
int main(int argc, const char **argv) {
493
43
  llvm::InitLLVM X(argc, argv);
494
43
495
43
  cl::HideUnrelatedOptions(ClangFormatCategory);
496
43
497
43
  cl::SetVersionPrinter(PrintVersion);
498
43
  cl::ParseCommandLineOptions(
499
43
      argc, argv,
500
43
      "A tool to format C/C++/Java/JavaScript/Objective-C/Protobuf/C# code.\n\n"
501
43
      "If no arguments are specified, it formats the code from standard input\n"
502
43
      "and writes the result to the standard output.\n"
503
43
      "If <file>s are given, it reformats the files. If -i is specified\n"
504
43
      "together with <file>s, the files are edited in-place. Otherwise, the\n"
505
43
      "result is written to the standard output.\n");
506
43
507
43
  if (Help) {
508
0
    cl::PrintHelpMessage();
509
0
    return 0;
510
0
  }
511
43
512
43
  if (DumpConfig) {
513
5
    return dumpConfig();
514
5
  }
515
38
516
38
  bool Error = false;
517
38
  if (FileNames.empty()) {
518
14
    Error = clang::format::format("-");
519
13
    return Error ? 
11
: 0;
520
14
  }
521
24
  if (FileNames.size() != 1 &&
522
4
      (!Offsets.empty() || 
!Lengths.empty()3
||
!LineRanges.empty()3
)) {
523
2
    errs() << "error: -offset, -length and -lines can only be used for "
524
2
              "single file.\n";
525
2
    return 1;
526
2
  }
527
24
  
for (const auto &FileName : FileNames)22
{
528
24
    if (Verbose)
529
2
      errs() << "Formatting " << FileName << "\n";
530
24
    Error |= clang::format::format(FileName);
531
24
  }
532
20
  return Error ? 
12
: 0;
533
22
}