xref: /minix3/external/bsd/llvm/dist/clang/tools/scan-build/ccc-analyzer (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1#!/usr/bin/env perl
2#
3#                     The LLVM Compiler Infrastructure
4#
5# This file is distributed under the University of Illinois Open Source
6# License. See LICENSE.TXT for details.
7#
8##===----------------------------------------------------------------------===##
9#
10#  A script designed to interpose between the build system and gcc.  It invokes
11#  both gcc and the static analyzer.
12#
13##===----------------------------------------------------------------------===##
14
15use strict;
16use warnings;
17use FindBin;
18use Cwd qw/ getcwd abs_path /;
19use File::Temp qw/ tempfile /;
20use File::Path qw / mkpath /;
21use File::Basename;
22use Text::ParseWords;
23
24##===----------------------------------------------------------------------===##
25# Compiler command setup.
26##===----------------------------------------------------------------------===##
27
28# Search in the PATH if the compiler exists
29sub SearchInPath {
30    my $file = shift;
31    foreach my $dir (split (':', $ENV{PATH})) {
32        if (-x "$dir/$file") {
33            return 1;
34        }
35    }
36    return 0;
37}
38
39my $Compiler;
40my $Clang;
41my $DefaultCCompiler;
42my $DefaultCXXCompiler;
43my $IsCXX;
44
45# If on OSX, use xcrun to determine the SDK root.
46my $UseXCRUN = 0;
47
48if (`uname -a` =~ m/Darwin/) {
49  $DefaultCCompiler = 'clang';
50  $DefaultCXXCompiler = 'clang++';
51  # Older versions of OSX do not have xcrun to
52  # query the SDK location.
53  if (-x "/usr/bin/xcrun") {
54    $UseXCRUN = 1;
55  }
56} else {
57  $DefaultCCompiler = 'gcc';
58  $DefaultCXXCompiler = 'g++';
59}
60
61if ($FindBin::Script =~ /c\+\+-analyzer/) {
62  $Compiler = $ENV{'CCC_CXX'};
63  if (!defined $Compiler || (! -x $Compiler && ! SearchInPath($Compiler))) { $Compiler = $DefaultCXXCompiler; }
64
65  $Clang = $ENV{'CLANG_CXX'};
66  if (!defined $Clang || ! -x $Clang) { $Clang = 'clang++'; }
67
68  $IsCXX = 1
69}
70else {
71  $Compiler = $ENV{'CCC_CC'};
72  if (!defined $Compiler || (! -x $Compiler && ! SearchInPath($Compiler))) { $Compiler = $DefaultCCompiler; }
73
74  $Clang = $ENV{'CLANG'};
75  if (!defined $Clang || ! -x $Clang) { $Clang = 'clang'; }
76
77  $IsCXX = 0
78}
79
80##===----------------------------------------------------------------------===##
81# Cleanup.
82##===----------------------------------------------------------------------===##
83
84my $ReportFailures = $ENV{'CCC_REPORT_FAILURES'};
85if (!defined $ReportFailures) { $ReportFailures = 1; }
86
87my $CleanupFile;
88my $ResultFile;
89
90# Remove any stale files at exit.
91END {
92  if (defined $ResultFile && -z $ResultFile) {
93    unlink($ResultFile);
94  }
95  if (defined $CleanupFile) {
96    unlink($CleanupFile);
97  }
98}
99
100##----------------------------------------------------------------------------##
101#  Process Clang Crashes.
102##----------------------------------------------------------------------------##
103
104sub GetPPExt {
105  my $Lang = shift;
106  if ($Lang =~ /objective-c\+\+/) { return ".mii" };
107  if ($Lang =~ /objective-c/) { return ".mi"; }
108  if ($Lang =~ /c\+\+/) { return ".ii"; }
109  return ".i";
110}
111
112# Set this to 1 if we want to include 'parser rejects' files.
113my $IncludeParserRejects = 0;
114my $ParserRejects = "Parser Rejects";
115my $AttributeIgnored = "Attribute Ignored";
116my $OtherError = "Other Error";
117
118sub ProcessClangFailure {
119  my ($Clang, $Lang, $file, $Args, $HtmlDir, $ErrorType, $ofile) = @_;
120  my $Dir = "$HtmlDir/failures";
121  mkpath $Dir;
122
123  my $prefix = "clang_crash";
124  if ($ErrorType eq $ParserRejects) {
125    $prefix = "clang_parser_rejects";
126  }
127  elsif ($ErrorType eq $AttributeIgnored) {
128    $prefix = "clang_attribute_ignored";
129  }
130  elsif ($ErrorType eq $OtherError) {
131    $prefix = "clang_other_error";
132  }
133
134  # Generate the preprocessed file with Clang.
135  my ($PPH, $PPFile) = tempfile( $prefix . "_XXXXXX",
136                                 SUFFIX => GetPPExt($Lang),
137                                 DIR => $Dir);
138  system $Clang, @$Args, "-E", "-o", $PPFile;
139  close ($PPH);
140
141  # Create the info file.
142  open (OUT, ">", "$PPFile.info.txt") or die "Cannot open $PPFile.info.txt\n";
143  print OUT abs_path($file), "\n";
144  print OUT "$ErrorType\n";
145  print OUT "@$Args\n";
146  close OUT;
147  `uname -a >> $PPFile.info.txt 2>&1`;
148  `$Compiler -v >> $PPFile.info.txt 2>&1`;
149  rename($ofile, "$PPFile.stderr.txt");
150  return (basename $PPFile);
151}
152
153##----------------------------------------------------------------------------##
154#  Running the analyzer.
155##----------------------------------------------------------------------------##
156
157sub GetCCArgs {
158  my $mode = shift;
159  my $Args = shift;
160
161  pipe (FROM_CHILD, TO_PARENT);
162  my $pid = fork();
163  if ($pid == 0) {
164    close FROM_CHILD;
165    open(STDOUT,">&", \*TO_PARENT);
166    open(STDERR,">&", \*TO_PARENT);
167    exec $Clang, "-###", $mode, @$Args;
168  }
169  close(TO_PARENT);
170  my $line;
171  while (<FROM_CHILD>) {
172    next if (!/\s"?-cc1"?\s/);
173    $line = $_;
174  }
175
176  waitpid($pid,0);
177  close(FROM_CHILD);
178
179  die "could not find clang line\n" if (!defined $line);
180  # Strip leading and trailing whitespace characters.
181  $line =~ s/^\s+|\s+$//g;
182  my @items = quotewords('\s+', 0, $line);
183  my $cmd = shift @items;
184  die "cannot find 'clang' in 'clang' command\n" if (!($cmd =~ /clang/));
185  return \@items;
186}
187
188sub Analyze {
189  my ($Clang, $OriginalArgs, $AnalyzeArgs, $Lang, $Output, $Verbose, $HtmlDir,
190      $file) = @_;
191
192  my @Args = @$OriginalArgs;
193  my $Cmd;
194  my @CmdArgs;
195  my @CmdArgsSansAnalyses;
196
197  if ($Lang =~ /header/) {
198    exit 0 if (!defined ($Output));
199    $Cmd = 'cp';
200    push @CmdArgs, $file;
201    # Remove the PCH extension.
202    $Output =~ s/[.]gch$//;
203    push @CmdArgs, $Output;
204    @CmdArgsSansAnalyses = @CmdArgs;
205  }
206  else {
207    $Cmd = $Clang;
208
209    # Create arguments for doing regular parsing.
210    my $SyntaxArgs = GetCCArgs("-fsyntax-only", \@Args);
211    @CmdArgsSansAnalyses = @$SyntaxArgs;
212
213    # Create arguments for doing static analysis.
214    if (defined $ResultFile) {
215      push @Args, '-o', $ResultFile;
216    }
217    elsif (defined $HtmlDir) {
218      push @Args, '-o', $HtmlDir;
219    }
220    if ($Verbose) {
221      push @Args, "-Xclang", "-analyzer-display-progress";
222    }
223
224    foreach my $arg (@$AnalyzeArgs) {
225      push @Args, "-Xclang", $arg;
226    }
227
228    # Display Ubiviz graph?
229    if (defined $ENV{'CCC_UBI'}) {
230      push @Args, "-Xclang", "-analyzer-viz-egraph-ubigraph";
231    }
232
233    my $AnalysisArgs = GetCCArgs("--analyze", \@Args);
234    @CmdArgs = @$AnalysisArgs;
235  }
236
237  my @PrintArgs;
238  my $dir;
239
240  if ($Verbose) {
241    $dir = getcwd();
242    print STDERR "\n[LOCATION]: $dir\n";
243    push @PrintArgs,"'$Cmd'";
244    foreach my $arg (@CmdArgs) {
245        push @PrintArgs,"\'$arg\'";
246    }
247  }
248  if ($Verbose == 1) {
249    # We MUST print to stderr.  Some clients use the stdout output of
250    # gcc for various purposes.
251    print STDERR join(' ', @PrintArgs);
252    print STDERR "\n";
253  }
254  elsif ($Verbose == 2) {
255    print STDERR "#SHELL (cd '$dir' && @PrintArgs)\n";
256  }
257
258  # Capture the STDERR of clang and send it to a temporary file.
259  # Capture the STDOUT of clang and reroute it to ccc-analyzer's STDERR.
260  # We save the output file in the 'crashes' directory if clang encounters
261  # any problems with the file.
262  pipe (FROM_CHILD, TO_PARENT);
263  my $pid = fork();
264  if ($pid == 0) {
265    close FROM_CHILD;
266    open(STDOUT,">&", \*TO_PARENT);
267    open(STDERR,">&", \*TO_PARENT);
268    exec $Cmd, @CmdArgs;
269  }
270
271  close TO_PARENT;
272  my ($ofh, $ofile) = tempfile("clang_output_XXXXXX", DIR => $HtmlDir);
273
274  while (<FROM_CHILD>) {
275    print $ofh $_;
276    print STDERR $_;
277  }
278  close $ofh;
279
280  waitpid($pid,0);
281  close(FROM_CHILD);
282  my $Result = $?;
283
284  # Did the command die because of a signal?
285  if ($ReportFailures) {
286    if ($Result & 127 and $Cmd eq $Clang and defined $HtmlDir) {
287      ProcessClangFailure($Clang, $Lang, $file, \@CmdArgsSansAnalyses,
288                          $HtmlDir, "Crash", $ofile);
289    }
290    elsif ($Result) {
291      if ($IncludeParserRejects && !($file =~/conftest/)) {
292        ProcessClangFailure($Clang, $Lang, $file, \@CmdArgsSansAnalyses,
293                            $HtmlDir, $ParserRejects, $ofile);
294      } else {
295        ProcessClangFailure($Clang, $Lang, $file, \@CmdArgsSansAnalyses,
296                            $HtmlDir, $OtherError, $ofile);
297      }
298    }
299    else {
300      # Check if there were any unhandled attributes.
301      if (open(CHILD, $ofile)) {
302        my %attributes_not_handled;
303
304        # Don't flag warnings about the following attributes that we
305        # know are currently not supported by Clang.
306        $attributes_not_handled{"cdecl"} = 1;
307
308        my $ppfile;
309        while (<CHILD>) {
310          next if (! /warning: '([^\']+)' attribute ignored/);
311
312          # Have we already spotted this unhandled attribute?
313          next if (defined $attributes_not_handled{$1});
314          $attributes_not_handled{$1} = 1;
315
316          # Get the name of the attribute file.
317          my $dir = "$HtmlDir/failures";
318          my $afile = "$dir/attribute_ignored_$1.txt";
319
320          # Only create another preprocessed file if the attribute file
321          # doesn't exist yet.
322          next if (-e $afile);
323
324          # Add this file to the list of files that contained this attribute.
325          # Generate a preprocessed file if we haven't already.
326          if (!(defined $ppfile)) {
327            $ppfile = ProcessClangFailure($Clang, $Lang, $file,
328                                          \@CmdArgsSansAnalyses,
329                                          $HtmlDir, $AttributeIgnored, $ofile);
330          }
331
332          mkpath $dir;
333          open(AFILE, ">$afile");
334          print AFILE "$ppfile\n";
335          close(AFILE);
336        }
337        close CHILD;
338      }
339    }
340  }
341
342  unlink($ofile);
343}
344
345##----------------------------------------------------------------------------##
346#  Lookup tables.
347##----------------------------------------------------------------------------##
348
349my %CompileOptionMap = (
350  '-nostdinc' => 0,
351  '-include' => 1,
352  '-idirafter' => 1,
353  '-imacros' => 1,
354  '-iprefix' => 1,
355  '-iquote' => 1,
356  '-isystem' => 1,
357  '-iwithprefix' => 1,
358  '-iwithprefixbefore' => 1
359);
360
361my %LinkerOptionMap = (
362  '-framework' => 1,
363  '-fobjc-link-runtime' => 0
364);
365
366my %CompilerLinkerOptionMap = (
367  '-Wwrite-strings' => 0,
368  '-ftrapv-handler' => 1, # specifically call out separated -f flag
369  '-mios-simulator-version-min' => 0, # This really has 1 argument, but always has '='
370  '-isysroot' => 1,
371  '-arch' => 1,
372  '-m32' => 0,
373  '-m64' => 0,
374  '-stdlib' => 0, # This is really a 1 argument, but always has '='
375  '--sysroot' => 1,
376  '-target' => 1,
377  '-v' => 0,
378  '-mmacosx-version-min' => 0, # This is really a 1 argument, but always has '='
379  '-miphoneos-version-min' => 0 # This is really a 1 argument, but always has '='
380);
381
382my %IgnoredOptionMap = (
383  '-MT' => 1,  # Ignore these preprocessor options.
384  '-MF' => 1,
385
386  '-fsyntax-only' => 0,
387  '-save-temps' => 0,
388  '-install_name' => 1,
389  '-exported_symbols_list' => 1,
390  '-current_version' => 1,
391  '-compatibility_version' => 1,
392  '-init' => 1,
393  '-e' => 1,
394  '-seg1addr' => 1,
395  '-bundle_loader' => 1,
396  '-multiply_defined' => 1,
397  '-sectorder' => 3,
398  '--param' => 1,
399  '-u' => 1,
400  '--serialize-diagnostics' => 1
401);
402
403my %LangMap = (
404  'c'   => $IsCXX ? 'c++' : 'c',
405  'cp'  => 'c++',
406  'cpp' => 'c++',
407  'cxx' => 'c++',
408  'txx' => 'c++',
409  'cc'  => 'c++',
410  'C'   => 'c++',
411  'ii'  => 'c++-cpp-output',
412  'i'   => $IsCXX ? 'c++-cpp-output' : 'c-cpp-output',
413  'm'   => 'objective-c',
414  'mi'  => 'objective-c-cpp-output',
415  'mm'  => 'objective-c++',
416  'mii' => 'objective-c++-cpp-output',
417);
418
419my %UniqueOptions = (
420  '-isysroot' => 0
421);
422
423##----------------------------------------------------------------------------##
424# Languages accepted.
425##----------------------------------------------------------------------------##
426
427my %LangsAccepted = (
428  "objective-c" => 1,
429  "c" => 1,
430  "c++" => 1,
431  "objective-c++" => 1,
432  "c-cpp-output" => 1,
433  "objective-c-cpp-output" => 1,
434  "c++-cpp-output" => 1
435);
436
437##----------------------------------------------------------------------------##
438#  Main Logic.
439##----------------------------------------------------------------------------##
440
441my $Action = 'link';
442my @CompileOpts;
443my @LinkOpts;
444my @Files;
445my $Lang;
446my $Output;
447my %Uniqued;
448
449# Forward arguments to gcc.
450my $Status = system($Compiler,@ARGV);
451if (defined $ENV{'CCC_ANALYZER_LOG'}) {
452  print STDERR "$Compiler @ARGV\n";
453}
454if ($Status) { exit($Status >> 8); }
455
456# Get the analysis options.
457my $Analyses = $ENV{'CCC_ANALYZER_ANALYSIS'};
458
459# Get the plugins to load.
460my $Plugins = $ENV{'CCC_ANALYZER_PLUGINS'};
461
462# Get the store model.
463my $StoreModel = $ENV{'CCC_ANALYZER_STORE_MODEL'};
464
465# Get the constraints engine.
466my $ConstraintsModel = $ENV{'CCC_ANALYZER_CONSTRAINTS_MODEL'};
467
468#Get the internal stats setting.
469my $InternalStats = $ENV{'CCC_ANALYZER_INTERNAL_STATS'};
470
471# Get the output format.
472my $OutputFormat = $ENV{'CCC_ANALYZER_OUTPUT_FORMAT'};
473if (!defined $OutputFormat) { $OutputFormat = "html"; }
474
475# Get the config options.
476my $ConfigOptions = $ENV{'CCC_ANALYZER_CONFIG'};
477
478# Determine the level of verbosity.
479my $Verbose = 0;
480if (defined $ENV{'CCC_ANALYZER_VERBOSE'}) { $Verbose = 1; }
481if (defined $ENV{'CCC_ANALYZER_LOG'}) { $Verbose = 2; }
482
483# Get the HTML output directory.
484my $HtmlDir = $ENV{'CCC_ANALYZER_HTML'};
485
486my %DisabledArchs = ('ppc' => 1, 'ppc64' => 1);
487my %ArchsSeen;
488my $HadArch = 0;
489my $HasSDK = 0;
490
491# Process the arguments.
492foreach (my $i = 0; $i < scalar(@ARGV); ++$i) {
493  my $Arg = $ARGV[$i];
494  my ($ArgKey) = split /=/,$Arg,2;
495
496  # Modes ccc-analyzer supports
497  if ($Arg =~ /^-(E|MM?)$/) { $Action = 'preprocess'; }
498  elsif ($Arg eq '-c') { $Action = 'compile'; }
499  elsif ($Arg =~ /^-print-prog-name/) { exit 0; }
500
501  # Specially handle duplicate cases of -arch
502  if ($Arg eq "-arch") {
503    my $arch = $ARGV[$i+1];
504    # We don't want to process 'ppc' because of Clang's lack of support
505    # for Altivec (also some #defines won't likely be defined correctly, etc.)
506    if (!(defined $DisabledArchs{$arch})) { $ArchsSeen{$arch} = 1; }
507    $HadArch = 1;
508    ++$i;
509    next;
510  }
511
512  # On OSX/iOS, record if an SDK path was specified.  This
513  # is innocuous for other platforms, so the check just happens.
514  if ($Arg =~ /^-isysroot/) {
515    $HasSDK = 1;
516  }
517
518  # Options with possible arguments that should pass through to compiler.
519  if (defined $CompileOptionMap{$ArgKey}) {
520    my $Cnt = $CompileOptionMap{$ArgKey};
521    push @CompileOpts,$Arg;
522    while ($Cnt > 0) { ++$i; --$Cnt; push @CompileOpts, $ARGV[$i]; }
523    next;
524  }
525  # Handle the case where there isn't a space after -iquote
526  if ($Arg =~ /^-iquote.*/) {
527    push @CompileOpts,$Arg;
528    next;
529  }
530
531  # Options with possible arguments that should pass through to linker.
532  if (defined $LinkerOptionMap{$ArgKey}) {
533    my $Cnt = $LinkerOptionMap{$ArgKey};
534    push @LinkOpts,$Arg;
535    while ($Cnt > 0) { ++$i; --$Cnt; push @LinkOpts, $ARGV[$i]; }
536    next;
537  }
538
539  # Options with possible arguments that should pass through to both compiler
540  # and the linker.
541  if (defined $CompilerLinkerOptionMap{$ArgKey}) {
542    my $Cnt = $CompilerLinkerOptionMap{$ArgKey};
543
544    # Check if this is an option that should have a unique value, and if so
545    # determine if the value was checked before.
546    if ($UniqueOptions{$Arg}) {
547      if (defined $Uniqued{$Arg}) {
548        $i += $Cnt;
549        next;
550      }
551      $Uniqued{$Arg} = 1;
552    }
553
554    push @CompileOpts,$Arg;
555    push @LinkOpts,$Arg;
556
557    while ($Cnt > 0) {
558      ++$i; --$Cnt;
559      push @CompileOpts, $ARGV[$i];
560      push @LinkOpts, $ARGV[$i];
561    }
562    next;
563  }
564
565  # Ignored options.
566  if (defined $IgnoredOptionMap{$ArgKey}) {
567    my $Cnt = $IgnoredOptionMap{$ArgKey};
568    while ($Cnt > 0) {
569      ++$i; --$Cnt;
570    }
571    next;
572  }
573
574  # Compile mode flags.
575  if ($Arg =~ /^-[D,I,U](.*)$/) {
576    my $Tmp = $Arg;
577    if ($1 eq '') {
578      # FIXME: Check if we are going off the end.
579      ++$i;
580      $Tmp = $Arg . $ARGV[$i];
581    }
582    push @CompileOpts,$Tmp;
583    next;
584  }
585
586  if ($Arg =~ /^-m.*/) {
587    push @CompileOpts,$Arg;
588    next;
589  }
590
591  # Language.
592  if ($Arg eq '-x') {
593    $Lang = $ARGV[$i+1];
594    ++$i; next;
595  }
596
597  # Output file.
598  if ($Arg eq '-o') {
599    ++$i;
600    $Output = $ARGV[$i];
601    next;
602  }
603
604  # Get the link mode.
605  if ($Arg =~ /^-[l,L,O]/) {
606    if ($Arg eq '-O') { push @LinkOpts,'-O1'; }
607    elsif ($Arg eq '-Os') { push @LinkOpts,'-O2'; }
608    else { push @LinkOpts,$Arg; }
609
610    # Must pass this along for the __OPTIMIZE__ macro
611    if ($Arg =~ /^-O/) { push @CompileOpts,$Arg; }
612    next;
613  }
614
615  if ($Arg =~ /^-std=/) {
616    push @CompileOpts,$Arg;
617    next;
618  }
619
620  # Get the compiler/link mode.
621  if ($Arg =~ /^-F(.+)$/) {
622    my $Tmp = $Arg;
623    if ($1 eq '') {
624      # FIXME: Check if we are going off the end.
625      ++$i;
626      $Tmp = $Arg . $ARGV[$i];
627    }
628    push @CompileOpts,$Tmp;
629    push @LinkOpts,$Tmp;
630    next;
631  }
632
633  # Input files.
634  if ($Arg eq '-filelist') {
635    # FIXME: Make sure we aren't walking off the end.
636    open(IN, $ARGV[$i+1]);
637    while (<IN>) { s/\015?\012//; push @Files,$_; }
638    close(IN);
639    ++$i;
640    next;
641  }
642
643  if ($Arg =~ /^-f/) {
644    push @CompileOpts,$Arg;
645    push @LinkOpts,$Arg;
646    next;
647  }
648
649  # Handle -Wno-.  We don't care about extra warnings, but
650  # we should suppress ones that we don't want to see.
651  if ($Arg =~ /^-Wno-/) {
652    push @CompileOpts, $Arg;
653    next;
654  }
655
656  if (!($Arg =~ /^-/)) {
657    push @Files, $Arg;
658    next;
659  }
660}
661
662# If we are on OSX and have an installation where the
663# default SDK is inferred by xcrun use xcrun to infer
664# the SDK.
665if (not $HasSDK and $UseXCRUN) {
666  my $sdk = `/usr/bin/xcrun --show-sdk-path -sdk macosx`;
667  chomp $sdk;
668  push @CompileOpts, "-isysroot", $sdk;
669}
670
671if ($Action eq 'compile' or $Action eq 'link') {
672  my @Archs = keys %ArchsSeen;
673  # Skip the file if we don't support the architectures specified.
674  exit 0 if ($HadArch && scalar(@Archs) == 0);
675
676  foreach my $file (@Files) {
677    # Determine the language for the file.
678    my $FileLang = $Lang;
679
680    if (!defined($FileLang)) {
681      # Infer the language from the extension.
682      if ($file =~ /[.]([^.]+)$/) {
683        $FileLang = $LangMap{$1};
684      }
685    }
686
687    # FileLang still not defined?  Skip the file.
688    next if (!defined $FileLang);
689
690    # Language not accepted?
691    next if (!defined $LangsAccepted{$FileLang});
692
693    my @CmdArgs;
694    my @AnalyzeArgs;
695
696    if ($FileLang ne 'unknown') {
697      push @CmdArgs, '-x', $FileLang;
698    }
699
700    if (defined $StoreModel) {
701      push @AnalyzeArgs, "-analyzer-store=$StoreModel";
702    }
703
704    if (defined $ConstraintsModel) {
705      push @AnalyzeArgs, "-analyzer-constraints=$ConstraintsModel";
706    }
707
708    if (defined $InternalStats) {
709      push @AnalyzeArgs, "-analyzer-stats";
710    }
711
712    if (defined $Analyses) {
713      push @AnalyzeArgs, split '\s+', $Analyses;
714    }
715
716    if (defined $Plugins) {
717      push @AnalyzeArgs, split '\s+', $Plugins;
718    }
719
720    if (defined $OutputFormat) {
721      push @AnalyzeArgs, "-analyzer-output=" . $OutputFormat;
722      if ($OutputFormat =~ /plist/) {
723        # Change "Output" to be a file.
724        my ($h, $f) = tempfile("report-XXXXXX", SUFFIX => ".plist",
725                               DIR => $HtmlDir);
726        $ResultFile = $f;
727        # If the HtmlDir is not set, we should clean up the plist files.
728        if (!defined $HtmlDir || -z $HtmlDir) {
729          $CleanupFile = $f;
730        }
731      }
732    }
733    if (defined $ConfigOptions) {
734      push @AnalyzeArgs, split '\s+', $ConfigOptions;
735    }
736
737    push @CmdArgs, @CompileOpts;
738    push @CmdArgs, $file;
739
740    if (scalar @Archs) {
741      foreach my $arch (@Archs) {
742        my @NewArgs;
743        push @NewArgs, '-arch', $arch;
744        push @NewArgs, @CmdArgs;
745        Analyze($Clang, \@NewArgs, \@AnalyzeArgs, $FileLang, $Output,
746                $Verbose, $HtmlDir, $file);
747      }
748    }
749    else {
750      Analyze($Clang, \@CmdArgs, \@AnalyzeArgs, $FileLang, $Output,
751              $Verbose, $HtmlDir, $file);
752    }
753  }
754}
755
756exit($Status >> 8);
757