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 15 use strict; 16 use warnings; 17 use FindBin; 18 use Cwd qw/ getcwd abs_path /; 19 use File::Temp qw/ tempfile /; 20 use File::Path qw / mkpath /; 21 use File::Basename; 22 use Text::ParseWords; 23 24 ##===----------------------------------------------------------------------===## 25 # Compiler command setup. 26 ##===----------------------------------------------------------------------===## 27 28 # Search in the PATH if the compiler exists 29 sub 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 39 my $Compiler; 40 my $Clang; 41 my $DefaultCCompiler; 42 my $DefaultCXXCompiler; 43 my $IsCXX; 44 45 # If on OSX, use xcrun to determine the SDK root. 46 my $UseXCRUN = 0; 47 48 if (`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 61 if ($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 } 70 else { 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 84 my $ReportFailures = $ENV{'CCC_REPORT_FAILURES'}; 85 if (!defined $ReportFailures) { $ReportFailures = 1; } 86 87 my $CleanupFile; 88 my $ResultFile; 89 90 # Remove any stale files at exit. 91 END { 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 104 sub 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. 113 my $IncludeParserRejects = 0; 114 my $ParserRejects = "Parser Rejects"; 115 my $AttributeIgnored = "Attribute Ignored"; 116 my $OtherError = "Other Error"; 117 118 sub 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 157 sub 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 188 sub 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 349 my %CompileOptionMap = ( 350 '-nostdinc' => 0, 351 '-include' => 1, 352 '-idirafter' => 1, 353 '-imacros' => 1, 354 '-iprefix' => 1, 355 '-iquote' => 1, 356 '-iwithprefix' => 1, 357 '-iwithprefixbefore' => 1 358 ); 359 360 my %LinkerOptionMap = ( 361 '-framework' => 1, 362 '-fobjc-link-runtime' => 0 363 ); 364 365 my %CompilerLinkerOptionMap = ( 366 '-Wwrite-strings' => 0, 367 '-ftrapv-handler' => 1, # specifically call out separated -f flag 368 '-mios-simulator-version-min' => 0, # This really has 1 argument, but always has '=' 369 '-isysroot' => 1, 370 '-arch' => 1, 371 '-m32' => 0, 372 '-m64' => 0, 373 '-stdlib' => 0, # This is really a 1 argument, but always has '=' 374 '--sysroot' => 1, 375 '-target' => 1, 376 '-v' => 0, 377 '-mmacosx-version-min' => 0, # This is really a 1 argument, but always has '=' 378 '-miphoneos-version-min' => 0 # This is really a 1 argument, but always has '=' 379 ); 380 381 my %IgnoredOptionMap = ( 382 '-MT' => 1, # Ignore these preprocessor options. 383 '-MF' => 1, 384 385 '-fsyntax-only' => 0, 386 '-save-temps' => 0, 387 '-install_name' => 1, 388 '-exported_symbols_list' => 1, 389 '-current_version' => 1, 390 '-compatibility_version' => 1, 391 '-init' => 1, 392 '-e' => 1, 393 '-seg1addr' => 1, 394 '-bundle_loader' => 1, 395 '-multiply_defined' => 1, 396 '-sectorder' => 3, 397 '--param' => 1, 398 '-u' => 1, 399 '--serialize-diagnostics' => 1 400 ); 401 402 my %LangMap = ( 403 'c' => $IsCXX ? 'c++' : 'c', 404 'cp' => 'c++', 405 'cpp' => 'c++', 406 'cxx' => 'c++', 407 'txx' => 'c++', 408 'cc' => 'c++', 409 'C' => 'c++', 410 'ii' => 'c++-cpp-output', 411 'i' => $IsCXX ? 'c++-cpp-output' : 'c-cpp-output', 412 'm' => 'objective-c', 413 'mi' => 'objective-c-cpp-output', 414 'mm' => 'objective-c++', 415 'mii' => 'objective-c++-cpp-output', 416 ); 417 418 my %UniqueOptions = ( 419 '-isysroot' => 0 420 ); 421 422 ##----------------------------------------------------------------------------## 423 # Languages accepted. 424 ##----------------------------------------------------------------------------## 425 426 my %LangsAccepted = ( 427 "objective-c" => 1, 428 "c" => 1, 429 "c++" => 1, 430 "objective-c++" => 1, 431 "c-cpp-output" => 1, 432 "objective-c-cpp-output" => 1, 433 "c++-cpp-output" => 1 434 ); 435 436 ##----------------------------------------------------------------------------## 437 # Main Logic. 438 ##----------------------------------------------------------------------------## 439 440 my $Action = 'link'; 441 my @CompileOpts; 442 my @LinkOpts; 443 my @Files; 444 my $Lang; 445 my $Output; 446 my %Uniqued; 447 448 # Forward arguments to gcc. 449 my $Status = system($Compiler,@ARGV); 450 if (defined $ENV{'CCC_ANALYZER_LOG'}) { 451 print STDERR "$Compiler @ARGV\n"; 452 } 453 if ($Status) { exit($Status >> 8); } 454 455 # Get the analysis options. 456 my $Analyses = $ENV{'CCC_ANALYZER_ANALYSIS'}; 457 458 # Get the plugins to load. 459 my $Plugins = $ENV{'CCC_ANALYZER_PLUGINS'}; 460 461 # Get the store model. 462 my $StoreModel = $ENV{'CCC_ANALYZER_STORE_MODEL'}; 463 464 # Get the constraints engine. 465 my $ConstraintsModel = $ENV{'CCC_ANALYZER_CONSTRAINTS_MODEL'}; 466 467 #Get the internal stats setting. 468 my $InternalStats = $ENV{'CCC_ANALYZER_INTERNAL_STATS'}; 469 470 # Get the output format. 471 my $OutputFormat = $ENV{'CCC_ANALYZER_OUTPUT_FORMAT'}; 472 if (!defined $OutputFormat) { $OutputFormat = "html"; } 473 474 # Get the config options. 475 my $ConfigOptions = $ENV{'CCC_ANALYZER_CONFIG'}; 476 477 # Determine the level of verbosity. 478 my $Verbose = 0; 479 if (defined $ENV{'CCC_ANALYZER_VERBOSE'}) { $Verbose = 1; } 480 if (defined $ENV{'CCC_ANALYZER_LOG'}) { $Verbose = 2; } 481 482 # Get the HTML output directory. 483 my $HtmlDir = $ENV{'CCC_ANALYZER_HTML'}; 484 485 my %DisabledArchs = ('ppc' => 1, 'ppc64' => 1); 486 my %ArchsSeen; 487 my $HadArch = 0; 488 my $HasSDK = 0; 489 490 # Process the arguments. 491 foreach (my $i = 0; $i < scalar(@ARGV); ++$i) { 492 my $Arg = $ARGV[$i]; 493 my ($ArgKey) = split /=/,$Arg,2; 494 495 # Be friendly to "" in the argument list. 496 if (!defined($ArgKey)) { 497 next; 498 } 499 500 # Modes ccc-analyzer supports 501 if ($Arg =~ /^-(E|MM?)$/) { $Action = 'preprocess'; } 502 elsif ($Arg eq '-c') { $Action = 'compile'; } 503 elsif ($Arg =~ /^-print-prog-name/) { exit 0; } 504 505 # Specially handle duplicate cases of -arch 506 if ($Arg eq "-arch") { 507 my $arch = $ARGV[$i+1]; 508 # We don't want to process 'ppc' because of Clang's lack of support 509 # for Altivec (also some #defines won't likely be defined correctly, etc.) 510 if (!(defined $DisabledArchs{$arch})) { $ArchsSeen{$arch} = 1; } 511 $HadArch = 1; 512 ++$i; 513 next; 514 } 515 516 # On OSX/iOS, record if an SDK path was specified. This 517 # is innocuous for other platforms, so the check just happens. 518 if ($Arg =~ /^-isysroot/) { 519 $HasSDK = 1; 520 } 521 522 # Options with possible arguments that should pass through to compiler. 523 if (defined $CompileOptionMap{$ArgKey}) { 524 my $Cnt = $CompileOptionMap{$ArgKey}; 525 push @CompileOpts,$Arg; 526 while ($Cnt > 0) { ++$i; --$Cnt; push @CompileOpts, $ARGV[$i]; } 527 next; 528 } 529 # Handle the case where there isn't a space after -iquote 530 if ($Arg =~ /^-iquote.*/) { 531 push @CompileOpts,$Arg; 532 next; 533 } 534 535 # Options with possible arguments that should pass through to linker. 536 if (defined $LinkerOptionMap{$ArgKey}) { 537 my $Cnt = $LinkerOptionMap{$ArgKey}; 538 push @LinkOpts,$Arg; 539 while ($Cnt > 0) { ++$i; --$Cnt; push @LinkOpts, $ARGV[$i]; } 540 next; 541 } 542 543 # Options with possible arguments that should pass through to both compiler 544 # and the linker. 545 if (defined $CompilerLinkerOptionMap{$ArgKey}) { 546 my $Cnt = $CompilerLinkerOptionMap{$ArgKey}; 547 548 # Check if this is an option that should have a unique value, and if so 549 # determine if the value was checked before. 550 if ($UniqueOptions{$Arg}) { 551 if (defined $Uniqued{$Arg}) { 552 $i += $Cnt; 553 next; 554 } 555 $Uniqued{$Arg} = 1; 556 } 557 558 push @CompileOpts,$Arg; 559 push @LinkOpts,$Arg; 560 561 while ($Cnt > 0) { 562 ++$i; --$Cnt; 563 push @CompileOpts, $ARGV[$i]; 564 push @LinkOpts, $ARGV[$i]; 565 } 566 next; 567 } 568 569 # Ignored options. 570 if (defined $IgnoredOptionMap{$ArgKey}) { 571 my $Cnt = $IgnoredOptionMap{$ArgKey}; 572 while ($Cnt > 0) { 573 ++$i; --$Cnt; 574 } 575 next; 576 } 577 578 # Compile mode flags. 579 if ($Arg =~ /^-[D,I,U,isystem](.*)$/) { 580 my $Tmp = $Arg; 581 if ($1 eq '') { 582 # FIXME: Check if we are going off the end. 583 ++$i; 584 $Tmp = $Arg . $ARGV[$i]; 585 } 586 push @CompileOpts,$Tmp; 587 next; 588 } 589 590 if ($Arg =~ /^-m.*/) { 591 push @CompileOpts,$Arg; 592 next; 593 } 594 595 # Language. 596 if ($Arg eq '-x') { 597 $Lang = $ARGV[$i+1]; 598 ++$i; next; 599 } 600 601 # Output file. 602 if ($Arg eq '-o') { 603 ++$i; 604 $Output = $ARGV[$i]; 605 next; 606 } 607 608 # Get the link mode. 609 if ($Arg =~ /^-[l,L,O]/) { 610 if ($Arg eq '-O') { push @LinkOpts,'-O1'; } 611 elsif ($Arg eq '-Os') { push @LinkOpts,'-O2'; } 612 else { push @LinkOpts,$Arg; } 613 614 # Must pass this along for the __OPTIMIZE__ macro 615 if ($Arg =~ /^-O/) { push @CompileOpts,$Arg; } 616 next; 617 } 618 619 if ($Arg =~ /^-std=/) { 620 push @CompileOpts,$Arg; 621 next; 622 } 623 624 # Get the compiler/link mode. 625 if ($Arg =~ /^-F(.+)$/) { 626 my $Tmp = $Arg; 627 if ($1 eq '') { 628 # FIXME: Check if we are going off the end. 629 ++$i; 630 $Tmp = $Arg . $ARGV[$i]; 631 } 632 push @CompileOpts,$Tmp; 633 push @LinkOpts,$Tmp; 634 next; 635 } 636 637 # Input files. 638 if ($Arg eq '-filelist') { 639 # FIXME: Make sure we aren't walking off the end. 640 open(IN, $ARGV[$i+1]); 641 while (<IN>) { s/\015?\012//; push @Files,$_; } 642 close(IN); 643 ++$i; 644 next; 645 } 646 647 if ($Arg =~ /^-f/) { 648 push @CompileOpts,$Arg; 649 push @LinkOpts,$Arg; 650 next; 651 } 652 653 # Handle -Wno-. We don't care about extra warnings, but 654 # we should suppress ones that we don't want to see. 655 if ($Arg =~ /^-Wno-/) { 656 push @CompileOpts, $Arg; 657 next; 658 } 659 660 if (!($Arg =~ /^-/)) { 661 push @Files, $Arg; 662 next; 663 } 664 } 665 666 # If we are on OSX and have an installation where the 667 # default SDK is inferred by xcrun use xcrun to infer 668 # the SDK. 669 if (not $HasSDK and $UseXCRUN) { 670 my $sdk = `/usr/bin/xcrun --show-sdk-path -sdk macosx`; 671 chomp $sdk; 672 push @CompileOpts, "-isysroot", $sdk; 673 } 674 675 if ($Action eq 'compile' or $Action eq 'link') { 676 my @Archs = keys %ArchsSeen; 677 # Skip the file if we don't support the architectures specified. 678 exit 0 if ($HadArch && scalar(@Archs) == 0); 679 680 foreach my $file (@Files) { 681 # Determine the language for the file. 682 my $FileLang = $Lang; 683 684 if (!defined($FileLang)) { 685 # Infer the language from the extension. 686 if ($file =~ /[.]([^.]+)$/) { 687 $FileLang = $LangMap{$1}; 688 } 689 } 690 691 # FileLang still not defined? Skip the file. 692 next if (!defined $FileLang); 693 694 # Language not accepted? 695 next if (!defined $LangsAccepted{$FileLang}); 696 697 my @CmdArgs; 698 my @AnalyzeArgs; 699 700 if ($FileLang ne 'unknown') { 701 push @CmdArgs, '-x', $FileLang; 702 } 703 704 if (defined $StoreModel) { 705 push @AnalyzeArgs, "-analyzer-store=$StoreModel"; 706 } 707 708 if (defined $ConstraintsModel) { 709 push @AnalyzeArgs, "-analyzer-constraints=$ConstraintsModel"; 710 } 711 712 if (defined $InternalStats) { 713 push @AnalyzeArgs, "-analyzer-stats"; 714 } 715 716 if (defined $Analyses) { 717 push @AnalyzeArgs, split '\s+', $Analyses; 718 } 719 720 if (defined $Plugins) { 721 push @AnalyzeArgs, split '\s+', $Plugins; 722 } 723 724 if (defined $OutputFormat) { 725 push @AnalyzeArgs, "-analyzer-output=" . $OutputFormat; 726 if ($OutputFormat =~ /plist/) { 727 # Change "Output" to be a file. 728 my ($h, $f) = tempfile("report-XXXXXX", SUFFIX => ".plist", 729 DIR => $HtmlDir); 730 $ResultFile = $f; 731 # If the HtmlDir is not set, we should clean up the plist files. 732 if (!defined $HtmlDir || -z $HtmlDir) { 733 $CleanupFile = $f; 734 } 735 } 736 } 737 if (defined $ConfigOptions) { 738 push @AnalyzeArgs, split '\s+', $ConfigOptions; 739 } 740 741 push @CmdArgs, @CompileOpts; 742 push @CmdArgs, $file; 743 744 if (scalar @Archs) { 745 foreach my $arch (@Archs) { 746 my @NewArgs; 747 push @NewArgs, '-arch', $arch; 748 push @NewArgs, @CmdArgs; 749 Analyze($Clang, \@NewArgs, \@AnalyzeArgs, $FileLang, $Output, 750 $Verbose, $HtmlDir, $file); 751 } 752 } 753 else { 754 Analyze($Clang, \@CmdArgs, \@AnalyzeArgs, $FileLang, $Output, 755 $Verbose, $HtmlDir, $file); 756 } 757 } 758 } 759 760 exit($Status >> 8); 761