blob: 9e0474b59945eea7a47294c64e756598ac7f672e [file] [log] [blame]
Ted Kremenekfbeeca82008-07-19 06:11:04 +00001#!/usr/bin/env perl
Ted Kremenekb0982882008-03-25 22:35:32 +00002#
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#
Ted Kremenekfbeeca82008-07-19 06:11:04 +000010# A script designed to interpose between the build system and gcc. It invokes
11# both gcc and the static analyzer.
Ted Kremenekb0982882008-03-25 22:35:32 +000012#
13##===----------------------------------------------------------------------===##
14
Ted Kremenekfbeeca82008-07-19 06:11:04 +000015use strict;
16use warnings;
Ted Kremenekb315a392008-09-21 19:56:14 +000017use Cwd qw/ getcwd abs_path /;
Ted Kremenek991c54b2008-08-08 20:46:42 +000018use File::Temp qw/ tempfile /;
19use File::Path qw / mkpath /;
Ted Kremenekddf32da2009-01-21 00:42:24 +000020use File::Basename;
Ted Kremenek2ec5cd52008-08-25 20:44:31 +000021
22my $CC = $ENV{'CCC_CC'};
23if (!defined $CC) { $CC = "gcc"; }
Ted Kremenekddf32da2009-01-21 00:42:24 +000024my $CleanupFile;
25my $ResultFile;
26
27# Remove any stale files at exit.
28END {
29 if (defined $CleanupFile && -z $CleanupFile) {
30 `rm -f $CleanupFile`;
31 }
32}
33
Ted Kremenek991c54b2008-08-08 20:46:42 +000034##----------------------------------------------------------------------------##
35# Process Clang Crashes.
36##----------------------------------------------------------------------------##
37
38sub GetPPExt {
39 my $Lang = shift;
40 if ($Lang =~ /objective-c/) { return ".mi"; }
41 return ".i";
42}
43
Ted Kremenek5daa3be2009-01-27 01:19:08 +000044my $ParserRejects = "Parser Rejects";
Ted Kremenek938eef12009-02-17 23:31:05 +000045my $AttributeIgnored = "Attribute Ignored";
Ted Kremenek5daa3be2009-01-27 01:19:08 +000046
Ted Kremenek5d31f832008-08-18 18:38:29 +000047sub ProcessClangFailure {
Ted Kremenekc3998fa2008-09-25 00:51:44 +000048 my ($Clang, $Lang, $file, $Args, $HtmlDir, $ErrorType, $ofile) = @_;
Ted Kremenek938eef12009-02-17 23:31:05 +000049 my $Dir = "$HtmlDir/failures";
Ted Kremenek991c54b2008-08-08 20:46:42 +000050 mkpath $Dir;
Ted Kremenek5daa3be2009-01-27 01:19:08 +000051
52 my $prefix = "clang_crash";
Ted Kremenek938eef12009-02-17 23:31:05 +000053 if ($ErrorType eq $ParserRejects) {
54 $prefix = "clang_parser_rejects";
55 }
56 elsif ($ErrorType eq $AttributeIgnored) {
57 $prefix = "clang_attribute_ignored";
58 }
Ted Kremenekc3998fa2008-09-25 00:51:44 +000059
60 # Generate the preprocessed file with cc (i.e., gcc).
Ted Kremenek5daa3be2009-01-27 01:19:08 +000061 my ($PPH, $PPFile) = tempfile( $prefix . "_XXXXXX",
62 SUFFIX => GetPPExt($Lang),
63 DIR => $Dir);
Ted Kremenek991c54b2008-08-08 20:46:42 +000064
Ted Kremenek2ec5cd52008-08-25 20:44:31 +000065 system $CC, @$Args, "-E", "-o", $PPFile;
Ted Kremenek991c54b2008-08-08 20:46:42 +000066 close ($PPH);
Ted Kremenekc3998fa2008-09-25 00:51:44 +000067
68 # Generate the preprocessed file with clang.
69 my $PPFile_Clang = $PPFile;
70 $PPFile_Clang =~ s/[.](.+)$/.clang.$1/;
71 system $Clang, @$Args, "-E", "-o", "$PPFile_Clang";
72
73 # Create the info file.
Ted Kremenek82a12532008-09-25 00:25:16 +000074 open (OUT, ">", "$PPFile.info.txt") or die "Cannot open $PPFile.info.txt\n";
Ted Kremenek5f2825f2008-09-21 18:04:49 +000075 print OUT abs_path($file), "\n";
Ted Kremenek5d31f832008-08-18 18:38:29 +000076 print OUT "$ErrorType\n";
Ted Kremenek2dd7ad12008-08-18 20:55:25 +000077 print OUT "@$Args\n";
Ted Kremenek991c54b2008-08-08 20:46:42 +000078 close OUT;
Ted Kremenek82a12532008-09-25 00:25:16 +000079 `uname -a >> $PPFile.info.txt 2>&1`;
80 `$CC -v >> $PPFile.info.txt 2>&1`;
Ted Kremenek9f9b1fd2008-09-12 22:49:36 +000081 system 'mv',$ofile,"$PPFile.stderr.txt";
Ted Kremenek938eef12009-02-17 23:31:05 +000082 return (basename $PPFile);
Ted Kremenek991c54b2008-08-08 20:46:42 +000083}
Ted Kremenekb0982882008-03-25 22:35:32 +000084
Ted Kremenekfbeeca82008-07-19 06:11:04 +000085##----------------------------------------------------------------------------##
86# Running the analyzer.
87##----------------------------------------------------------------------------##
Ted Kremenekb0982882008-03-25 22:35:32 +000088
Ted Kremenekfbeeca82008-07-19 06:11:04 +000089sub Analyze {
90 my ($Clang, $Args, $Lang, $Output, $Verbose, $HtmlDir, $file, $Analyses) = @_;
Seo Sanghyeond3894652008-04-04 11:02:21 +000091
Ted Kremenekfbeeca82008-07-19 06:11:04 +000092 # Skip anything related to C++.
93 return if ($Lang =~ /c[+][+]/);
Ted Kremenek5d31f832008-08-18 18:38:29 +000094
Ted Kremenekfbeeca82008-07-19 06:11:04 +000095 my $RunAnalyzer = 0;
96 my $Cmd;
97 my @CmdArgs;
Ted Kremenek991c54b2008-08-08 20:46:42 +000098 my @CmdArgsSansAnalyses;
Ted Kremenek61cd9882008-05-24 15:58:54 +000099
Ted Kremenekfbeeca82008-07-19 06:11:04 +0000100 if ($Lang =~ /header/) {
101 exit 0 if (!defined ($Output));
102 $Cmd = 'cp';
103 push @CmdArgs,$file;
104 # Remove the PCH extension.
105 $Output =~ s/[.]gch$//;
106 push @CmdArgs,$Output;
Ted Kremenek991c54b2008-08-08 20:46:42 +0000107 @CmdArgsSansAnalyses = @CmdArgs;
Ted Kremenekfbeeca82008-07-19 06:11:04 +0000108 }
109 else {
110 $Cmd = $Clang;
Ted Kremenekfbeeca82008-07-19 06:11:04 +0000111 push @CmdArgs,'-DIBOutlet=__attribute__((iboutlet))';
112 push @CmdArgs,@$Args;
Ted Kremenek991c54b2008-08-08 20:46:42 +0000113 @CmdArgsSansAnalyses = @CmdArgs;
Ted Kremenek938eef12009-02-17 23:31:05 +0000114 push @CmdArgs,'-analyze';
115 push @CmdArgs,"-analyzer-display-progress";
116 push @CmdArgs,"-disable-free";
Ted Kremenek991c54b2008-08-08 20:46:42 +0000117 push @CmdArgs,(split /\s/,$Analyses);
Ted Kremenekfbeeca82008-07-19 06:11:04 +0000118 $RunAnalyzer = 1;
119 }
120
121 my @PrintArgs;
122 my $dir;
123
124 if ($Verbose) {
125 $dir = getcwd();
126 print STDERR "\n[LOCATION]: $dir\n";
127 push @PrintArgs,"'$Cmd'";
128 foreach my $arg (@CmdArgs) { push @PrintArgs,"\'$arg\'"; }
129 }
130
131 if ($Verbose == 1) {
Ted Kremenek61cd9882008-05-24 15:58:54 +0000132 # We MUST print to stderr. Some clients use the stdout output of
133 # gcc for various purposes.
Ted Kremenekfbeeca82008-07-19 06:11:04 +0000134 print STDERR join(' ',@PrintArgs);
135 print STDERR "\n";
136 }
137 elsif ($Verbose == 2) {
138 print STDERR "#SHELL (cd '$dir' && @PrintArgs)\n";
139 }
Ted Kremenek61cd9882008-05-24 15:58:54 +0000140
Ted Kremenekddf32da2009-01-21 00:42:24 +0000141 if ($RunAnalyzer) {
142 if (defined $ResultFile) {
143 push @CmdArgs,'-o';
144 push @CmdArgs, $ResultFile;
145 }
146 elsif (defined $HtmlDir) {
147 push @CmdArgs,'-o';
148 push @CmdArgs, $HtmlDir;
149 }
Ted Kremenekfbeeca82008-07-19 06:11:04 +0000150 }
Ted Kremenek948e06b2008-08-27 22:30:34 +0000151
152 if (defined $ENV{'CCC_UBI'}) {
153 push @CmdArgs,"--analyzer-viz-egraph-ubigraph";
154 }
Ted Kremenek991c54b2008-08-08 20:46:42 +0000155
Ted Kremenek9a3c7da2008-09-04 00:02:34 +0000156 # Capture the STDERR of clang and send it to a temporary file.
157 # Capture the STDOUT of clang and reroute it to ccc-analyzer's STDERR.
158 # We save the output file in the 'crashes' directory if clang encounters
159 # any problems with the file.
Ted Kremenek13462682008-09-11 23:05:26 +0000160 pipe (FROM_CHILD, TO_PARENT);
Ted Kremenek9a3c7da2008-09-04 00:02:34 +0000161 my $pid = fork();
162 if ($pid == 0) {
Ted Kremenek13462682008-09-11 23:05:26 +0000163 close FROM_CHILD;
164 open(STDOUT,">&", \*TO_PARENT);
165 open(STDERR,">&", \*TO_PARENT);
Ted Kremenek9a3c7da2008-09-04 00:02:34 +0000166 exec $Cmd, @CmdArgs;
167 }
Ted Kremenek13462682008-09-11 23:05:26 +0000168
169 close TO_PARENT;
170 my ($ofh, $ofile) = tempfile("clang_output_XXXXXX", DIR => $HtmlDir);
171
172 while (<FROM_CHILD>) {
173 print $ofh $_;
174 print STDERR $_;
175 }
176
177 waitpid($pid,0);
Ted Kremenek9a3c7da2008-09-04 00:02:34 +0000178 my $Result = $?;
179
180 # Did the command die because of a signal?
181 if ($Result & 127 and $Cmd eq $Clang and defined $HtmlDir) {
Ted Kremenekc3998fa2008-09-25 00:51:44 +0000182 ProcessClangFailure($Clang, $Lang, $file, \@CmdArgsSansAnalyses, $HtmlDir,
Ted Kremenek9a3c7da2008-09-04 00:02:34 +0000183 "Crash", $ofile);
184 }
185 elsif ($Result) {
Ted Kremenekc3998fa2008-09-25 00:51:44 +0000186 ProcessClangFailure($Clang, $Lang, $file, \@CmdArgsSansAnalyses, $HtmlDir,
Ted Kremenek5daa3be2009-01-27 01:19:08 +0000187 $ParserRejects, $ofile);
Ted Kremenek9a3c7da2008-09-04 00:02:34 +0000188 }
Ted Kremenek938eef12009-02-17 23:31:05 +0000189 else {
190 # Check if there were any unhandled attributes.
191 if (open(CHILD, $ofile)) {
192 my %attributes_not_handled;
193 my $ppfile;
194 while (<CHILD>) {
195 next if (! /warning: '([^\']+)' attribute ignored/);
196
197 # Have we already spotted this unhandled attribute?
198 next if (defined $attributes_not_handled{$1});
199 $attributes_not_handled{$1} = 1;
200
201 # Add this file to the list of files that contained this attribute.
202 # Generate a preprocessed file if we haven't already.
203 if (!(defined $ppfile)) {
204 $ppfile = ProcessClangFailure($Clang, $Lang, $file,
205 \@CmdArgsSansAnalyses,
206 $HtmlDir, $AttributeIgnored, $ofile);
207 }
208
209 my $dir = "$HtmlDir/failures";
210 mkpath $dir;
211 my $afile = "$dir/attribute_ignored_$1.txt";
212 open(AFILE, ">>$afile");
213 print AFILE "$ppfile\n";
214 close(AFILE);
215 }
216 close CHILD;
217 }
218 }
Ted Kremenek9a3c7da2008-09-04 00:02:34 +0000219
220 `rm -f $ofile`;
Ted Kremenekfbeeca82008-07-19 06:11:04 +0000221}
Ted Kremenek61cd9882008-05-24 15:58:54 +0000222
Ted Kremenekfbeeca82008-07-19 06:11:04 +0000223##----------------------------------------------------------------------------##
224# Lookup tables.
225##----------------------------------------------------------------------------##
226
227my %CompileOptionMap = (
228 '-nostdinc' => 0,
Anders Carlsson06c58b12008-12-19 20:56:23 +0000229 '-fblocks' => 0,
Ted Kremenekfbeeca82008-07-19 06:11:04 +0000230 '-fobjc-gc-only' => 0,
231 '-fobjc-gc' => 0,
232 '-include' => 1,
233 '-idirafter' => 1,
234 '-iprefix' => 1,
235 '-iquote' => 1,
236 '-isystem' => 1,
237 '-iwithprefix' => 1,
238 '-iwithprefixbefore' => 1
239);
240
241my %LinkerOptionMap = (
242 '-framework' => 1
243);
244
245my %CompilerLinkerOptionMap = (
246 '-isysroot' => 1,
247 '-arch' => 1,
Ted Kremeneke4f69522008-09-29 22:45:28 +0000248 '-v' => 0,
Ted Kremenekb10362a2008-09-30 23:40:25 +0000249 '-fpascal-strings' => 0,
250 '-mmacosx-version-min' => 0 # This is really a 1 argument, but always has '='
Ted Kremenekfbeeca82008-07-19 06:11:04 +0000251);
252
253my %IgnoredOptionMap = (
Ted Kremenek94026092008-07-24 03:52:21 +0000254 '-MT' => 1, # Ignore these preprocessor options.
255 '-MF' => 1,
256
Ted Kremenekfbeeca82008-07-19 06:11:04 +0000257 '-fsyntax-only' => 0,
258 '-save-temps' => 0,
259 '-install_name' => 1,
260 '-exported_symbols_list' => 1,
261 '-current_version' => 1,
262 '-compatibility_version' => 1,
263 '-init' => 1,
264 '-e' => 1,
265 '-seg1addr' => 1,
266 '-bundle_loader' => 1,
267 '-multiply_defined' => 1,
268 '-sectorder' => 3,
269 '--param' => 1,
270 '-u' => 1
271);
272
273my %LangMap = (
274 'c' => 'c',
275 'cpp' => 'c++',
276 'cc' => 'c++',
277 'i' => 'c-cpp-output',
278 'm' => 'objective-c',
279 'mi' => 'objective-c-cpp-output'
280);
281
Ted Kremeneka30730e2008-09-29 16:15:20 +0000282my %UniqueOptions = (
283 '-isysroot' => 0
284);
285
Ted Kremenekfbeeca82008-07-19 06:11:04 +0000286##----------------------------------------------------------------------------##
287# Main Logic.
288##----------------------------------------------------------------------------##
289
290my $Action = 'link';
291my @CompileOpts;
292my @LinkOpts;
293my @Files;
294my $Lang;
295my $Output;
Ted Kremeneka30730e2008-09-29 16:15:20 +0000296my %Uniqued;
Ted Kremenekfbeeca82008-07-19 06:11:04 +0000297
298# Forward arguments to gcc.
Ted Kremenekf17ef3c2008-08-21 21:47:09 +0000299my $Status = system($CC,@ARGV);
Ted Kremenekcb344d02008-08-28 01:18:44 +0000300if ($Status) { exit($Status >> 8); }
Ted Kremenekfbeeca82008-07-19 06:11:04 +0000301
302# Get the analysis options.
303my $Analyses = $ENV{'CCC_ANALYZER_ANALYSIS'};
304if (!defined($Analyses)) { $Analyses = '-checker-cfref'; }
305
Zhongxing Xu07c37672008-10-27 14:26:32 +0000306# Get the store model.
307my $StoreModel = $ENV{'CCC_ANALYZER_STORE_MODEL'};
Ted Kremenekbe1fe1e2009-02-17 04:27:41 +0000308if (!defined $StoreModel) { $StoreModel = "basic"; }
309
310# Get the constraints engine.
311my $ConstraintsModel = $ENV{'CCC_ANALYZER_CONSTRAINTS_MODEL'};
Ted Kremenek9f4ecb32009-02-20 21:49:22 +0000312if (!defined $ConstraintsModel) { $ConstraintsModel = "range"; }
Zhongxing Xu07c37672008-10-27 14:26:32 +0000313
Ted Kremenekdb4f5f22008-11-04 00:02:53 +0000314# Get the output format.
315my $OutputFormat = $ENV{'CCC_ANALYZER_OUTPUT_FORMAT'};
Ted Kremenek3891a152009-02-17 05:01:10 +0000316if (!defined $OutputFormat) { $OutputFormat = "html"; }
Ted Kremenekdb4f5f22008-11-04 00:02:53 +0000317
Ted Kremenekfbeeca82008-07-19 06:11:04 +0000318# Determine the level of verbosity.
319my $Verbose = 0;
320if (defined $ENV{CCC_ANALYZER_VERBOSE}) { $Verbose = 1; }
321if (defined $ENV{CCC_ANALYZER_LOG}) { $Verbose = 2; }
322
323# Determine what clang executable to use.
324my $Clang = $ENV{'CLANG'};
325if (!defined $Clang) { $Clang = 'clang'; }
326
327# Get the HTML output directory.
328my $HtmlDir = $ENV{'CCC_ANALYZER_HTML'};
329
Ted Kremenek27783eb2008-09-25 20:17:57 +0000330my %ArchsSeen;
Ted Kremenekfbeeca82008-07-19 06:11:04 +0000331
332# Process the arguments.
333foreach (my $i = 0; $i < scalar(@ARGV); ++$i) {
Ted Kremenek89c4fcf2008-10-19 06:42:38 +0000334 my $Arg = $ARGV[$i];
335 my ($ArgKey) = split /=/,$Arg,2;
336
Ted Kremenekfbeeca82008-07-19 06:11:04 +0000337 # Modes ccc-analyzer supports
338 if ($Arg eq '-E') { $Action = 'preprocess'; }
339 elsif ($Arg eq '-c') { $Action = 'compile'; }
340 elsif ($Arg =~ /^-print-prog-name/) { exit 0; }
Ted Kremenek27783eb2008-09-25 20:17:57 +0000341
342 # Specially handle duplicate cases of -arch
343 if ($Arg eq "-arch") {
344 my $arch = $ARGV[$i+1];
345 $ArchsSeen{$arch} = 1;
346 ++$i;
347 next;
348 }
349
Ted Kremenekfbeeca82008-07-19 06:11:04 +0000350 # Options with possible arguments that should pass through to compiler.
Ted Kremenek89c4fcf2008-10-19 06:42:38 +0000351 if (defined $CompileOptionMap{$ArgKey}) {
352 my $Cnt = $CompileOptionMap{$ArgKey};
Ted Kremenekfbeeca82008-07-19 06:11:04 +0000353 push @CompileOpts,$Arg;
354 while ($Cnt > 0) { ++$i; --$Cnt; push @CompileOpts, $ARGV[$i]; }
355 next;
356 }
357
358 # Options with possible arguments that should pass through to linker.
Ted Kremenek89c4fcf2008-10-19 06:42:38 +0000359 if (defined $LinkerOptionMap{$ArgKey}) {
360 my $Cnt = $LinkerOptionMap{$ArgKey};
Ted Kremenekfbeeca82008-07-19 06:11:04 +0000361 push @LinkOpts,$Arg;
362 while ($Cnt > 0) { ++$i; --$Cnt; push @LinkOpts, $ARGV[$i]; }
363 next;
364 }
365
366 # Options with possible arguments that should pass through to both compiler
367 # and the linker.
Ted Kremenek89c4fcf2008-10-19 06:42:38 +0000368 if (defined $CompilerLinkerOptionMap{$ArgKey}) {
369 my $Cnt = $CompilerLinkerOptionMap{$ArgKey};
Ted Kremenek47fc25f2008-09-29 23:06:09 +0000370
Ted Kremeneka30730e2008-09-29 16:15:20 +0000371 # Check if this is an option that should have a unique value, and if so
372 # determine if the value was checked before.
373 if ($UniqueOptions{$Arg}) {
374 if (defined $Uniqued{$Arg}) {
375 $i += $Cnt;
376 next;
377 }
378 $Uniqued{$Arg} = 1;
379 }
380
Ted Kremenek47fc25f2008-09-29 23:06:09 +0000381 push @CompileOpts,$Arg;
382 push @LinkOpts,$Arg;
383
Ted Kremenekfbeeca82008-07-19 06:11:04 +0000384 while ($Cnt > 0) {
385 ++$i; --$Cnt;
386 push @CompileOpts, $ARGV[$i];
387 push @LinkOpts, $ARGV[$i];
388 }
389 next;
390 }
Ted Kremenek61cd9882008-05-24 15:58:54 +0000391
Ted Kremenekfbeeca82008-07-19 06:11:04 +0000392 # Ignored options.
Ted Kremenek89c4fcf2008-10-19 06:42:38 +0000393 if (defined $IgnoredOptionMap{$ArgKey}) {
394 my $Cnt = $IgnoredOptionMap{$ArgKey};
Ted Kremenekfbeeca82008-07-19 06:11:04 +0000395 while ($Cnt > 0) {
396 ++$i; --$Cnt;
397 }
398 next;
399 }
Ted Kremenek61cd9882008-05-24 15:58:54 +0000400
Ted Kremenekfbeeca82008-07-19 06:11:04 +0000401 # Compile mode flags.
402 if ($Arg =~ /^-[D,I,U](.*)$/) {
403 my $Tmp = $Arg;
404 if ($1 eq '') {
405 # FIXME: Check if we are going off the end.
406 ++$i;
407 $Tmp = $Arg . $ARGV[$i];
408 }
409 push @CompileOpts,$Tmp;
410 next;
411 }
412
413 # Language.
414 if ($Arg eq '-x') {
415 $Lang = $ARGV[$i+1];
416 ++$i; next;
417 }
Ted Kremenek61cd9882008-05-24 15:58:54 +0000418
Ted Kremenekfbeeca82008-07-19 06:11:04 +0000419 # Output file.
420 if ($Arg eq '-o') {
421 ++$i;
422 $Output = $ARGV[$i];
423 next;
424 }
425
426 # Get the link mode.
427 if ($Arg =~ /^-[l,L,O]/) {
428 if ($Arg eq '-O') { push @LinkOpts,'-O1'; }
429 elsif ($Arg eq '-Os') { push @LinkOpts,'-O2'; }
430 else { push @LinkOpts,$Arg; }
431 next;
432 }
433
434 if ($Arg =~ /^-std=/) {
435 push @CompileOpts,$Arg;
436 next;
437 }
438
439# if ($Arg =~ /^-f/) {
440# # FIXME: Not sure if the remaining -fxxxx options have no arguments.
441# push @CompileOpts,$Arg;
442# push @LinkOpts,$Arg; # FIXME: Not sure if these are link opts.
443# }
444
445 # Get the compiler/link mode.
446 if ($Arg =~ /^-F(.+)$/) {
447 my $Tmp = $Arg;
448 if ($1 eq '') {
449 # FIXME: Check if we are going off the end.
450 ++$i;
451 $Tmp = $Arg . $ARGV[$i];
452 }
453 push @CompileOpts,$Tmp;
454 push @LinkOpts,$Tmp;
455 next;
456 }
Ted Kremenek61cd9882008-05-24 15:58:54 +0000457
Ted Kremenekfbeeca82008-07-19 06:11:04 +0000458 # Input files.
459 if ($Arg eq '-filelist') {
460 # FIXME: Make sure we aren't walking off the end.
461 open(IN, $ARGV[$i+1]);
462 while (<IN>) { s/\015?\012//; push @Files,$_; }
463 close(IN);
464 ++$i; next;
465 }
466
467 if (!($Arg =~ /^-/)) {
468 push @Files,$Arg; next;
469 }
470}
Ted Kremenek61cd9882008-05-24 15:58:54 +0000471
Ted Kremenekfbeeca82008-07-19 06:11:04 +0000472if ($Action eq 'compile' or $Action eq 'link') {
473 foreach my $file (@Files) {
474 # Determine the language for the file.
475 my $FileLang = $Lang;
476
477 if (!defined($FileLang)) {
478 # Infer the language from the extension.
479 if ($file =~ /[.]([^.]+)$/) {
480 $FileLang = $LangMap{$1};
481 }
482 }
Ted Kremenek1262fc42008-05-14 20:10:33 +0000483
Ted Kremenekfbeeca82008-07-19 06:11:04 +0000484 next if (!defined $FileLang);
485
486 my @AnalyzeArgs;
487
488 if ($FileLang ne 'unknown') {
489 push @AnalyzeArgs,'-x';
490 push @AnalyzeArgs,$FileLang;
491 }
Ted Kremenekb0982882008-03-25 22:35:32 +0000492
Zhongxing Xu07c37672008-10-27 14:26:32 +0000493 if (defined $StoreModel) {
Ted Kremenekbe1fe1e2009-02-17 04:27:41 +0000494 push @AnalyzeArgs, "-analyzer-store=$StoreModel";
Zhongxing Xu07c37672008-10-27 14:26:32 +0000495 }
Ted Kremenekbe1fe1e2009-02-17 04:27:41 +0000496
497 if (defined $ConstraintsModel) {
498 push @AnalyzeArgs, "-analyzer-constraints=$ConstraintsModel";
499 }
500
Ted Kremenekdb4f5f22008-11-04 00:02:53 +0000501 if (defined $OutputFormat) {
Ted Kremenekbe1fe1e2009-02-17 04:27:41 +0000502 push @AnalyzeArgs, "-analyzer-output=" . $OutputFormat;
Ted Kremenekddf32da2009-01-21 00:42:24 +0000503 if ($OutputFormat eq "plist") {
504 # Change "Output" to be a file.
505 my ($h, $f) = tempfile("report-XXXXXX", SUFFIX => ".plist",
506 DIR => $HtmlDir);
507 $ResultFile = $f;
508 $CleanupFile = $f;
509 }
Ted Kremenekdb4f5f22008-11-04 00:02:53 +0000510 }
Zhongxing Xu07c37672008-10-27 14:26:32 +0000511
Ted Kremenekfbeeca82008-07-19 06:11:04 +0000512 push @AnalyzeArgs,@CompileOpts;
513 push @AnalyzeArgs,$file;
Zhongxing Xu07c37672008-10-27 14:26:32 +0000514
Ted Kremenek27783eb2008-09-25 20:17:57 +0000515 my @Archs = keys %ArchsSeen;
516 if (scalar @Archs) {
517 foreach my $arch (@Archs) {
518 my @NewArgs;
519 push @NewArgs, '-arch';
520 push @NewArgs, $arch;
521 push @NewArgs, @AnalyzeArgs;
522 Analyze($Clang, \@NewArgs, $FileLang, $Output,
523 $Verbose, $HtmlDir, $file, $Analyses);
524 }
525 }
526 else {
527 Analyze($Clang, \@AnalyzeArgs, $FileLang, $Output,
528 $Verbose, $HtmlDir, $file, $Analyses);
529 }
Ted Kremenekfbeeca82008-07-19 06:11:04 +0000530 }
531}
Ted Kremenekb0982882008-03-25 22:35:32 +0000532
Ted Kremenek948e06b2008-08-27 22:30:34 +0000533exit($Status >> 8);
534