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