Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 1 | #!/usr/bin/env perl |
Ted Kremenek | b098288 | 2008-03-25 22:35:32 +0000 | [diff] [blame] | 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 | # |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 10 | # A script designed to interpose between the build system and gcc. It invokes |
| 11 | # both gcc and the static analyzer. |
Ted Kremenek | b098288 | 2008-03-25 22:35:32 +0000 | [diff] [blame] | 12 | # |
| 13 | ##===----------------------------------------------------------------------===## |
| 14 | |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 15 | use strict; |
| 16 | use warnings; |
Ted Kremenek | 51365b5 | 2009-12-15 02:35:54 +0000 | [diff] [blame] | 17 | use FindBin; |
Ted Kremenek | b315a39 | 2008-09-21 19:56:14 +0000 | [diff] [blame] | 18 | use Cwd qw/ getcwd abs_path /; |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 19 | use File::Temp qw/ tempfile /; |
| 20 | use File::Path qw / mkpath /; |
Ted Kremenek | ddf32da | 2009-01-21 00:42:24 +0000 | [diff] [blame] | 21 | use File::Basename; |
Ted Kremenek | 1df35e3 | 2009-05-11 23:29:51 +0000 | [diff] [blame] | 22 | use Text::ParseWords; |
Ted Kremenek | 2ec5cd5 | 2008-08-25 20:44:31 +0000 | [diff] [blame] | 23 | |
Ted Kremenek | 51365b5 | 2009-12-15 02:35:54 +0000 | [diff] [blame] | 24 | ##===----------------------------------------------------------------------===## |
| 25 | # Compiler command setup. |
| 26 | ##===----------------------------------------------------------------------===## |
| 27 | |
| 28 | my $Compiler; |
| 29 | my $Clang; |
| 30 | |
| 31 | if ($FindBin::Script =~ /c\+\+-analyzer/) { |
| 32 | $Compiler = $ENV{'CCC_CXX'}; |
| 33 | if (!defined $Compiler) { $Compiler = "g++"; } |
| 34 | |
| 35 | $Clang = $ENV{'CLANG_CXX'}; |
| 36 | if (!defined $Clang) { $Clang = 'clang++'; } |
| 37 | } |
| 38 | else { |
| 39 | $Compiler = $ENV{'CCC_CC'}; |
| 40 | if (!defined $Compiler) { $Compiler = "gcc"; } |
| 41 | |
| 42 | $Clang = $ENV{'CLANG'}; |
| 43 | if (!defined $Clang) { $Clang = 'clang'; } |
| 44 | } |
| 45 | |
| 46 | ##===----------------------------------------------------------------------===## |
| 47 | # Cleanup. |
| 48 | ##===----------------------------------------------------------------------===## |
Ted Kremenek | e600bed | 2009-07-30 23:55:19 +0000 | [diff] [blame] | 49 | |
| 50 | my $ReportFailures = $ENV{'CCC_REPORT_FAILURES'}; |
| 51 | if (!defined $ReportFailures) { $ReportFailures = 1; } |
| 52 | |
Ted Kremenek | ddf32da | 2009-01-21 00:42:24 +0000 | [diff] [blame] | 53 | my $CleanupFile; |
| 54 | my $ResultFile; |
| 55 | |
| 56 | # Remove any stale files at exit. |
| 57 | END { |
| 58 | if (defined $CleanupFile && -z $CleanupFile) { |
| 59 | `rm -f $CleanupFile`; |
| 60 | } |
| 61 | } |
| 62 | |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 63 | ##----------------------------------------------------------------------------## |
| 64 | # Process Clang Crashes. |
| 65 | ##----------------------------------------------------------------------------## |
| 66 | |
| 67 | sub GetPPExt { |
| 68 | my $Lang = shift; |
Ted Kremenek | 79433b5 | 2009-12-16 18:32:41 +0000 | [diff] [blame] | 69 | if ($Lang =~ /objective-c\+\+/) { return ".mii" }; |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 70 | if ($Lang =~ /objective-c/) { return ".mi"; } |
Ted Kremenek | 51b939f | 2009-12-16 05:02:47 +0000 | [diff] [blame] | 71 | if ($Lang =~ /c\+\+/) { return ".ii"; } |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 72 | return ".i"; |
| 73 | } |
| 74 | |
Ted Kremenek | a4d8cde | 2009-04-28 17:37:44 +0000 | [diff] [blame] | 75 | # Set this to 1 if we want to include 'parser rejects' files. |
| 76 | my $IncludeParserRejects = 0; |
Ted Kremenek | 5daa3be | 2009-01-27 01:19:08 +0000 | [diff] [blame] | 77 | my $ParserRejects = "Parser Rejects"; |
Ted Kremenek | a4d8cde | 2009-04-28 17:37:44 +0000 | [diff] [blame] | 78 | |
Ted Kremenek | 938eef1 | 2009-02-17 23:31:05 +0000 | [diff] [blame] | 79 | my $AttributeIgnored = "Attribute Ignored"; |
Ted Kremenek | 5daa3be | 2009-01-27 01:19:08 +0000 | [diff] [blame] | 80 | |
Ted Kremenek | 5d31f83 | 2008-08-18 18:38:29 +0000 | [diff] [blame] | 81 | sub ProcessClangFailure { |
Ted Kremenek | 2a3a8b9 | 2009-12-11 22:44:53 +0000 | [diff] [blame] | 82 | my ($Clang, $Lang, $file, $Args, $HtmlDir, $ErrorType, $ofile) = @_; |
Ted Kremenek | 938eef1 | 2009-02-17 23:31:05 +0000 | [diff] [blame] | 83 | my $Dir = "$HtmlDir/failures"; |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 84 | mkpath $Dir; |
Ted Kremenek | 5daa3be | 2009-01-27 01:19:08 +0000 | [diff] [blame] | 85 | |
| 86 | my $prefix = "clang_crash"; |
Ted Kremenek | 938eef1 | 2009-02-17 23:31:05 +0000 | [diff] [blame] | 87 | if ($ErrorType eq $ParserRejects) { |
| 88 | $prefix = "clang_parser_rejects"; |
| 89 | } |
| 90 | elsif ($ErrorType eq $AttributeIgnored) { |
| 91 | $prefix = "clang_attribute_ignored"; |
| 92 | } |
Ted Kremenek | c3998fa | 2008-09-25 00:51:44 +0000 | [diff] [blame] | 93 | |
Ted Kremenek | 3386c8a | 2009-07-28 00:14:21 +0000 | [diff] [blame] | 94 | # Generate the preprocessed file with Clang. |
Ted Kremenek | 5daa3be | 2009-01-27 01:19:08 +0000 | [diff] [blame] | 95 | my ($PPH, $PPFile) = tempfile( $prefix . "_XXXXXX", |
| 96 | SUFFIX => GetPPExt($Lang), |
| 97 | DIR => $Dir); |
Ted Kremenek | 2a3a8b9 | 2009-12-11 22:44:53 +0000 | [diff] [blame] | 98 | system $Clang, @$Args, "-E", "-o", $PPFile; |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 99 | close ($PPH); |
Ted Kremenek | c3998fa | 2008-09-25 00:51:44 +0000 | [diff] [blame] | 100 | |
| 101 | # Create the info file. |
Ted Kremenek | 82a1253 | 2008-09-25 00:25:16 +0000 | [diff] [blame] | 102 | open (OUT, ">", "$PPFile.info.txt") or die "Cannot open $PPFile.info.txt\n"; |
Ted Kremenek | 5f2825f | 2008-09-21 18:04:49 +0000 | [diff] [blame] | 103 | print OUT abs_path($file), "\n"; |
Ted Kremenek | 5d31f83 | 2008-08-18 18:38:29 +0000 | [diff] [blame] | 104 | print OUT "$ErrorType\n"; |
Ted Kremenek | 2dd7ad1 | 2008-08-18 20:55:25 +0000 | [diff] [blame] | 105 | print OUT "@$Args\n"; |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 106 | close OUT; |
Ted Kremenek | 82a1253 | 2008-09-25 00:25:16 +0000 | [diff] [blame] | 107 | `uname -a >> $PPFile.info.txt 2>&1`; |
Ted Kremenek | 51365b5 | 2009-12-15 02:35:54 +0000 | [diff] [blame] | 108 | `$Compiler -v >> $PPFile.info.txt 2>&1`; |
Ted Kremenek | 9f9b1fd | 2008-09-12 22:49:36 +0000 | [diff] [blame] | 109 | system 'mv',$ofile,"$PPFile.stderr.txt"; |
Ted Kremenek | 938eef1 | 2009-02-17 23:31:05 +0000 | [diff] [blame] | 110 | return (basename $PPFile); |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 111 | } |
Ted Kremenek | b098288 | 2008-03-25 22:35:32 +0000 | [diff] [blame] | 112 | |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 113 | ##----------------------------------------------------------------------------## |
| 114 | # Running the analyzer. |
| 115 | ##----------------------------------------------------------------------------## |
Ted Kremenek | b098288 | 2008-03-25 22:35:32 +0000 | [diff] [blame] | 116 | |
Ted Kremenek | fd9df0e | 2009-05-09 19:19:28 +0000 | [diff] [blame] | 117 | sub GetCCArgs { |
| 118 | my $Args = shift; |
| 119 | |
| 120 | pipe (FROM_CHILD, TO_PARENT); |
| 121 | my $pid = fork(); |
| 122 | if ($pid == 0) { |
| 123 | close FROM_CHILD; |
| 124 | open(STDOUT,">&", \*TO_PARENT); |
| 125 | open(STDERR,">&", \*TO_PARENT); |
| 126 | exec $Clang, "-###", "-fsyntax-only", @$Args; |
| 127 | } |
| 128 | close(TO_PARENT); |
| 129 | my $line; |
| 130 | while (<FROM_CHILD>) { |
Ted Kremenek | 32317b2 | 2009-12-11 23:12:52 +0000 | [diff] [blame] | 131 | next if (!/-cc1/); |
Ted Kremenek | fd9df0e | 2009-05-09 19:19:28 +0000 | [diff] [blame] | 132 | $line = $_; |
| 133 | } |
| 134 | |
| 135 | waitpid($pid,0); |
| 136 | close(FROM_CHILD); |
| 137 | |
Ted Kremenek | 32317b2 | 2009-12-11 23:12:52 +0000 | [diff] [blame] | 138 | die "could not find clang line\n" if (!defined $line); |
Ted Kremenek | 1df35e3 | 2009-05-11 23:29:51 +0000 | [diff] [blame] | 139 | # Strip the newline and initial whitspace |
| 140 | chomp $line; |
| 141 | $line =~ s/^\s+//; |
Ted Kremenek | 2aefcb2 | 2010-04-06 19:41:24 +0000 | [diff] [blame] | 142 | my @items = quotewords('\s+', 0, $line); |
Ted Kremenek | fd9df0e | 2009-05-09 19:19:28 +0000 | [diff] [blame] | 143 | my $cmd = shift @items; |
Ted Kremenek | 32317b2 | 2009-12-11 23:12:52 +0000 | [diff] [blame] | 144 | die "cannot find 'clang' in 'clang' command\n" if (!($cmd =~ /clang/)); |
Ted Kremenek | fd9df0e | 2009-05-09 19:19:28 +0000 | [diff] [blame] | 145 | return \@items; |
| 146 | } |
| 147 | |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 148 | sub Analyze { |
Ted Kremenek | 2a3a8b9 | 2009-12-11 22:44:53 +0000 | [diff] [blame] | 149 | my ($Clang, $Args, $AnalyzeArgs, $Lang, $Output, $Verbose, $HtmlDir, |
Ted Kremenek | 9a9e0d4 | 2009-05-15 04:20:31 +0000 | [diff] [blame] | 150 | $file, $Analyses) = @_; |
Ted Kremenek | efaf191 | 2009-05-11 21:08:34 +0000 | [diff] [blame] | 151 | |
Ted Kremenek | fd9df0e | 2009-05-09 19:19:28 +0000 | [diff] [blame] | 152 | $Args = GetCCArgs($Args); |
Seo Sanghyeon | d389465 | 2008-04-04 11:02:21 +0000 | [diff] [blame] | 153 | |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 154 | my $RunAnalyzer = 0; |
| 155 | my $Cmd; |
| 156 | my @CmdArgs; |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 157 | my @CmdArgsSansAnalyses; |
Ted Kremenek | 61cd988 | 2008-05-24 15:58:54 +0000 | [diff] [blame] | 158 | |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 159 | if ($Lang =~ /header/) { |
| 160 | exit 0 if (!defined ($Output)); |
| 161 | $Cmd = 'cp'; |
| 162 | push @CmdArgs,$file; |
| 163 | # Remove the PCH extension. |
| 164 | $Output =~ s/[.]gch$//; |
| 165 | push @CmdArgs,$Output; |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 166 | @CmdArgsSansAnalyses = @CmdArgs; |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 167 | } |
| 168 | else { |
Ted Kremenek | 2a3a8b9 | 2009-12-11 22:44:53 +0000 | [diff] [blame] | 169 | $Cmd = $Clang; |
| 170 | push @CmdArgs, "-cc1"; |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 171 | push @CmdArgs,'-DIBOutlet=__attribute__((iboutlet))'; |
Ted Kremenek | 2a3a8b9 | 2009-12-11 22:44:53 +0000 | [diff] [blame] | 172 | push @CmdArgs, @$Args; |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 173 | @CmdArgsSansAnalyses = @CmdArgs; |
Ted Kremenek | 938eef1 | 2009-02-17 23:31:05 +0000 | [diff] [blame] | 174 | push @CmdArgs,'-analyze'; |
| 175 | push @CmdArgs,"-analyzer-display-progress"; |
Ted Kremenek | a2bdaf5 | 2009-02-26 17:36:31 +0000 | [diff] [blame] | 176 | push @CmdArgs,"-analyzer-eagerly-assume"; |
Ted Kremenek | b40d06d | 2009-12-07 22:26:14 +0000 | [diff] [blame] | 177 | push @CmdArgs,"-analyzer-opt-analyze-nested-blocks"; |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 178 | push @CmdArgs,(split /\s/,$Analyses); |
Ted Kremenek | 8382cf5 | 2009-11-13 18:46:29 +0000 | [diff] [blame] | 179 | |
| 180 | if (defined $ENV{"CCC_EXPERIMENTAL_CHECKS"}) { |
| 181 | push @CmdArgs,"-analyzer-experimental-internal-checks"; |
Ted Kremenek | 2a1814a | 2009-11-13 18:49:48 +0000 | [diff] [blame] | 182 | push @CmdArgs,"-analyzer-experimental-checks"; |
Ted Kremenek | 8382cf5 | 2009-11-13 18:46:29 +0000 | [diff] [blame] | 183 | } |
| 184 | |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 185 | $RunAnalyzer = 1; |
| 186 | } |
| 187 | |
Ted Kremenek | 9a9e0d4 | 2009-05-15 04:20:31 +0000 | [diff] [blame] | 188 | # Add the analysis arguments passed down from scan-build. |
| 189 | foreach my $Arg (@$AnalyzeArgs) { |
| 190 | push @CmdArgs, $Arg; |
| 191 | } |
| 192 | |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 193 | my @PrintArgs; |
| 194 | my $dir; |
Ted Kremenek | 63fe5ec | 2009-08-02 05:42:46 +0000 | [diff] [blame] | 195 | |
| 196 | if ($RunAnalyzer) { |
| 197 | if (defined $ResultFile) { |
| 198 | push @CmdArgs,'-o'; |
| 199 | push @CmdArgs, $ResultFile; |
| 200 | } |
| 201 | elsif (defined $HtmlDir) { |
| 202 | push @CmdArgs,'-o'; |
| 203 | push @CmdArgs, $HtmlDir; |
| 204 | } |
| 205 | } |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 206 | |
| 207 | if ($Verbose) { |
| 208 | $dir = getcwd(); |
| 209 | print STDERR "\n[LOCATION]: $dir\n"; |
| 210 | push @PrintArgs,"'$Cmd'"; |
| 211 | foreach my $arg (@CmdArgs) { push @PrintArgs,"\'$arg\'"; } |
| 212 | } |
| 213 | |
| 214 | if ($Verbose == 1) { |
Ted Kremenek | 61cd988 | 2008-05-24 15:58:54 +0000 | [diff] [blame] | 215 | # We MUST print to stderr. Some clients use the stdout output of |
| 216 | # gcc for various purposes. |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 217 | print STDERR join(' ',@PrintArgs); |
| 218 | print STDERR "\n"; |
| 219 | } |
| 220 | elsif ($Verbose == 2) { |
| 221 | print STDERR "#SHELL (cd '$dir' && @PrintArgs)\n"; |
| 222 | } |
Ted Kremenek | 61cd988 | 2008-05-24 15:58:54 +0000 | [diff] [blame] | 223 | |
Ted Kremenek | 948e06b | 2008-08-27 22:30:34 +0000 | [diff] [blame] | 224 | if (defined $ENV{'CCC_UBI'}) { |
| 225 | push @CmdArgs,"--analyzer-viz-egraph-ubigraph"; |
| 226 | } |
Ted Kremenek | fd9df0e | 2009-05-09 19:19:28 +0000 | [diff] [blame] | 227 | |
Ted Kremenek | 9a3c7da | 2008-09-04 00:02:34 +0000 | [diff] [blame] | 228 | # Capture the STDERR of clang and send it to a temporary file. |
| 229 | # Capture the STDOUT of clang and reroute it to ccc-analyzer's STDERR. |
| 230 | # We save the output file in the 'crashes' directory if clang encounters |
| 231 | # any problems with the file. |
Ted Kremenek | 1346268 | 2008-09-11 23:05:26 +0000 | [diff] [blame] | 232 | pipe (FROM_CHILD, TO_PARENT); |
Ted Kremenek | 9a3c7da | 2008-09-04 00:02:34 +0000 | [diff] [blame] | 233 | my $pid = fork(); |
| 234 | if ($pid == 0) { |
Ted Kremenek | 1346268 | 2008-09-11 23:05:26 +0000 | [diff] [blame] | 235 | close FROM_CHILD; |
| 236 | open(STDOUT,">&", \*TO_PARENT); |
| 237 | open(STDERR,">&", \*TO_PARENT); |
Ted Kremenek | 9a3c7da | 2008-09-04 00:02:34 +0000 | [diff] [blame] | 238 | exec $Cmd, @CmdArgs; |
| 239 | } |
Ted Kremenek | 1346268 | 2008-09-11 23:05:26 +0000 | [diff] [blame] | 240 | |
| 241 | close TO_PARENT; |
| 242 | my ($ofh, $ofile) = tempfile("clang_output_XXXXXX", DIR => $HtmlDir); |
| 243 | |
| 244 | while (<FROM_CHILD>) { |
| 245 | print $ofh $_; |
| 246 | print STDERR $_; |
| 247 | } |
| 248 | |
| 249 | waitpid($pid,0); |
Ted Kremenek | fd9df0e | 2009-05-09 19:19:28 +0000 | [diff] [blame] | 250 | close(FROM_CHILD); |
Ted Kremenek | 9a3c7da | 2008-09-04 00:02:34 +0000 | [diff] [blame] | 251 | my $Result = $?; |
| 252 | |
| 253 | # Did the command die because of a signal? |
Ted Kremenek | e600bed | 2009-07-30 23:55:19 +0000 | [diff] [blame] | 254 | if ($ReportFailures) { |
Ted Kremenek | 2a3a8b9 | 2009-12-11 22:44:53 +0000 | [diff] [blame] | 255 | if ($Result & 127 and $Cmd eq $Clang and defined $HtmlDir) { |
| 256 | ProcessClangFailure($Clang, $Lang, $file, \@CmdArgsSansAnalyses, |
Ted Kremenek | e600bed | 2009-07-30 23:55:19 +0000 | [diff] [blame] | 257 | $HtmlDir, "Crash", $ofile); |
Ted Kremenek | 5de4092 | 2009-02-27 06:17:38 +0000 | [diff] [blame] | 258 | } |
Ted Kremenek | e600bed | 2009-07-30 23:55:19 +0000 | [diff] [blame] | 259 | elsif ($Result) { |
| 260 | if ($IncludeParserRejects && !($file =~/conftest/)) { |
Ted Kremenek | 2a3a8b9 | 2009-12-11 22:44:53 +0000 | [diff] [blame] | 261 | ProcessClangFailure($Clang, $Lang, $file, \@CmdArgsSansAnalyses, |
Ted Kremenek | e600bed | 2009-07-30 23:55:19 +0000 | [diff] [blame] | 262 | $HtmlDir, $ParserRejects, $ofile); |
Ted Kremenek | 938eef1 | 2009-02-17 23:31:05 +0000 | [diff] [blame] | 263 | } |
Ted Kremenek | e600bed | 2009-07-30 23:55:19 +0000 | [diff] [blame] | 264 | } |
| 265 | else { |
| 266 | # Check if there were any unhandled attributes. |
| 267 | if (open(CHILD, $ofile)) { |
| 268 | my %attributes_not_handled; |
| 269 | |
| 270 | # Don't flag warnings about the following attributes that we |
| 271 | # know are currently not supported by Clang. |
| 272 | $attributes_not_handled{"cdecl"} = 1; |
| 273 | |
| 274 | my $ppfile; |
| 275 | while (<CHILD>) { |
| 276 | next if (! /warning: '([^\']+)' attribute ignored/); |
| 277 | |
| 278 | # Have we already spotted this unhandled attribute? |
| 279 | next if (defined $attributes_not_handled{$1}); |
| 280 | $attributes_not_handled{$1} = 1; |
| 281 | |
| 282 | # Get the name of the attribute file. |
| 283 | my $dir = "$HtmlDir/failures"; |
| 284 | my $afile = "$dir/attribute_ignored_$1.txt"; |
| 285 | |
| 286 | # Only create another preprocessed file if the attribute file |
| 287 | # doesn't exist yet. |
| 288 | next if (-e $afile); |
| 289 | |
| 290 | # Add this file to the list of files that contained this attribute. |
| 291 | # Generate a preprocessed file if we haven't already. |
| 292 | if (!(defined $ppfile)) { |
Ted Kremenek | 2a3a8b9 | 2009-12-11 22:44:53 +0000 | [diff] [blame] | 293 | $ppfile = ProcessClangFailure($Clang, $Lang, $file, |
Ted Kremenek | e600bed | 2009-07-30 23:55:19 +0000 | [diff] [blame] | 294 | \@CmdArgsSansAnalyses, |
| 295 | $HtmlDir, $AttributeIgnored, $ofile); |
| 296 | } |
| 297 | |
| 298 | mkpath $dir; |
| 299 | open(AFILE, ">$afile"); |
| 300 | print AFILE "$ppfile\n"; |
| 301 | close(AFILE); |
| 302 | } |
| 303 | close CHILD; |
| 304 | } |
Ted Kremenek | 938eef1 | 2009-02-17 23:31:05 +0000 | [diff] [blame] | 305 | } |
| 306 | } |
Ted Kremenek | 9a3c7da | 2008-09-04 00:02:34 +0000 | [diff] [blame] | 307 | |
Ted Kremenek | e3bf8a8 | 2009-08-04 00:55:59 +0000 | [diff] [blame] | 308 | unlink($ofile); |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 309 | } |
Ted Kremenek | 61cd988 | 2008-05-24 15:58:54 +0000 | [diff] [blame] | 310 | |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 311 | ##----------------------------------------------------------------------------## |
| 312 | # Lookup tables. |
| 313 | ##----------------------------------------------------------------------------## |
| 314 | |
| 315 | my %CompileOptionMap = ( |
| 316 | '-nostdinc' => 0, |
Anders Carlsson | 06c58b1 | 2008-12-19 20:56:23 +0000 | [diff] [blame] | 317 | '-fblocks' => 0, |
Shantonu Sen | d9d9726 | 2010-07-03 03:08:23 +0000 | [diff] [blame] | 318 | '-fno-builtin' => 0, |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 319 | '-fobjc-gc-only' => 0, |
Ted Kremenek | 6c4312d | 2009-02-26 23:09:43 +0000 | [diff] [blame] | 320 | '-fobjc-gc' => 0, |
| 321 | '-ffreestanding' => 0, |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 322 | '-include' => 1, |
| 323 | '-idirafter' => 1, |
Ted Kremenek | 55d7d36 | 2010-06-08 18:27:55 +0000 | [diff] [blame] | 324 | '-imacros' => 1, |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 325 | '-iprefix' => 1, |
| 326 | '-iquote' => 1, |
| 327 | '-isystem' => 1, |
| 328 | '-iwithprefix' => 1, |
| 329 | '-iwithprefixbefore' => 1 |
| 330 | ); |
| 331 | |
| 332 | my %LinkerOptionMap = ( |
| 333 | '-framework' => 1 |
| 334 | ); |
| 335 | |
| 336 | my %CompilerLinkerOptionMap = ( |
| 337 | '-isysroot' => 1, |
| 338 | '-arch' => 1, |
Charles Davis | a1359ba | 2010-03-02 15:26:41 +0000 | [diff] [blame] | 339 | '-m32' => 0, |
| 340 | '-m64' => 0, |
Ted Kremenek | e4f6952 | 2008-09-29 22:45:28 +0000 | [diff] [blame] | 341 | '-v' => 0, |
Ted Kremenek | b10362a | 2008-09-30 23:40:25 +0000 | [diff] [blame] | 342 | '-fpascal-strings' => 0, |
Daniel Dunbar | 8d33cd7 | 2009-04-10 19:52:24 +0000 | [diff] [blame] | 343 | '-mmacosx-version-min' => 0, # This is really a 1 argument, but always has '=' |
| 344 | '-miphoneos-version-min' => 0 # This is really a 1 argument, but always has '=' |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 345 | ); |
| 346 | |
| 347 | my %IgnoredOptionMap = ( |
Ted Kremenek | 9402609 | 2008-07-24 03:52:21 +0000 | [diff] [blame] | 348 | '-MT' => 1, # Ignore these preprocessor options. |
| 349 | '-MF' => 1, |
| 350 | |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 351 | '-fsyntax-only' => 0, |
| 352 | '-save-temps' => 0, |
| 353 | '-install_name' => 1, |
| 354 | '-exported_symbols_list' => 1, |
| 355 | '-current_version' => 1, |
| 356 | '-compatibility_version' => 1, |
| 357 | '-init' => 1, |
| 358 | '-e' => 1, |
| 359 | '-seg1addr' => 1, |
| 360 | '-bundle_loader' => 1, |
| 361 | '-multiply_defined' => 1, |
| 362 | '-sectorder' => 3, |
| 363 | '--param' => 1, |
| 364 | '-u' => 1 |
| 365 | ); |
| 366 | |
| 367 | my %LangMap = ( |
| 368 | 'c' => 'c', |
Shantonu Sen | d9d9726 | 2010-07-03 03:08:23 +0000 | [diff] [blame] | 369 | 'cp' => 'c++', |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 370 | 'cpp' => 'c++', |
| 371 | 'cc' => 'c++', |
| 372 | 'i' => 'c-cpp-output', |
| 373 | 'm' => 'objective-c', |
| 374 | 'mi' => 'objective-c-cpp-output' |
| 375 | ); |
| 376 | |
Ted Kremenek | a30730e | 2008-09-29 16:15:20 +0000 | [diff] [blame] | 377 | my %UniqueOptions = ( |
| 378 | '-isysroot' => 0 |
| 379 | ); |
| 380 | |
Ted Kremenek | f6f8d5a | 2010-03-08 19:06:44 +0000 | [diff] [blame] | 381 | ##----------------------------------------------------------------------------## |
| 382 | # Languages accepted. |
| 383 | ##----------------------------------------------------------------------------## |
| 384 | |
Ted Kremenek | efaf191 | 2009-05-11 21:08:34 +0000 | [diff] [blame] | 385 | my %LangsAccepted = ( |
| 386 | "objective-c" => 1, |
Ted Kremenek | f6f8d5a | 2010-03-08 19:06:44 +0000 | [diff] [blame] | 387 | "c" => 1 |
Ted Kremenek | efaf191 | 2009-05-11 21:08:34 +0000 | [diff] [blame] | 388 | ); |
| 389 | |
Ted Kremenek | f6f8d5a | 2010-03-08 19:06:44 +0000 | [diff] [blame] | 390 | if (defined $ENV{'CCC_ANALYZER_CPLUSPLUS'}) { |
| 391 | $LangsAccepted{"c++"} = 1; |
| 392 | $LangsAccepted{"objective-c++"} = 1; |
| 393 | } |
| 394 | |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 395 | ##----------------------------------------------------------------------------## |
| 396 | # Main Logic. |
| 397 | ##----------------------------------------------------------------------------## |
| 398 | |
| 399 | my $Action = 'link'; |
| 400 | my @CompileOpts; |
| 401 | my @LinkOpts; |
| 402 | my @Files; |
| 403 | my $Lang; |
| 404 | my $Output; |
Ted Kremenek | a30730e | 2008-09-29 16:15:20 +0000 | [diff] [blame] | 405 | my %Uniqued; |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 406 | |
| 407 | # Forward arguments to gcc. |
Ted Kremenek | 51365b5 | 2009-12-15 02:35:54 +0000 | [diff] [blame] | 408 | my $Status = system($Compiler,@ARGV); |
Tom Care | a716f63 | 2010-09-29 23:48:31 +0000 | [diff] [blame^] | 409 | if (defined $ENV{'CCC_ANALYZER_LOG'}) { |
| 410 | print "$Compiler @ARGV\n"; |
| 411 | } |
Ted Kremenek | cb344d0 | 2008-08-28 01:18:44 +0000 | [diff] [blame] | 412 | if ($Status) { exit($Status >> 8); } |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 413 | |
| 414 | # Get the analysis options. |
| 415 | my $Analyses = $ENV{'CCC_ANALYZER_ANALYSIS'}; |
Ted Kremenek | 565e465 | 2010-02-05 02:06:54 +0000 | [diff] [blame] | 416 | if (!defined($Analyses)) { $Analyses = '-analyzer-check-objc-mem'; } |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 417 | |
Zhongxing Xu | 07c3767 | 2008-10-27 14:26:32 +0000 | [diff] [blame] | 418 | # Get the store model. |
| 419 | my $StoreModel = $ENV{'CCC_ANALYZER_STORE_MODEL'}; |
Ted Kremenek | b8bb3e7 | 2009-09-25 05:55:59 +0000 | [diff] [blame] | 420 | if (!defined $StoreModel) { $StoreModel = "region"; } |
Ted Kremenek | be1fe1e | 2009-02-17 04:27:41 +0000 | [diff] [blame] | 421 | |
| 422 | # Get the constraints engine. |
| 423 | my $ConstraintsModel = $ENV{'CCC_ANALYZER_CONSTRAINTS_MODEL'}; |
Ted Kremenek | 9f4ecb3 | 2009-02-20 21:49:22 +0000 | [diff] [blame] | 424 | if (!defined $ConstraintsModel) { $ConstraintsModel = "range"; } |
Zhongxing Xu | 07c3767 | 2008-10-27 14:26:32 +0000 | [diff] [blame] | 425 | |
Ted Kremenek | db4f5f2 | 2008-11-04 00:02:53 +0000 | [diff] [blame] | 426 | # Get the output format. |
| 427 | my $OutputFormat = $ENV{'CCC_ANALYZER_OUTPUT_FORMAT'}; |
Ted Kremenek | 3891a15 | 2009-02-17 05:01:10 +0000 | [diff] [blame] | 428 | if (!defined $OutputFormat) { $OutputFormat = "html"; } |
Ted Kremenek | db4f5f2 | 2008-11-04 00:02:53 +0000 | [diff] [blame] | 429 | |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 430 | # Determine the level of verbosity. |
| 431 | my $Verbose = 0; |
| 432 | if (defined $ENV{CCC_ANALYZER_VERBOSE}) { $Verbose = 1; } |
| 433 | if (defined $ENV{CCC_ANALYZER_LOG}) { $Verbose = 2; } |
| 434 | |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 435 | # Get the HTML output directory. |
| 436 | my $HtmlDir = $ENV{'CCC_ANALYZER_HTML'}; |
| 437 | |
Ted Kremenek | 8459132 | 2009-02-24 22:07:12 +0000 | [diff] [blame] | 438 | my %DisabledArchs = ('ppc' => 1, 'ppc64' => 1); |
Ted Kremenek | 27783eb | 2008-09-25 20:17:57 +0000 | [diff] [blame] | 439 | my %ArchsSeen; |
Ted Kremenek | 8459132 | 2009-02-24 22:07:12 +0000 | [diff] [blame] | 440 | my $HadArch = 0; |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 441 | |
| 442 | # Process the arguments. |
| 443 | foreach (my $i = 0; $i < scalar(@ARGV); ++$i) { |
Ted Kremenek | 89c4fcf | 2008-10-19 06:42:38 +0000 | [diff] [blame] | 444 | my $Arg = $ARGV[$i]; |
| 445 | my ($ArgKey) = split /=/,$Arg,2; |
| 446 | |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 447 | # Modes ccc-analyzer supports |
Ted Kremenek | d732a7b | 2009-08-04 00:57:12 +0000 | [diff] [blame] | 448 | if ($Arg =~ /^-(E|MM?)$/) { $Action = 'preprocess'; } |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 449 | elsif ($Arg eq '-c') { $Action = 'compile'; } |
| 450 | elsif ($Arg =~ /^-print-prog-name/) { exit 0; } |
Ted Kremenek | 27783eb | 2008-09-25 20:17:57 +0000 | [diff] [blame] | 451 | |
| 452 | # Specially handle duplicate cases of -arch |
| 453 | if ($Arg eq "-arch") { |
| 454 | my $arch = $ARGV[$i+1]; |
Ted Kremenek | 8459132 | 2009-02-24 22:07:12 +0000 | [diff] [blame] | 455 | # We don't want to process 'ppc' because of Clang's lack of support |
| 456 | # for Altivec (also some #defines won't likely be defined correctly, etc.) |
| 457 | if (!(defined $DisabledArchs{$arch})) { $ArchsSeen{$arch} = 1; } |
| 458 | $HadArch = 1; |
Ted Kremenek | 27783eb | 2008-09-25 20:17:57 +0000 | [diff] [blame] | 459 | ++$i; |
| 460 | next; |
| 461 | } |
| 462 | |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 463 | # Options with possible arguments that should pass through to compiler. |
Ted Kremenek | 89c4fcf | 2008-10-19 06:42:38 +0000 | [diff] [blame] | 464 | if (defined $CompileOptionMap{$ArgKey}) { |
| 465 | my $Cnt = $CompileOptionMap{$ArgKey}; |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 466 | push @CompileOpts,$Arg; |
| 467 | while ($Cnt > 0) { ++$i; --$Cnt; push @CompileOpts, $ARGV[$i]; } |
| 468 | next; |
| 469 | } |
| 470 | |
| 471 | # Options with possible arguments that should pass through to linker. |
Ted Kremenek | 89c4fcf | 2008-10-19 06:42:38 +0000 | [diff] [blame] | 472 | if (defined $LinkerOptionMap{$ArgKey}) { |
| 473 | my $Cnt = $LinkerOptionMap{$ArgKey}; |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 474 | push @LinkOpts,$Arg; |
| 475 | while ($Cnt > 0) { ++$i; --$Cnt; push @LinkOpts, $ARGV[$i]; } |
| 476 | next; |
| 477 | } |
| 478 | |
| 479 | # Options with possible arguments that should pass through to both compiler |
| 480 | # and the linker. |
Ted Kremenek | 89c4fcf | 2008-10-19 06:42:38 +0000 | [diff] [blame] | 481 | if (defined $CompilerLinkerOptionMap{$ArgKey}) { |
| 482 | my $Cnt = $CompilerLinkerOptionMap{$ArgKey}; |
Ted Kremenek | 47fc25f | 2008-09-29 23:06:09 +0000 | [diff] [blame] | 483 | |
Ted Kremenek | a30730e | 2008-09-29 16:15:20 +0000 | [diff] [blame] | 484 | # Check if this is an option that should have a unique value, and if so |
| 485 | # determine if the value was checked before. |
| 486 | if ($UniqueOptions{$Arg}) { |
| 487 | if (defined $Uniqued{$Arg}) { |
| 488 | $i += $Cnt; |
| 489 | next; |
| 490 | } |
| 491 | $Uniqued{$Arg} = 1; |
| 492 | } |
| 493 | |
Ted Kremenek | 47fc25f | 2008-09-29 23:06:09 +0000 | [diff] [blame] | 494 | push @CompileOpts,$Arg; |
| 495 | push @LinkOpts,$Arg; |
| 496 | |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 497 | while ($Cnt > 0) { |
| 498 | ++$i; --$Cnt; |
| 499 | push @CompileOpts, $ARGV[$i]; |
| 500 | push @LinkOpts, $ARGV[$i]; |
| 501 | } |
| 502 | next; |
| 503 | } |
Ted Kremenek | 61cd988 | 2008-05-24 15:58:54 +0000 | [diff] [blame] | 504 | |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 505 | # Ignored options. |
Ted Kremenek | 89c4fcf | 2008-10-19 06:42:38 +0000 | [diff] [blame] | 506 | if (defined $IgnoredOptionMap{$ArgKey}) { |
| 507 | my $Cnt = $IgnoredOptionMap{$ArgKey}; |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 508 | while ($Cnt > 0) { |
| 509 | ++$i; --$Cnt; |
| 510 | } |
| 511 | next; |
| 512 | } |
Ted Kremenek | 61cd988 | 2008-05-24 15:58:54 +0000 | [diff] [blame] | 513 | |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 514 | # Compile mode flags. |
| 515 | if ($Arg =~ /^-[D,I,U](.*)$/) { |
| 516 | my $Tmp = $Arg; |
| 517 | if ($1 eq '') { |
| 518 | # FIXME: Check if we are going off the end. |
| 519 | ++$i; |
| 520 | $Tmp = $Arg . $ARGV[$i]; |
| 521 | } |
| 522 | push @CompileOpts,$Tmp; |
| 523 | next; |
| 524 | } |
| 525 | |
| 526 | # Language. |
| 527 | if ($Arg eq '-x') { |
| 528 | $Lang = $ARGV[$i+1]; |
| 529 | ++$i; next; |
| 530 | } |
Ted Kremenek | 61cd988 | 2008-05-24 15:58:54 +0000 | [diff] [blame] | 531 | |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 532 | # Output file. |
| 533 | if ($Arg eq '-o') { |
| 534 | ++$i; |
| 535 | $Output = $ARGV[$i]; |
| 536 | next; |
| 537 | } |
| 538 | |
| 539 | # Get the link mode. |
| 540 | if ($Arg =~ /^-[l,L,O]/) { |
| 541 | if ($Arg eq '-O') { push @LinkOpts,'-O1'; } |
| 542 | elsif ($Arg eq '-Os') { push @LinkOpts,'-O2'; } |
| 543 | else { push @LinkOpts,$Arg; } |
| 544 | next; |
| 545 | } |
| 546 | |
| 547 | if ($Arg =~ /^-std=/) { |
| 548 | push @CompileOpts,$Arg; |
| 549 | next; |
| 550 | } |
| 551 | |
| 552 | # if ($Arg =~ /^-f/) { |
| 553 | # # FIXME: Not sure if the remaining -fxxxx options have no arguments. |
| 554 | # push @CompileOpts,$Arg; |
| 555 | # push @LinkOpts,$Arg; # FIXME: Not sure if these are link opts. |
| 556 | # } |
| 557 | |
| 558 | # Get the compiler/link mode. |
| 559 | if ($Arg =~ /^-F(.+)$/) { |
| 560 | my $Tmp = $Arg; |
| 561 | if ($1 eq '') { |
| 562 | # FIXME: Check if we are going off the end. |
| 563 | ++$i; |
| 564 | $Tmp = $Arg . $ARGV[$i]; |
| 565 | } |
| 566 | push @CompileOpts,$Tmp; |
| 567 | push @LinkOpts,$Tmp; |
| 568 | next; |
| 569 | } |
Ted Kremenek | 61cd988 | 2008-05-24 15:58:54 +0000 | [diff] [blame] | 570 | |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 571 | # Input files. |
| 572 | if ($Arg eq '-filelist') { |
| 573 | # FIXME: Make sure we aren't walking off the end. |
| 574 | open(IN, $ARGV[$i+1]); |
| 575 | while (<IN>) { s/\015?\012//; push @Files,$_; } |
| 576 | close(IN); |
Ted Kremenek | 0895937 | 2009-08-14 18:20:50 +0000 | [diff] [blame] | 577 | ++$i; |
| 578 | next; |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 579 | } |
| 580 | |
Ted Kremenek | 0895937 | 2009-08-14 18:20:50 +0000 | [diff] [blame] | 581 | # Handle -Wno-. We don't care about extra warnings, but |
| 582 | # we should suppress ones that we don't want to see. |
| 583 | if ($Arg =~ /^-Wno-/) { |
| 584 | push @CompileOpts, $Arg; |
| 585 | next; |
| 586 | } |
| 587 | |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 588 | if (!($Arg =~ /^-/)) { |
Ted Kremenek | 0895937 | 2009-08-14 18:20:50 +0000 | [diff] [blame] | 589 | push @Files, $Arg; |
| 590 | next; |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 591 | } |
| 592 | } |
Ted Kremenek | 61cd988 | 2008-05-24 15:58:54 +0000 | [diff] [blame] | 593 | |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 594 | if ($Action eq 'compile' or $Action eq 'link') { |
Ted Kremenek | 8459132 | 2009-02-24 22:07:12 +0000 | [diff] [blame] | 595 | my @Archs = keys %ArchsSeen; |
| 596 | # Skip the file if we don't support the architectures specified. |
Ted Kremenek | 0e0eb8b | 2009-02-25 00:10:37 +0000 | [diff] [blame] | 597 | exit 0 if ($HadArch && scalar(@Archs) == 0); |
Ted Kremenek | 8459132 | 2009-02-24 22:07:12 +0000 | [diff] [blame] | 598 | |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 599 | foreach my $file (@Files) { |
| 600 | # Determine the language for the file. |
| 601 | my $FileLang = $Lang; |
| 602 | |
| 603 | if (!defined($FileLang)) { |
| 604 | # Infer the language from the extension. |
| 605 | if ($file =~ /[.]([^.]+)$/) { |
| 606 | $FileLang = $LangMap{$1}; |
| 607 | } |
| 608 | } |
Ted Kremenek | 1262fc4 | 2008-05-14 20:10:33 +0000 | [diff] [blame] | 609 | |
Ted Kremenek | 1d81ed9 | 2010-02-12 00:10:34 +0000 | [diff] [blame] | 610 | # FileLang still not defined? Skip the file. |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 611 | next if (!defined $FileLang); |
Ted Kremenek | 1d81ed9 | 2010-02-12 00:10:34 +0000 | [diff] [blame] | 612 | |
| 613 | # Language not accepted? |
Ted Kremenek | efaf191 | 2009-05-11 21:08:34 +0000 | [diff] [blame] | 614 | next if (!defined $LangsAccepted{$FileLang}); |
Ted Kremenek | 1d81ed9 | 2010-02-12 00:10:34 +0000 | [diff] [blame] | 615 | |
Ted Kremenek | 9a9e0d4 | 2009-05-15 04:20:31 +0000 | [diff] [blame] | 616 | my @CmdArgs; |
| 617 | my @AnalyzeArgs; |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 618 | |
| 619 | if ($FileLang ne 'unknown') { |
Ted Kremenek | 9a9e0d4 | 2009-05-15 04:20:31 +0000 | [diff] [blame] | 620 | push @CmdArgs,'-x'; |
| 621 | push @CmdArgs,$FileLang; |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 622 | } |
Ted Kremenek | b098288 | 2008-03-25 22:35:32 +0000 | [diff] [blame] | 623 | |
Zhongxing Xu | 07c3767 | 2008-10-27 14:26:32 +0000 | [diff] [blame] | 624 | if (defined $StoreModel) { |
Ted Kremenek | be1fe1e | 2009-02-17 04:27:41 +0000 | [diff] [blame] | 625 | push @AnalyzeArgs, "-analyzer-store=$StoreModel"; |
Zhongxing Xu | 07c3767 | 2008-10-27 14:26:32 +0000 | [diff] [blame] | 626 | } |
Ted Kremenek | be1fe1e | 2009-02-17 04:27:41 +0000 | [diff] [blame] | 627 | |
| 628 | if (defined $ConstraintsModel) { |
| 629 | push @AnalyzeArgs, "-analyzer-constraints=$ConstraintsModel"; |
| 630 | } |
| 631 | |
Ted Kremenek | db4f5f2 | 2008-11-04 00:02:53 +0000 | [diff] [blame] | 632 | if (defined $OutputFormat) { |
Ted Kremenek | be1fe1e | 2009-02-17 04:27:41 +0000 | [diff] [blame] | 633 | push @AnalyzeArgs, "-analyzer-output=" . $OutputFormat; |
Ted Kremenek | 7753b35 | 2009-07-27 22:10:34 +0000 | [diff] [blame] | 634 | if ($OutputFormat =~ /plist/) { |
Ted Kremenek | ddf32da | 2009-01-21 00:42:24 +0000 | [diff] [blame] | 635 | # Change "Output" to be a file. |
| 636 | my ($h, $f) = tempfile("report-XXXXXX", SUFFIX => ".plist", |
| 637 | DIR => $HtmlDir); |
| 638 | $ResultFile = $f; |
| 639 | $CleanupFile = $f; |
| 640 | } |
Ted Kremenek | db4f5f2 | 2008-11-04 00:02:53 +0000 | [diff] [blame] | 641 | } |
Zhongxing Xu | 07c3767 | 2008-10-27 14:26:32 +0000 | [diff] [blame] | 642 | |
Ted Kremenek | 9a9e0d4 | 2009-05-15 04:20:31 +0000 | [diff] [blame] | 643 | push @CmdArgs,@CompileOpts; |
| 644 | push @CmdArgs,$file; |
Zhongxing Xu | 07c3767 | 2008-10-27 14:26:32 +0000 | [diff] [blame] | 645 | |
Ted Kremenek | 27783eb | 2008-09-25 20:17:57 +0000 | [diff] [blame] | 646 | if (scalar @Archs) { |
| 647 | foreach my $arch (@Archs) { |
| 648 | my @NewArgs; |
| 649 | push @NewArgs, '-arch'; |
| 650 | push @NewArgs, $arch; |
Ted Kremenek | 9a9e0d4 | 2009-05-15 04:20:31 +0000 | [diff] [blame] | 651 | push @NewArgs, @CmdArgs; |
Ted Kremenek | 2a3a8b9 | 2009-12-11 22:44:53 +0000 | [diff] [blame] | 652 | Analyze($Clang, \@NewArgs, \@AnalyzeArgs, $FileLang, $Output, |
Ted Kremenek | 27783eb | 2008-09-25 20:17:57 +0000 | [diff] [blame] | 653 | $Verbose, $HtmlDir, $file, $Analyses); |
| 654 | } |
| 655 | } |
| 656 | else { |
Ted Kremenek | 2a3a8b9 | 2009-12-11 22:44:53 +0000 | [diff] [blame] | 657 | Analyze($Clang, \@CmdArgs, \@AnalyzeArgs, $FileLang, $Output, |
Ted Kremenek | 27783eb | 2008-09-25 20:17:57 +0000 | [diff] [blame] | 658 | $Verbose, $HtmlDir, $file, $Analyses); |
| 659 | } |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 660 | } |
| 661 | } |
Ted Kremenek | b098288 | 2008-03-25 22:35:32 +0000 | [diff] [blame] | 662 | |
Ted Kremenek | 948e06b | 2008-08-27 22:30:34 +0000 | [diff] [blame] | 663 | exit($Status >> 8); |
| 664 | |