blob: cf56d14ebe8fe0b8c41c18e08c3b65e79ee738c8 [file] [log] [blame]
Ted Kremenekf7ffd662008-07-19 06:11:04 +00001#!/usr/bin/env perl
Ted Kremenek5efdf842008-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 Kremenekf7ffd662008-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 Kremenek5efdf842008-03-25 22:35:32 +000012#
13##===----------------------------------------------------------------------===##
14
Ted Kremenekf7ffd662008-07-19 06:11:04 +000015use strict;
16use warnings;
Ted Kremenekf65a0c62009-12-15 02:35:54 +000017use FindBin;
Ted Kremenek23432d42008-09-21 19:56:14 +000018use Cwd qw/ getcwd abs_path /;
Ted Kremenek994c8e32008-08-08 20:46:42 +000019use File::Temp qw/ tempfile /;
20use File::Path qw / mkpath /;
Ted Kremenek13747162009-01-21 00:42:24 +000021use File::Basename;
Ted Kremenek25421bb2009-05-11 23:29:51 +000022use Text::ParseWords;
Ted Kremenek6aa1ad02008-08-25 20:44:31 +000023
Ted Kremenekf65a0c62009-12-15 02:35:54 +000024##===----------------------------------------------------------------------===##
25# Compiler command setup.
26##===----------------------------------------------------------------------===##
27
Sylvestre Ledru9e075292014-08-08 17:15:13 +000028# 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
Ted Kremenekf65a0c62009-12-15 02:35:54 +000039my $Compiler;
40my $Clang;
Anna Zaks1d391522012-01-06 01:54:05 +000041my $DefaultCCompiler;
42my $DefaultCXXCompiler;
Jordan Rosea63f2292014-01-07 21:39:51 +000043my $IsCXX;
Ted Kremenek67978552014-12-31 08:19:08 +000044
45# If on OSX, use xcrun to determine the SDK root.
Ted Kremenek398f46f2014-12-31 07:44:51 +000046my $UseXCRUN = 0;
Anna Zaks1d391522012-01-06 01:54:05 +000047
Sylvestre Ledru82e547e2014-02-18 17:21:45 +000048if (`uname -a` =~ m/Darwin/) {
Jordan Rose85ff8f22012-11-28 19:12:44 +000049 $DefaultCCompiler = 'clang';
50 $DefaultCXXCompiler = 'clang++';
Ted Kremenek67978552014-12-31 08:19:08 +000051 # Older versions of OSX do not have xcrun to
52 # query the SDK location.
Ted Kremenek398f46f2014-12-31 07:44:51 +000053 if (-x "/usr/bin/xcrun") {
54 $UseXCRUN = 1;
55 }
Anna Zaks1d391522012-01-06 01:54:05 +000056} else {
Jordan Rose85ff8f22012-11-28 19:12:44 +000057 $DefaultCCompiler = 'gcc';
58 $DefaultCXXCompiler = 'g++';
Anna Zaks1d391522012-01-06 01:54:05 +000059}
Ted Kremenekf65a0c62009-12-15 02:35:54 +000060
61if ($FindBin::Script =~ /c\+\+-analyzer/) {
62 $Compiler = $ENV{'CCC_CXX'};
Sylvestre Ledru9e075292014-08-08 17:15:13 +000063 if (!defined $Compiler || (! -x $Compiler && ! SearchInPath($Compiler))) { $Compiler = $DefaultCXXCompiler; }
Sylvestre Ledru82e547e2014-02-18 17:21:45 +000064
Ted Kremenekf65a0c62009-12-15 02:35:54 +000065 $Clang = $ENV{'CLANG_CXX'};
Sylvestre Ledru3ea1dae2014-02-18 17:45:06 +000066 if (!defined $Clang || ! -x $Clang) { $Clang = 'clang++'; }
Jordan Rosea63f2292014-01-07 21:39:51 +000067
68 $IsCXX = 1
Ted Kremenekf65a0c62009-12-15 02:35:54 +000069}
70else {
71 $Compiler = $ENV{'CCC_CC'};
Sylvestre Ledru9e075292014-08-08 17:15:13 +000072 if (!defined $Compiler || (! -x $Compiler && ! SearchInPath($Compiler))) { $Compiler = $DefaultCCompiler; }
Ted Kremenekf65a0c62009-12-15 02:35:54 +000073
74 $Clang = $ENV{'CLANG'};
Sylvestre Ledru3ea1dae2014-02-18 17:45:06 +000075 if (!defined $Clang || ! -x $Clang) { $Clang = 'clang'; }
Jordan Rosea63f2292014-01-07 21:39:51 +000076
77 $IsCXX = 0
Ted Kremenekf65a0c62009-12-15 02:35:54 +000078}
79
80##===----------------------------------------------------------------------===##
81# Cleanup.
82##===----------------------------------------------------------------------===##
Ted Kremenekbfe393f2009-07-30 23:55:19 +000083
84my $ReportFailures = $ENV{'CCC_REPORT_FAILURES'};
85if (!defined $ReportFailures) { $ReportFailures = 1; }
86
Ted Kremenek13747162009-01-21 00:42:24 +000087my $CleanupFile;
88my $ResultFile;
89
90# Remove any stale files at exit.
Sylvestre Ledru82e547e2014-02-18 17:21:45 +000091END {
Anna Zaks45ce1bf2011-09-09 18:43:53 +000092 if (defined $ResultFile && -z $ResultFile) {
Sylvestre Ledrudf70a7b2014-05-23 16:10:00 +000093 unlink($ResultFile);
Anna Zaks45ce1bf2011-09-09 18:43:53 +000094 }
95 if (defined $CleanupFile) {
Sylvestre Ledrudf70a7b2014-05-23 16:10:00 +000096 unlink($CleanupFile);
Ted Kremenek13747162009-01-21 00:42:24 +000097 }
98}
99
Ted Kremenek994c8e32008-08-08 20:46:42 +0000100##----------------------------------------------------------------------------##
101# Process Clang Crashes.
102##----------------------------------------------------------------------------##
103
104sub GetPPExt {
105 my $Lang = shift;
Ted Kremenek22a8a4b2009-12-16 18:32:41 +0000106 if ($Lang =~ /objective-c\+\+/) { return ".mii" };
Ted Kremenek994c8e32008-08-08 20:46:42 +0000107 if ($Lang =~ /objective-c/) { return ".mi"; }
Ted Kremenekdca68162009-12-16 05:02:47 +0000108 if ($Lang =~ /c\+\+/) { return ".ii"; }
Ted Kremenek994c8e32008-08-08 20:46:42 +0000109 return ".i";
110}
111
Ted Kremenekce6b8652009-04-28 17:37:44 +0000112# Set this to 1 if we want to include 'parser rejects' files.
113my $IncludeParserRejects = 0;
Ted Kremenek725fb432009-01-27 01:19:08 +0000114my $ParserRejects = "Parser Rejects";
Ted Kremenek13ed6f12009-02-17 23:31:05 +0000115my $AttributeIgnored = "Attribute Ignored";
Anna Zaks9fed0842011-11-07 22:38:10 +0000116my $OtherError = "Other Error";
Ted Kremenek725fb432009-01-27 01:19:08 +0000117
Ted Kremenek5abf5462008-08-18 18:38:29 +0000118sub ProcessClangFailure {
Ted Kremenek5c512e62009-12-11 22:44:53 +0000119 my ($Clang, $Lang, $file, $Args, $HtmlDir, $ErrorType, $ofile) = @_;
Ted Kremenek13ed6f12009-02-17 23:31:05 +0000120 my $Dir = "$HtmlDir/failures";
Ted Kremenek994c8e32008-08-08 20:46:42 +0000121 mkpath $Dir;
Sylvestre Ledru82e547e2014-02-18 17:21:45 +0000122
Ted Kremenek725fb432009-01-27 01:19:08 +0000123 my $prefix = "clang_crash";
Ted Kremenek13ed6f12009-02-17 23:31:05 +0000124 if ($ErrorType eq $ParserRejects) {
125 $prefix = "clang_parser_rejects";
126 }
127 elsif ($ErrorType eq $AttributeIgnored) {
128 $prefix = "clang_attribute_ignored";
129 }
Anna Zaks9fed0842011-11-07 22:38:10 +0000130 elsif ($ErrorType eq $OtherError) {
131 $prefix = "clang_other_error";
132 }
Ted Kremenek72e4b0b2008-09-25 00:51:44 +0000133
Ted Kremenek0799d4f2009-07-28 00:14:21 +0000134 # Generate the preprocessed file with Clang.
Ted Kremenek725fb432009-01-27 01:19:08 +0000135 my ($PPH, $PPFile) = tempfile( $prefix . "_XXXXXX",
136 SUFFIX => GetPPExt($Lang),
137 DIR => $Dir);
Ted Kremenek994c8e32008-08-08 20:46:42 +0000138 close ($PPH);
Anton Yartsev321b1762015-06-17 23:12:33 +0000139 system $Clang, @$Args, "-E", "-o", $PPFile;
Sylvestre Ledru82e547e2014-02-18 17:21:45 +0000140
Ted Kremenek72e4b0b2008-09-25 00:51:44 +0000141 # Create the info file.
Ted Kremenek1ad3b3d2008-09-25 00:25:16 +0000142 open (OUT, ">", "$PPFile.info.txt") or die "Cannot open $PPFile.info.txt\n";
Ted Kremenek32c11812008-09-21 18:04:49 +0000143 print OUT abs_path($file), "\n";
Ted Kremenek5abf5462008-08-18 18:38:29 +0000144 print OUT "$ErrorType\n";
Ted Kremenekb3c98d32008-08-18 20:55:25 +0000145 print OUT "@$Args\n";
Ted Kremenek994c8e32008-08-08 20:46:42 +0000146 close OUT;
Ted Kremenek1ad3b3d2008-09-25 00:25:16 +0000147 `uname -a >> $PPFile.info.txt 2>&1`;
Ahmed Bougacha51919112015-05-06 02:08:27 +0000148 `$Compiler -v >> $PPFile.info.txt 2>&1`;
Sylvestre Ledrudf70a7b2014-05-23 16:10:00 +0000149 rename($ofile, "$PPFile.stderr.txt");
Ted Kremenek13ed6f12009-02-17 23:31:05 +0000150 return (basename $PPFile);
Ted Kremenek994c8e32008-08-08 20:46:42 +0000151}
Ted Kremenek5efdf842008-03-25 22:35:32 +0000152
Ted Kremenekf7ffd662008-07-19 06:11:04 +0000153##----------------------------------------------------------------------------##
154# Running the analyzer.
155##----------------------------------------------------------------------------##
Ted Kremenek5efdf842008-03-25 22:35:32 +0000156
Ted Kremenek1f991f02009-05-09 19:19:28 +0000157sub GetCCArgs {
Ted Kremenek42ec9142011-02-17 02:28:30 +0000158 my $mode = shift;
Ted Kremenek1f991f02009-05-09 19:19:28 +0000159 my $Args = shift;
Sylvestre Ledru82e547e2014-02-18 17:21:45 +0000160
Ted Kremenek1f991f02009-05-09 19:19:28 +0000161 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);
Ted Kremenek42ec9142011-02-17 02:28:30 +0000167 exec $Clang, "-###", $mode, @$Args;
Sylvestre Ledru82e547e2014-02-18 17:21:45 +0000168 }
Ted Kremenek1f991f02009-05-09 19:19:28 +0000169 close(TO_PARENT);
170 my $line;
171 while (<FROM_CHILD>) {
Jordan Rose0d7d09f2014-03-20 17:43:54 +0000172 next if (!/\s"?-cc1"?\s/);
Ted Kremenek1f991f02009-05-09 19:19:28 +0000173 $line = $_;
174 }
175
176 waitpid($pid,0);
177 close(FROM_CHILD);
Sylvestre Ledru82e547e2014-02-18 17:21:45 +0000178
Ted Kremenekf92b4462009-12-11 23:12:52 +0000179 die "could not find clang line\n" if (!defined $line);
Anton Yartsev0cb7c8a2014-01-23 14:12:48 +0000180 # Strip leading and trailing whitespace characters.
181 $line =~ s/^\s+|\s+$//g;
Anton Yartsev22f61892015-05-05 19:43:37 +0000182 my @items = quotewords('\s+', 0, $line);
Ted Kremenek1f991f02009-05-09 19:19:28 +0000183 my $cmd = shift @items;
Ted Kremenekf92b4462009-12-11 23:12:52 +0000184 die "cannot find 'clang' in 'clang' command\n" if (!($cmd =~ /clang/));
Ted Kremenek1f991f02009-05-09 19:19:28 +0000185 return \@items;
186}
187
Ted Kremenekf7ffd662008-07-19 06:11:04 +0000188sub Analyze {
Ted Kremenek339f7c32011-03-10 21:10:08 +0000189 my ($Clang, $OriginalArgs, $AnalyzeArgs, $Lang, $Output, $Verbose, $HtmlDir,
Ted Kremenek42ec9142011-02-17 02:28:30 +0000190 $file) = @_;
Seo Sanghyeonb7bf0f32008-04-04 11:02:21 +0000191
Ted Kremenek339f7c32011-03-10 21:10:08 +0000192 my @Args = @$OriginalArgs;
Ted Kremenekf7ffd662008-07-19 06:11:04 +0000193 my $Cmd;
194 my @CmdArgs;
Ted Kremenek994c8e32008-08-08 20:46:42 +0000195 my @CmdArgsSansAnalyses;
Ted Kremenek42ec9142011-02-17 02:28:30 +0000196
Ted Kremenekf7ffd662008-07-19 06:11:04 +0000197 if ($Lang =~ /header/) {
198 exit 0 if (!defined ($Output));
199 $Cmd = 'cp';
Ted Kremenek42ec9142011-02-17 02:28:30 +0000200 push @CmdArgs, $file;
Ted Kremenekf7ffd662008-07-19 06:11:04 +0000201 # Remove the PCH extension.
202 $Output =~ s/[.]gch$//;
Ted Kremenek42ec9142011-02-17 02:28:30 +0000203 push @CmdArgs, $Output;
204 @CmdArgsSansAnalyses = @CmdArgs;
Ted Kremenekf7ffd662008-07-19 06:11:04 +0000205 }
206 else {
Ted Kremenek5c512e62009-12-11 22:44:53 +0000207 $Cmd = $Clang;
Ted Kremenek42ec9142011-02-17 02:28:30 +0000208
209 # Create arguments for doing regular parsing.
Ted Kremenek339f7c32011-03-10 21:10:08 +0000210 my $SyntaxArgs = GetCCArgs("-fsyntax-only", \@Args);
211 @CmdArgsSansAnalyses = @$SyntaxArgs;
212
Ted Kremenek42ec9142011-02-17 02:28:30 +0000213 # Create arguments for doing static analysis.
214 if (defined $ResultFile) {
Ted Kremenekd4bcb4f2011-03-16 21:10:42 +0000215 push @Args, '-o', $ResultFile;
Ted Kremenek42ec9142011-02-17 02:28:30 +0000216 }
217 elsif (defined $HtmlDir) {
Ted Kremenekd4bcb4f2011-03-16 21:10:42 +0000218 push @Args, '-o', $HtmlDir;
Ted Kremenek42ec9142011-02-17 02:28:30 +0000219 }
Ted Kremenek9acb3462011-03-21 20:12:21 +0000220 if ($Verbose) {
221 push @Args, "-Xclang", "-analyzer-display-progress";
222 }
Ted Kremenek42ec9142011-02-17 02:28:30 +0000223
224 foreach my $arg (@$AnalyzeArgs) {
Ted Kremenekd4bcb4f2011-03-16 21:10:42 +0000225 push @Args, "-Xclang", $arg;
Ted Kremenek4ef13f82009-11-13 18:46:29 +0000226 }
Ted Kremenekd4bcb4f2011-03-16 21:10:42 +0000227
Ted Kremenek42ec9142011-02-17 02:28:30 +0000228 # Display Ubiviz graph?
Sylvestre Ledru82e547e2014-02-18 17:21:45 +0000229 if (defined $ENV{'CCC_UBI'}) {
Ted Kremenekd4bcb4f2011-03-16 21:10:42 +0000230 push @Args, "-Xclang", "-analyzer-viz-egraph-ubigraph";
Ted Kremenek42ec9142011-02-17 02:28:30 +0000231 }
232
Ted Kremenek339f7c32011-03-10 21:10:08 +0000233 my $AnalysisArgs = GetCCArgs("--analyze", \@Args);
234 @CmdArgs = @$AnalysisArgs;
Ted Kremenekf7ffd662008-07-19 06:11:04 +0000235 }
Ted Kremenek42ec9142011-02-17 02:28:30 +0000236
Ted Kremenekf7ffd662008-07-19 06:11:04 +0000237 my @PrintArgs;
238 my $dir;
Ted Kremenek7ac29bb2009-08-02 05:42:46 +0000239
Ted Kremenekf7ffd662008-07-19 06:11:04 +0000240 if ($Verbose) {
241 $dir = getcwd();
242 print STDERR "\n[LOCATION]: $dir\n";
243 push @PrintArgs,"'$Cmd'";
Ted Kremenek42ec9142011-02-17 02:28:30 +0000244 foreach my $arg (@CmdArgs) {
245 push @PrintArgs,"\'$arg\'";
246 }
Ted Kremenekf7ffd662008-07-19 06:11:04 +0000247 }
Ted Kremenekf7ffd662008-07-19 06:11:04 +0000248 if ($Verbose == 1) {
Ted Kremenekf18f4602008-05-24 15:58:54 +0000249 # We MUST print to stderr. Some clients use the stdout output of
Sylvestre Ledru82e547e2014-02-18 17:21:45 +0000250 # gcc for various purposes.
Ted Kremenek339f7c32011-03-10 21:10:08 +0000251 print STDERR join(' ', @PrintArgs);
Ted Kremenekf7ffd662008-07-19 06:11:04 +0000252 print STDERR "\n";
253 }
254 elsif ($Verbose == 2) {
255 print STDERR "#SHELL (cd '$dir' && @PrintArgs)\n";
256 }
Ted Kremenek42ec9142011-02-17 02:28:30 +0000257
Ted Kremenek370de842008-09-04 00:02:34 +0000258 # 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
Sylvestre Ledru82e547e2014-02-18 17:21:45 +0000261 # any problems with the file.
Ted Kremenek4ab81cb2008-09-11 23:05:26 +0000262 pipe (FROM_CHILD, TO_PARENT);
Ted Kremenek370de842008-09-04 00:02:34 +0000263 my $pid = fork();
264 if ($pid == 0) {
Ted Kremenek4ab81cb2008-09-11 23:05:26 +0000265 close FROM_CHILD;
266 open(STDOUT,">&", \*TO_PARENT);
267 open(STDERR,">&", \*TO_PARENT);
Ted Kremenek370de842008-09-04 00:02:34 +0000268 exec $Cmd, @CmdArgs;
269 }
Ted Kremenek42ec9142011-02-17 02:28:30 +0000270
Ted Kremenek4ab81cb2008-09-11 23:05:26 +0000271 close TO_PARENT;
272 my ($ofh, $ofile) = tempfile("clang_output_XXXXXX", DIR => $HtmlDir);
Sylvestre Ledru82e547e2014-02-18 17:21:45 +0000273
Ted Kremenek4ab81cb2008-09-11 23:05:26 +0000274 while (<FROM_CHILD>) {
275 print $ofh $_;
Ted Kremenek42ec9142011-02-17 02:28:30 +0000276 print STDERR $_;
Ted Kremenek4ab81cb2008-09-11 23:05:26 +0000277 }
Jordan Rose85ff8f22012-11-28 19:12:44 +0000278 close $ofh;
Ted Kremenek4ab81cb2008-09-11 23:05:26 +0000279
280 waitpid($pid,0);
Ted Kremenek1f991f02009-05-09 19:19:28 +0000281 close(FROM_CHILD);
Ted Kremenek370de842008-09-04 00:02:34 +0000282 my $Result = $?;
283
284 # Did the command die because of a signal?
Ted Kremenekbfe393f2009-07-30 23:55:19 +0000285 if ($ReportFailures) {
Ted Kremenek5c512e62009-12-11 22:44:53 +0000286 if ($Result & 127 and $Cmd eq $Clang and defined $HtmlDir) {
287 ProcessClangFailure($Clang, $Lang, $file, \@CmdArgsSansAnalyses,
Ted Kremenekbfe393f2009-07-30 23:55:19 +0000288 $HtmlDir, "Crash", $ofile);
Ted Kremenek078b8872009-02-27 06:17:38 +0000289 }
Ted Kremenekbfe393f2009-07-30 23:55:19 +0000290 elsif ($Result) {
291 if ($IncludeParserRejects && !($file =~/conftest/)) {
Ted Kremenek5c512e62009-12-11 22:44:53 +0000292 ProcessClangFailure($Clang, $Lang, $file, \@CmdArgsSansAnalyses,
Ted Kremenekbfe393f2009-07-30 23:55:19 +0000293 $HtmlDir, $ParserRejects, $ofile);
Anna Zaks9fed0842011-11-07 22:38:10 +0000294 } else {
295 ProcessClangFailure($Clang, $Lang, $file, \@CmdArgsSansAnalyses,
Jordan Rose85ff8f22012-11-28 19:12:44 +0000296 $HtmlDir, $OtherError, $ofile);
Ted Kremenek13ed6f12009-02-17 23:31:05 +0000297 }
Ted Kremenekbfe393f2009-07-30 23:55:19 +0000298 }
299 else {
300 # Check if there were any unhandled attributes.
301 if (open(CHILD, $ofile)) {
302 my %attributes_not_handled;
Ted Kremenek42ec9142011-02-17 02:28:30 +0000303
Ted Kremenekbfe393f2009-07-30 23:55:19 +0000304 # Don't flag warnings about the following attributes that we
305 # know are currently not supported by Clang.
306 $attributes_not_handled{"cdecl"} = 1;
Ted Kremenek42ec9142011-02-17 02:28:30 +0000307
Ted Kremenekbfe393f2009-07-30 23:55:19 +0000308 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;
Sylvestre Ledru82e547e2014-02-18 17:21:45 +0000315
Ted Kremenekbfe393f2009-07-30 23:55:19 +0000316 # Get the name of the attribute file.
317 my $dir = "$HtmlDir/failures";
318 my $afile = "$dir/attribute_ignored_$1.txt";
Sylvestre Ledru82e547e2014-02-18 17:21:45 +0000319
Ted Kremenekbfe393f2009-07-30 23:55:19 +0000320 # Only create another preprocessed file if the attribute file
321 # doesn't exist yet.
322 next if (-e $afile);
Sylvestre Ledru82e547e2014-02-18 17:21:45 +0000323
Ted Kremenekbfe393f2009-07-30 23:55:19 +0000324 # 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)) {
Ted Kremenek5c512e62009-12-11 22:44:53 +0000327 $ppfile = ProcessClangFailure($Clang, $Lang, $file,
Ted Kremenekbfe393f2009-07-30 23:55:19 +0000328 \@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 }
Ted Kremenek13ed6f12009-02-17 23:31:05 +0000339 }
340 }
Sylvestre Ledru82e547e2014-02-18 17:21:45 +0000341
Ted Kremenek90fc8a42009-08-04 00:55:59 +0000342 unlink($ofile);
Ted Kremenekf7ffd662008-07-19 06:11:04 +0000343}
Ted Kremenekf18f4602008-05-24 15:58:54 +0000344
Ted Kremenekf7ffd662008-07-19 06:11:04 +0000345##----------------------------------------------------------------------------##
346# Lookup tables.
347##----------------------------------------------------------------------------##
348
349my %CompileOptionMap = (
350 '-nostdinc' => 0,
Ted Kremenekf7ffd662008-07-19 06:11:04 +0000351 '-include' => 1,
352 '-idirafter' => 1,
Ted Kremeneke869a182010-06-08 18:27:55 +0000353 '-imacros' => 1,
Ted Kremenekf7ffd662008-07-19 06:11:04 +0000354 '-iprefix' => 1,
355 '-iquote' => 1,
Ted Kremenekf7ffd662008-07-19 06:11:04 +0000356 '-iwithprefix' => 1,
357 '-iwithprefixbefore' => 1
358);
359
360my %LinkerOptionMap = (
Ted Kremenek415287d2012-03-06 20:06:12 +0000361 '-framework' => 1,
362 '-fobjc-link-runtime' => 0
Ted Kremenekf7ffd662008-07-19 06:11:04 +0000363);
364
365my %CompilerLinkerOptionMap = (
Jordan Rose525121f2013-07-12 16:07:33 +0000366 '-Wwrite-strings' => 0,
Jordan Rose05b3a8b2013-07-11 23:56:12 +0000367 '-ftrapv-handler' => 1, # specifically call out separated -f flag
Ted Kremenek7c88d2a2012-08-07 19:27:08 +0000368 '-mios-simulator-version-min' => 0, # This really has 1 argument, but always has '='
Ted Kremenekf7ffd662008-07-19 06:11:04 +0000369 '-isysroot' => 1,
370 '-arch' => 1,
Charles Davisdde71b92010-03-02 15:26:41 +0000371 '-m32' => 0,
372 '-m64' => 0,
Benjamin Kramer75e4bb12012-09-19 22:56:24 +0000373 '-stdlib' => 0, # This is really a 1 argument, but always has '='
Jordan Rose57ee6d22014-05-12 17:04:44 +0000374 '--sysroot' => 1,
Jordan Rose687fc9a2013-08-08 16:06:26 +0000375 '-target' => 1,
Ted Kremenek6b2e07a2008-09-29 22:45:28 +0000376 '-v' => 0,
Daniel Dunbar497ff132009-04-10 19:52:24 +0000377 '-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 '='
Ted Kremenekf7ffd662008-07-19 06:11:04 +0000379);
380
381my %IgnoredOptionMap = (
Ted Kremenek4a154b22008-07-24 03:52:21 +0000382 '-MT' => 1, # Ignore these preprocessor options.
383 '-MF' => 1,
384
Ted Kremenekf7ffd662008-07-19 06:11:04 +0000385 '-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,
Anna Zaks3a7f73d2012-01-06 01:54:02 +0000398 '-u' => 1,
399 '--serialize-diagnostics' => 1
Ted Kremenekf7ffd662008-07-19 06:11:04 +0000400);
401
402my %LangMap = (
Jordan Rosea63f2292014-01-07 21:39:51 +0000403 'c' => $IsCXX ? 'c++' : 'c',
Shantonu Sendf44f742010-07-03 03:08:23 +0000404 'cp' => 'c++',
Ted Kremenekf7ffd662008-07-19 06:11:04 +0000405 'cpp' => 'c++',
Anna Zaksd6827412012-04-14 16:30:00 +0000406 'cxx' => 'c++',
407 'txx' => 'c++',
Ted Kremenekf7ffd662008-07-19 06:11:04 +0000408 'cc' => 'c++',
Jordan Rosedbbbf5512012-11-28 19:12:29 +0000409 'C' => 'c++',
Jordan Rosea63f2292014-01-07 21:39:51 +0000410 'ii' => 'c++-cpp-output',
411 'i' => $IsCXX ? 'c++-cpp-output' : 'c-cpp-output',
Ted Kremenekf7ffd662008-07-19 06:11:04 +0000412 'm' => 'objective-c',
Anna Zaks5efad632011-08-31 23:53:24 +0000413 'mi' => 'objective-c-cpp-output',
Jordan Rosea63f2292014-01-07 21:39:51 +0000414 'mm' => 'objective-c++',
415 'mii' => 'objective-c++-cpp-output',
Ted Kremenekf7ffd662008-07-19 06:11:04 +0000416);
417
Ted Kremenek8b89a652008-09-29 16:15:20 +0000418my %UniqueOptions = (
Sylvestre Ledru82e547e2014-02-18 17:21:45 +0000419 '-isysroot' => 0
Ted Kremenek8b89a652008-09-29 16:15:20 +0000420);
421
Ted Kremenekadccbca2010-03-08 19:06:44 +0000422##----------------------------------------------------------------------------##
423# Languages accepted.
424##----------------------------------------------------------------------------##
425
Ted Kremenekdc99ec42009-05-11 21:08:34 +0000426my %LangsAccepted = (
427 "objective-c" => 1,
Ted Kremenekd33c4d32011-08-11 22:47:20 +0000428 "c" => 1,
429 "c++" => 1,
Ted Kremenek38d77472014-02-25 19:16:33 +0000430 "objective-c++" => 1,
431 "c-cpp-output" => 1,
432 "objective-c-cpp-output" => 1,
433 "c++-cpp-output" => 1
Ted Kremenekdc99ec42009-05-11 21:08:34 +0000434);
435
Ted Kremenekf7ffd662008-07-19 06:11:04 +0000436##----------------------------------------------------------------------------##
437# Main Logic.
438##----------------------------------------------------------------------------##
439
440my $Action = 'link';
441my @CompileOpts;
442my @LinkOpts;
443my @Files;
444my $Lang;
445my $Output;
Ted Kremenek8b89a652008-09-29 16:15:20 +0000446my %Uniqued;
Ted Kremenekf7ffd662008-07-19 06:11:04 +0000447
448# Forward arguments to gcc.
Ted Kremenekf65a0c62009-12-15 02:35:54 +0000449my $Status = system($Compiler,@ARGV);
Jordan Rose1187b952013-07-03 16:42:02 +0000450if (defined $ENV{'CCC_ANALYZER_LOG'}) {
451 print STDERR "$Compiler @ARGV\n";
Tom Carea5f13c862010-09-29 23:48:31 +0000452}
Ted Kremenek1a422782008-08-28 01:18:44 +0000453if ($Status) { exit($Status >> 8); }
Ted Kremenekf7ffd662008-07-19 06:11:04 +0000454
455# Get the analysis options.
456my $Analyses = $ENV{'CCC_ANALYZER_ANALYSIS'};
Ted Kremenekf7ffd662008-07-19 06:11:04 +0000457
Anna Zaks268f1542012-05-25 01:13:50 +0000458# Get the plugins to load.
459my $Plugins = $ENV{'CCC_ANALYZER_PLUGINS'};
460
Zhongxing Xuad4c3de2008-10-27 14:26:32 +0000461# Get the store model.
462my $StoreModel = $ENV{'CCC_ANALYZER_STORE_MODEL'};
Ted Kremenekb5351812009-02-17 04:27:41 +0000463
464# Get the constraints engine.
465my $ConstraintsModel = $ENV{'CCC_ANALYZER_CONSTRAINTS_MODEL'};
Zhongxing Xuad4c3de2008-10-27 14:26:32 +0000466
Anna Zaks7aa36872012-06-22 22:08:12 +0000467#Get the internal stats setting.
468my $InternalStats = $ENV{'CCC_ANALYZER_INTERNAL_STATS'};
469
Ted Kremenek90230552008-11-04 00:02:53 +0000470# Get the output format.
471my $OutputFormat = $ENV{'CCC_ANALYZER_OUTPUT_FORMAT'};
Ted Kremenekd3d16aa2009-02-17 05:01:10 +0000472if (!defined $OutputFormat) { $OutputFormat = "html"; }
Ted Kremenek90230552008-11-04 00:02:53 +0000473
Jordan Rose3dcbca32013-12-13 17:16:28 +0000474# Get the config options.
475my $ConfigOptions = $ENV{'CCC_ANALYZER_CONFIG'};
476
Ted Kremenekf7ffd662008-07-19 06:11:04 +0000477# Determine the level of verbosity.
478my $Verbose = 0;
Jordan Rose1187b952013-07-03 16:42:02 +0000479if (defined $ENV{'CCC_ANALYZER_VERBOSE'}) { $Verbose = 1; }
480if (defined $ENV{'CCC_ANALYZER_LOG'}) { $Verbose = 2; }
Ted Kremenekf7ffd662008-07-19 06:11:04 +0000481
Ted Kremenekf7ffd662008-07-19 06:11:04 +0000482# Get the HTML output directory.
483my $HtmlDir = $ENV{'CCC_ANALYZER_HTML'};
484
Ted Kremenek9b15eff2009-02-24 22:07:12 +0000485my %DisabledArchs = ('ppc' => 1, 'ppc64' => 1);
Ted Kremenek15146a52008-09-25 20:17:57 +0000486my %ArchsSeen;
Ted Kremenek9b15eff2009-02-24 22:07:12 +0000487my $HadArch = 0;
Ted Kremenek398f46f2014-12-31 07:44:51 +0000488my $HasSDK = 0;
Ted Kremenekf7ffd662008-07-19 06:11:04 +0000489
490# Process the arguments.
491foreach (my $i = 0; $i < scalar(@ARGV); ++$i) {
Sylvestre Ledru82e547e2014-02-18 17:21:45 +0000492 my $Arg = $ARGV[$i];
Ted Kremenekad4a57d2008-10-19 06:42:38 +0000493 my ($ArgKey) = split /=/,$Arg,2;
494
Anna Zaks50b09562015-03-28 02:17:21 +0000495 # Be friendly to "" in the argument list.
496 if (!defined($ArgKey)) {
497 next;
498 }
499
Ted Kremenekf7ffd662008-07-19 06:11:04 +0000500 # Modes ccc-analyzer supports
Ted Kremenekba8d7fc2009-08-04 00:57:12 +0000501 if ($Arg =~ /^-(E|MM?)$/) { $Action = 'preprocess'; }
Ted Kremenekf7ffd662008-07-19 06:11:04 +0000502 elsif ($Arg eq '-c') { $Action = 'compile'; }
503 elsif ($Arg =~ /^-print-prog-name/) { exit 0; }
Ted Kremenek15146a52008-09-25 20:17:57 +0000504
505 # Specially handle duplicate cases of -arch
506 if ($Arg eq "-arch") {
507 my $arch = $ARGV[$i+1];
Ted Kremenek9b15eff2009-02-24 22:07:12 +0000508 # 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;
Ted Kremenek15146a52008-09-25 20:17:57 +0000512 ++$i;
513 next;
514 }
515
Ted Kremenek398f46f2014-12-31 07:44:51 +0000516 # 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
Ted Kremenekf7ffd662008-07-19 06:11:04 +0000522 # Options with possible arguments that should pass through to compiler.
Ted Kremenekad4a57d2008-10-19 06:42:38 +0000523 if (defined $CompileOptionMap{$ArgKey}) {
524 my $Cnt = $CompileOptionMap{$ArgKey};
Ted Kremenekf7ffd662008-07-19 06:11:04 +0000525 push @CompileOpts,$Arg;
526 while ($Cnt > 0) { ++$i; --$Cnt; push @CompileOpts, $ARGV[$i]; }
527 next;
528 }
Ted Kremenek3cfba5b2013-02-14 00:32:25 +0000529 # Handle the case where there isn't a space after -iquote
Jordan Rose69ab7262014-03-19 17:42:26 +0000530 if ($Arg =~ /^-iquote.*/) {
Ted Kremenek3cfba5b2013-02-14 00:32:25 +0000531 push @CompileOpts,$Arg;
532 next;
533 }
Ted Kremenekf7ffd662008-07-19 06:11:04 +0000534
535 # Options with possible arguments that should pass through to linker.
Ted Kremenekad4a57d2008-10-19 06:42:38 +0000536 if (defined $LinkerOptionMap{$ArgKey}) {
537 my $Cnt = $LinkerOptionMap{$ArgKey};
Ted Kremenekf7ffd662008-07-19 06:11:04 +0000538 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.
Ted Kremenekad4a57d2008-10-19 06:42:38 +0000545 if (defined $CompilerLinkerOptionMap{$ArgKey}) {
546 my $Cnt = $CompilerLinkerOptionMap{$ArgKey};
Sylvestre Ledru82e547e2014-02-18 17:21:45 +0000547
Ted Kremenek8b89a652008-09-29 16:15:20 +0000548 # 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 }
Sylvestre Ledru82e547e2014-02-18 17:21:45 +0000557
558 push @CompileOpts,$Arg;
Ted Kremenek887c49d2008-09-29 23:06:09 +0000559 push @LinkOpts,$Arg;
560
Ted Kremenekf7ffd662008-07-19 06:11:04 +0000561 while ($Cnt > 0) {
562 ++$i; --$Cnt;
563 push @CompileOpts, $ARGV[$i];
564 push @LinkOpts, $ARGV[$i];
565 }
566 next;
567 }
Sylvestre Ledru82e547e2014-02-18 17:21:45 +0000568
Ted Kremenekf7ffd662008-07-19 06:11:04 +0000569 # Ignored options.
Ted Kremenekad4a57d2008-10-19 06:42:38 +0000570 if (defined $IgnoredOptionMap{$ArgKey}) {
571 my $Cnt = $IgnoredOptionMap{$ArgKey};
Ted Kremenekf7ffd662008-07-19 06:11:04 +0000572 while ($Cnt > 0) {
573 ++$i; --$Cnt;
574 }
575 next;
576 }
Sylvestre Ledru82e547e2014-02-18 17:21:45 +0000577
Ted Kremenekf7ffd662008-07-19 06:11:04 +0000578 # Compile mode flags.
Ted Kremenek0f26d132015-02-03 06:23:36 +0000579 if ($Arg =~ /^-[D,I,U,isystem](.*)$/) {
Sylvestre Ledru82e547e2014-02-18 17:21:45 +0000580 my $Tmp = $Arg;
Ted Kremenekf7ffd662008-07-19 06:11:04 +0000581 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 }
Sylvestre Ledru82e547e2014-02-18 17:21:45 +0000589
Jordan Rose69ab7262014-03-19 17:42:26 +0000590 if ($Arg =~ /^-m.*/) {
Jordan Rose476bbb022013-10-22 18:55:18 +0000591 push @CompileOpts,$Arg;
592 next;
593 }
Sylvestre Ledru82e547e2014-02-18 17:21:45 +0000594
Ted Kremenekf7ffd662008-07-19 06:11:04 +0000595 # Language.
596 if ($Arg eq '-x') {
597 $Lang = $ARGV[$i+1];
598 ++$i; next;
599 }
Ted Kremenekf18f4602008-05-24 15:58:54 +0000600
Ted Kremenekf7ffd662008-07-19 06:11:04 +0000601 # Output file.
602 if ($Arg eq '-o') {
603 ++$i;
604 $Output = $ARGV[$i];
605 next;
606 }
Sylvestre Ledru82e547e2014-02-18 17:21:45 +0000607
Ted Kremenekf7ffd662008-07-19 06:11:04 +0000608 # 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; }
Jordan Rose05b3a8b2013-07-11 23:56:12 +0000613
614 # Must pass this along for the __OPTIMIZE__ macro
615 if ($Arg =~ /^-O/) { push @CompileOpts,$Arg; }
Ted Kremenekf7ffd662008-07-19 06:11:04 +0000616 next;
617 }
Sylvestre Ledru82e547e2014-02-18 17:21:45 +0000618
Ted Kremenekf7ffd662008-07-19 06:11:04 +0000619 if ($Arg =~ /^-std=/) {
620 push @CompileOpts,$Arg;
621 next;
622 }
Sylvestre Ledru82e547e2014-02-18 17:21:45 +0000623
Ted Kremenekf7ffd662008-07-19 06:11:04 +0000624 # 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 }
Ted Kremenekf18f4602008-05-24 15:58:54 +0000636
Ted Kremenekf7ffd662008-07-19 06:11:04 +0000637 # 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);
Ted Kremenekd0d72562009-08-14 18:20:50 +0000643 ++$i;
644 next;
Ted Kremenekf7ffd662008-07-19 06:11:04 +0000645 }
Sylvestre Ledru82e547e2014-02-18 17:21:45 +0000646
Jordan Rose05b3a8b2013-07-11 23:56:12 +0000647 if ($Arg =~ /^-f/) {
648 push @CompileOpts,$Arg;
649 push @LinkOpts,$Arg;
650 next;
651 }
Sylvestre Ledru82e547e2014-02-18 17:21:45 +0000652
Ted Kremenekd0d72562009-08-14 18:20:50 +0000653 # 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
Ted Kremenekf7ffd662008-07-19 06:11:04 +0000660 if (!($Arg =~ /^-/)) {
Ted Kremenekd0d72562009-08-14 18:20:50 +0000661 push @Files, $Arg;
662 next;
Ted Kremenekf7ffd662008-07-19 06:11:04 +0000663 }
664}
Ted Kremenekf18f4602008-05-24 15:58:54 +0000665
Ted Kremenek398f46f2014-12-31 07:44:51 +0000666# 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.
669if (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
Ted Kremenekf7ffd662008-07-19 06:11:04 +0000675if ($Action eq 'compile' or $Action eq 'link') {
Ted Kremenek9b15eff2009-02-24 22:07:12 +0000676 my @Archs = keys %ArchsSeen;
677 # Skip the file if we don't support the architectures specified.
Ted Kremenek86cb75a2009-02-25 00:10:37 +0000678 exit 0 if ($HadArch && scalar(@Archs) == 0);
Jordan Rose85ff8f22012-11-28 19:12:44 +0000679
Ted Kremenekf7ffd662008-07-19 06:11:04 +0000680 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 }
Sylvestre Ledru82e547e2014-02-18 17:21:45 +0000690
Ted Kremenek14015de2010-02-12 00:10:34 +0000691 # FileLang still not defined? Skip the file.
Ted Kremenekf7ffd662008-07-19 06:11:04 +0000692 next if (!defined $FileLang);
Ted Kremenek14015de2010-02-12 00:10:34 +0000693
694 # Language not accepted?
Ted Kremenekdc99ec42009-05-11 21:08:34 +0000695 next if (!defined $LangsAccepted{$FileLang});
Ted Kremenek14015de2010-02-12 00:10:34 +0000696
Ted Kremenek46727df2009-05-15 04:20:31 +0000697 my @CmdArgs;
Sylvestre Ledru82e547e2014-02-18 17:21:45 +0000698 my @AnalyzeArgs;
699
Ted Kremenekf7ffd662008-07-19 06:11:04 +0000700 if ($FileLang ne 'unknown') {
Ted Kremenekd4bcb4f2011-03-16 21:10:42 +0000701 push @CmdArgs, '-x', $FileLang;
Ted Kremenekf7ffd662008-07-19 06:11:04 +0000702 }
Ted Kremenek5efdf842008-03-25 22:35:32 +0000703
Zhongxing Xuad4c3de2008-10-27 14:26:32 +0000704 if (defined $StoreModel) {
Ted Kremenekb5351812009-02-17 04:27:41 +0000705 push @AnalyzeArgs, "-analyzer-store=$StoreModel";
Zhongxing Xuad4c3de2008-10-27 14:26:32 +0000706 }
Ted Kremenekb5351812009-02-17 04:27:41 +0000707
708 if (defined $ConstraintsModel) {
709 push @AnalyzeArgs, "-analyzer-constraints=$ConstraintsModel";
710 }
Anna Zaks7aa36872012-06-22 22:08:12 +0000711
712 if (defined $InternalStats) {
713 push @AnalyzeArgs, "-analyzer-stats";
714 }
Sylvestre Ledru82e547e2014-02-18 17:21:45 +0000715
Anna Zaks5efad632011-08-31 23:53:24 +0000716 if (defined $Analyses) {
717 push @AnalyzeArgs, split '\s+', $Analyses;
718 }
Ted Kremenekb5351812009-02-17 04:27:41 +0000719
Anna Zaks268f1542012-05-25 01:13:50 +0000720 if (defined $Plugins) {
721 push @AnalyzeArgs, split '\s+', $Plugins;
722 }
723
Ted Kremenek90230552008-11-04 00:02:53 +0000724 if (defined $OutputFormat) {
Ted Kremenekb5351812009-02-17 04:27:41 +0000725 push @AnalyzeArgs, "-analyzer-output=" . $OutputFormat;
Ted Kremenek5cc54862009-07-27 22:10:34 +0000726 if ($OutputFormat =~ /plist/) {
Ted Kremenek13747162009-01-21 00:42:24 +0000727 # Change "Output" to be a file.
728 my ($h, $f) = tempfile("report-XXXXXX", SUFFIX => ".plist",
729 DIR => $HtmlDir);
730 $ResultFile = $f;
Alp Tokerf6a24ce2013-12-05 16:25:25 +0000731 # If the HtmlDir is not set, we should clean up the plist files.
Anna Zaks45ce1bf2011-09-09 18:43:53 +0000732 if (!defined $HtmlDir || -z $HtmlDir) {
Jordan Rose85ff8f22012-11-28 19:12:44 +0000733 $CleanupFile = $f;
Anna Zaks45ce1bf2011-09-09 18:43:53 +0000734 }
Ted Kremenek13747162009-01-21 00:42:24 +0000735 }
Ted Kremenek90230552008-11-04 00:02:53 +0000736 }
Jordan Rose3dcbca32013-12-13 17:16:28 +0000737 if (defined $ConfigOptions) {
738 push @AnalyzeArgs, split '\s+', $ConfigOptions;
739 }
Zhongxing Xuad4c3de2008-10-27 14:26:32 +0000740
Ted Kremenek42ec9142011-02-17 02:28:30 +0000741 push @CmdArgs, @CompileOpts;
742 push @CmdArgs, $file;
Zhongxing Xuad4c3de2008-10-27 14:26:32 +0000743
Ted Kremenek15146a52008-09-25 20:17:57 +0000744 if (scalar @Archs) {
745 foreach my $arch (@Archs) {
746 my @NewArgs;
Ted Kremenekd4bcb4f2011-03-16 21:10:42 +0000747 push @NewArgs, '-arch', $arch;
Ted Kremenek46727df2009-05-15 04:20:31 +0000748 push @NewArgs, @CmdArgs;
Ted Kremenek5c512e62009-12-11 22:44:53 +0000749 Analyze($Clang, \@NewArgs, \@AnalyzeArgs, $FileLang, $Output,
Ted Kremenek42ec9142011-02-17 02:28:30 +0000750 $Verbose, $HtmlDir, $file);
Ted Kremenek15146a52008-09-25 20:17:57 +0000751 }
752 }
753 else {
Ted Kremenek5c512e62009-12-11 22:44:53 +0000754 Analyze($Clang, \@CmdArgs, \@AnalyzeArgs, $FileLang, $Output,
Ted Kremenek42ec9142011-02-17 02:28:30 +0000755 $Verbose, $HtmlDir, $file);
Ted Kremenek15146a52008-09-25 20:17:57 +0000756 }
Ted Kremenekf7ffd662008-07-19 06:11:04 +0000757 }
758}
Ted Kremenek5efdf842008-03-25 22:35:32 +0000759
Ted Kremenek7b628062008-08-27 22:30:34 +0000760exit($Status >> 8);