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 { |
Anna Zaks | 9134294 | 2011-09-09 18:43:53 +0000 | [diff] [blame] | 58 | if (defined $ResultFile && -z $ResultFile) { |
| 59 | `rm -f $ResultFile`; |
| 60 | } |
| 61 | if (defined $CleanupFile) { |
Ted Kremenek | ddf32da | 2009-01-21 00:42:24 +0000 | [diff] [blame] | 62 | `rm -f $CleanupFile`; |
| 63 | } |
| 64 | } |
| 65 | |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 66 | ##----------------------------------------------------------------------------## |
| 67 | # Process Clang Crashes. |
| 68 | ##----------------------------------------------------------------------------## |
| 69 | |
| 70 | sub GetPPExt { |
| 71 | my $Lang = shift; |
Ted Kremenek | 79433b5 | 2009-12-16 18:32:41 +0000 | [diff] [blame] | 72 | if ($Lang =~ /objective-c\+\+/) { return ".mii" }; |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 73 | if ($Lang =~ /objective-c/) { return ".mi"; } |
Ted Kremenek | 51b939f | 2009-12-16 05:02:47 +0000 | [diff] [blame] | 74 | if ($Lang =~ /c\+\+/) { return ".ii"; } |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 75 | return ".i"; |
| 76 | } |
| 77 | |
Ted Kremenek | a4d8cde | 2009-04-28 17:37:44 +0000 | [diff] [blame] | 78 | # Set this to 1 if we want to include 'parser rejects' files. |
| 79 | my $IncludeParserRejects = 0; |
Ted Kremenek | 5daa3be | 2009-01-27 01:19:08 +0000 | [diff] [blame] | 80 | my $ParserRejects = "Parser Rejects"; |
Ted Kremenek | a4d8cde | 2009-04-28 17:37:44 +0000 | [diff] [blame] | 81 | |
Ted Kremenek | 938eef1 | 2009-02-17 23:31:05 +0000 | [diff] [blame] | 82 | my $AttributeIgnored = "Attribute Ignored"; |
Ted Kremenek | 5daa3be | 2009-01-27 01:19:08 +0000 | [diff] [blame] | 83 | |
Ted Kremenek | 5d31f83 | 2008-08-18 18:38:29 +0000 | [diff] [blame] | 84 | sub ProcessClangFailure { |
Ted Kremenek | 2a3a8b9 | 2009-12-11 22:44:53 +0000 | [diff] [blame] | 85 | my ($Clang, $Lang, $file, $Args, $HtmlDir, $ErrorType, $ofile) = @_; |
Ted Kremenek | 938eef1 | 2009-02-17 23:31:05 +0000 | [diff] [blame] | 86 | my $Dir = "$HtmlDir/failures"; |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 87 | mkpath $Dir; |
Ted Kremenek | 5daa3be | 2009-01-27 01:19:08 +0000 | [diff] [blame] | 88 | |
| 89 | my $prefix = "clang_crash"; |
Ted Kremenek | 938eef1 | 2009-02-17 23:31:05 +0000 | [diff] [blame] | 90 | if ($ErrorType eq $ParserRejects) { |
| 91 | $prefix = "clang_parser_rejects"; |
| 92 | } |
| 93 | elsif ($ErrorType eq $AttributeIgnored) { |
| 94 | $prefix = "clang_attribute_ignored"; |
| 95 | } |
Ted Kremenek | c3998fa | 2008-09-25 00:51:44 +0000 | [diff] [blame] | 96 | |
Ted Kremenek | 3386c8a | 2009-07-28 00:14:21 +0000 | [diff] [blame] | 97 | # Generate the preprocessed file with Clang. |
Ted Kremenek | 5daa3be | 2009-01-27 01:19:08 +0000 | [diff] [blame] | 98 | my ($PPH, $PPFile) = tempfile( $prefix . "_XXXXXX", |
| 99 | SUFFIX => GetPPExt($Lang), |
| 100 | DIR => $Dir); |
Ted Kremenek | 2a3a8b9 | 2009-12-11 22:44:53 +0000 | [diff] [blame] | 101 | system $Clang, @$Args, "-E", "-o", $PPFile; |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 102 | close ($PPH); |
Ted Kremenek | c3998fa | 2008-09-25 00:51:44 +0000 | [diff] [blame] | 103 | |
| 104 | # Create the info file. |
Ted Kremenek | 82a1253 | 2008-09-25 00:25:16 +0000 | [diff] [blame] | 105 | 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] | 106 | print OUT abs_path($file), "\n"; |
Ted Kremenek | 5d31f83 | 2008-08-18 18:38:29 +0000 | [diff] [blame] | 107 | print OUT "$ErrorType\n"; |
Ted Kremenek | 2dd7ad1 | 2008-08-18 20:55:25 +0000 | [diff] [blame] | 108 | print OUT "@$Args\n"; |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 109 | close OUT; |
Ted Kremenek | 82a1253 | 2008-09-25 00:25:16 +0000 | [diff] [blame] | 110 | `uname -a >> $PPFile.info.txt 2>&1`; |
Ted Kremenek | 51365b5 | 2009-12-15 02:35:54 +0000 | [diff] [blame] | 111 | `$Compiler -v >> $PPFile.info.txt 2>&1`; |
Ted Kremenek | 9f9b1fd | 2008-09-12 22:49:36 +0000 | [diff] [blame] | 112 | system 'mv',$ofile,"$PPFile.stderr.txt"; |
Ted Kremenek | 938eef1 | 2009-02-17 23:31:05 +0000 | [diff] [blame] | 113 | return (basename $PPFile); |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 114 | } |
Ted Kremenek | b098288 | 2008-03-25 22:35:32 +0000 | [diff] [blame] | 115 | |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 116 | ##----------------------------------------------------------------------------## |
| 117 | # Running the analyzer. |
| 118 | ##----------------------------------------------------------------------------## |
Ted Kremenek | b098288 | 2008-03-25 22:35:32 +0000 | [diff] [blame] | 119 | |
Ted Kremenek | fd9df0e | 2009-05-09 19:19:28 +0000 | [diff] [blame] | 120 | sub GetCCArgs { |
Ted Kremenek | 7fe679f | 2011-02-17 02:28:30 +0000 | [diff] [blame] | 121 | my $mode = shift; |
Ted Kremenek | fd9df0e | 2009-05-09 19:19:28 +0000 | [diff] [blame] | 122 | my $Args = shift; |
| 123 | |
| 124 | pipe (FROM_CHILD, TO_PARENT); |
| 125 | my $pid = fork(); |
| 126 | if ($pid == 0) { |
| 127 | close FROM_CHILD; |
| 128 | open(STDOUT,">&", \*TO_PARENT); |
| 129 | open(STDERR,">&", \*TO_PARENT); |
Ted Kremenek | 7fe679f | 2011-02-17 02:28:30 +0000 | [diff] [blame] | 130 | exec $Clang, "-###", $mode, @$Args; |
Ted Kremenek | fd9df0e | 2009-05-09 19:19:28 +0000 | [diff] [blame] | 131 | } |
| 132 | close(TO_PARENT); |
| 133 | my $line; |
| 134 | while (<FROM_CHILD>) { |
Ted Kremenek | 32317b2 | 2009-12-11 23:12:52 +0000 | [diff] [blame] | 135 | next if (!/-cc1/); |
Ted Kremenek | fd9df0e | 2009-05-09 19:19:28 +0000 | [diff] [blame] | 136 | $line = $_; |
| 137 | } |
| 138 | |
| 139 | waitpid($pid,0); |
| 140 | close(FROM_CHILD); |
| 141 | |
Ted Kremenek | 32317b2 | 2009-12-11 23:12:52 +0000 | [diff] [blame] | 142 | die "could not find clang line\n" if (!defined $line); |
Ted Kremenek | 1df35e3 | 2009-05-11 23:29:51 +0000 | [diff] [blame] | 143 | # Strip the newline and initial whitspace |
Ted Kremenek | 7fe679f | 2011-02-17 02:28:30 +0000 | [diff] [blame] | 144 | chomp $line; |
Ted Kremenek | 1df35e3 | 2009-05-11 23:29:51 +0000 | [diff] [blame] | 145 | $line =~ s/^\s+//; |
Ted Kremenek | 2aefcb2 | 2010-04-06 19:41:24 +0000 | [diff] [blame] | 146 | my @items = quotewords('\s+', 0, $line); |
Ted Kremenek | fd9df0e | 2009-05-09 19:19:28 +0000 | [diff] [blame] | 147 | my $cmd = shift @items; |
Ted Kremenek | 32317b2 | 2009-12-11 23:12:52 +0000 | [diff] [blame] | 148 | die "cannot find 'clang' in 'clang' command\n" if (!($cmd =~ /clang/)); |
Ted Kremenek | fd9df0e | 2009-05-09 19:19:28 +0000 | [diff] [blame] | 149 | return \@items; |
| 150 | } |
| 151 | |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 152 | sub Analyze { |
Ted Kremenek | 27871ea | 2011-03-10 21:10:08 +0000 | [diff] [blame] | 153 | my ($Clang, $OriginalArgs, $AnalyzeArgs, $Lang, $Output, $Verbose, $HtmlDir, |
Ted Kremenek | 7fe679f | 2011-02-17 02:28:30 +0000 | [diff] [blame] | 154 | $file) = @_; |
Seo Sanghyeon | d389465 | 2008-04-04 11:02:21 +0000 | [diff] [blame] | 155 | |
Ted Kremenek | 27871ea | 2011-03-10 21:10:08 +0000 | [diff] [blame] | 156 | my @Args = @$OriginalArgs; |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 157 | my $Cmd; |
| 158 | my @CmdArgs; |
Ted Kremenek | 991c54b | 2008-08-08 20:46:42 +0000 | [diff] [blame] | 159 | my @CmdArgsSansAnalyses; |
Ted Kremenek | 7fe679f | 2011-02-17 02:28:30 +0000 | [diff] [blame] | 160 | |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 161 | if ($Lang =~ /header/) { |
| 162 | exit 0 if (!defined ($Output)); |
| 163 | $Cmd = 'cp'; |
Ted Kremenek | 7fe679f | 2011-02-17 02:28:30 +0000 | [diff] [blame] | 164 | push @CmdArgs, $file; |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 165 | # Remove the PCH extension. |
| 166 | $Output =~ s/[.]gch$//; |
Ted Kremenek | 7fe679f | 2011-02-17 02:28:30 +0000 | [diff] [blame] | 167 | push @CmdArgs, $Output; |
| 168 | @CmdArgsSansAnalyses = @CmdArgs; |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 169 | } |
| 170 | else { |
Ted Kremenek | 2a3a8b9 | 2009-12-11 22:44:53 +0000 | [diff] [blame] | 171 | $Cmd = $Clang; |
Ted Kremenek | 7fe679f | 2011-02-17 02:28:30 +0000 | [diff] [blame] | 172 | if ($Lang eq "objective-c" || $Lang eq "objective-c++") { |
Ted Kremenek | 27871ea | 2011-03-10 21:10:08 +0000 | [diff] [blame] | 173 | push @Args,'-DIBOutlet=__attribute__((iboutlet))'; |
| 174 | push @Args,'-DIBOutletCollection(ClassName)=__attribute__((iboutletcollection)))'; |
| 175 | push @Args,'-DIBAction=void)__attribute__((ibaction)'; |
Ted Kremenek | 7fe679f | 2011-02-17 02:28:30 +0000 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | # Create arguments for doing regular parsing. |
Ted Kremenek | 27871ea | 2011-03-10 21:10:08 +0000 | [diff] [blame] | 179 | my $SyntaxArgs = GetCCArgs("-fsyntax-only", \@Args); |
| 180 | @CmdArgsSansAnalyses = @$SyntaxArgs; |
| 181 | |
Ted Kremenek | 7fe679f | 2011-02-17 02:28:30 +0000 | [diff] [blame] | 182 | # Create arguments for doing static analysis. |
| 183 | if (defined $ResultFile) { |
Ted Kremenek | 5e48bcf | 2011-03-16 21:10:42 +0000 | [diff] [blame] | 184 | push @Args, '-o', $ResultFile; |
Ted Kremenek | 7fe679f | 2011-02-17 02:28:30 +0000 | [diff] [blame] | 185 | } |
| 186 | elsif (defined $HtmlDir) { |
Ted Kremenek | 5e48bcf | 2011-03-16 21:10:42 +0000 | [diff] [blame] | 187 | push @Args, '-o', $HtmlDir; |
Ted Kremenek | 7fe679f | 2011-02-17 02:28:30 +0000 | [diff] [blame] | 188 | } |
Ted Kremenek | b26fbc1 | 2011-03-21 20:12:21 +0000 | [diff] [blame] | 189 | if ($Verbose) { |
| 190 | push @Args, "-Xclang", "-analyzer-display-progress"; |
| 191 | } |
Ted Kremenek | 7fe679f | 2011-02-17 02:28:30 +0000 | [diff] [blame] | 192 | |
| 193 | foreach my $arg (@$AnalyzeArgs) { |
Ted Kremenek | 5e48bcf | 2011-03-16 21:10:42 +0000 | [diff] [blame] | 194 | push @Args, "-Xclang", $arg; |
Ted Kremenek | 8382cf5 | 2009-11-13 18:46:29 +0000 | [diff] [blame] | 195 | } |
Ted Kremenek | 5e48bcf | 2011-03-16 21:10:42 +0000 | [diff] [blame] | 196 | |
Ted Kremenek | 7fe679f | 2011-02-17 02:28:30 +0000 | [diff] [blame] | 197 | # Display Ubiviz graph? |
| 198 | if (defined $ENV{'CCC_UBI'}) { |
Ted Kremenek | 5e48bcf | 2011-03-16 21:10:42 +0000 | [diff] [blame] | 199 | push @Args, "-Xclang", "-analyzer-viz-egraph-ubigraph"; |
Ted Kremenek | 7fe679f | 2011-02-17 02:28:30 +0000 | [diff] [blame] | 200 | } |
| 201 | |
Ted Kremenek | 27871ea | 2011-03-10 21:10:08 +0000 | [diff] [blame] | 202 | my $AnalysisArgs = GetCCArgs("--analyze", \@Args); |
| 203 | @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 | 27871ea | 2011-03-10 21:10:08 +0000 | [diff] [blame] | 220 | print STDERR join(' ', @PrintArgs); |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 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++', |
Anna Zaks | 71f11d6 | 2011-08-31 23:53:24 +0000 | [diff] [blame] | 371 | 'ii' => 'c++', |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 372 | 'i' => 'c-cpp-output', |
| 373 | 'm' => 'objective-c', |
Anna Zaks | 71f11d6 | 2011-08-31 23:53:24 +0000 | [diff] [blame] | 374 | 'mi' => 'objective-c-cpp-output', |
| 375 | 'mm' => 'objective-c++' |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 376 | ); |
| 377 | |
Ted Kremenek | a30730e | 2008-09-29 16:15:20 +0000 | [diff] [blame] | 378 | my %UniqueOptions = ( |
| 379 | '-isysroot' => 0 |
| 380 | ); |
| 381 | |
Ted Kremenek | f6f8d5a | 2010-03-08 19:06:44 +0000 | [diff] [blame] | 382 | ##----------------------------------------------------------------------------## |
| 383 | # Languages accepted. |
| 384 | ##----------------------------------------------------------------------------## |
| 385 | |
Ted Kremenek | efaf191 | 2009-05-11 21:08:34 +0000 | [diff] [blame] | 386 | my %LangsAccepted = ( |
| 387 | "objective-c" => 1, |
Ted Kremenek | 0a20818 | 2011-08-11 22:47:20 +0000 | [diff] [blame] | 388 | "c" => 1, |
| 389 | "c++" => 1, |
| 390 | "objective-c++" => 1 |
Ted Kremenek | efaf191 | 2009-05-11 21:08:34 +0000 | [diff] [blame] | 391 | ); |
| 392 | |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 393 | ##----------------------------------------------------------------------------## |
| 394 | # Main Logic. |
| 395 | ##----------------------------------------------------------------------------## |
| 396 | |
| 397 | my $Action = 'link'; |
| 398 | my @CompileOpts; |
| 399 | my @LinkOpts; |
| 400 | my @Files; |
| 401 | my $Lang; |
| 402 | my $Output; |
Ted Kremenek | a30730e | 2008-09-29 16:15:20 +0000 | [diff] [blame] | 403 | my %Uniqued; |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 404 | |
| 405 | # Forward arguments to gcc. |
Ted Kremenek | 51365b5 | 2009-12-15 02:35:54 +0000 | [diff] [blame] | 406 | my $Status = system($Compiler,@ARGV); |
Tom Care | a716f63 | 2010-09-29 23:48:31 +0000 | [diff] [blame] | 407 | if (defined $ENV{'CCC_ANALYZER_LOG'}) { |
| 408 | print "$Compiler @ARGV\n"; |
| 409 | } |
Ted Kremenek | cb344d0 | 2008-08-28 01:18:44 +0000 | [diff] [blame] | 410 | if ($Status) { exit($Status >> 8); } |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 411 | |
| 412 | # Get the analysis options. |
| 413 | my $Analyses = $ENV{'CCC_ANALYZER_ANALYSIS'}; |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 414 | |
Zhongxing Xu | 07c3767 | 2008-10-27 14:26:32 +0000 | [diff] [blame] | 415 | # Get the store model. |
| 416 | my $StoreModel = $ENV{'CCC_ANALYZER_STORE_MODEL'}; |
Ted Kremenek | be1fe1e | 2009-02-17 04:27:41 +0000 | [diff] [blame] | 417 | |
| 418 | # Get the constraints engine. |
| 419 | my $ConstraintsModel = $ENV{'CCC_ANALYZER_CONSTRAINTS_MODEL'}; |
Zhongxing Xu | 07c3767 | 2008-10-27 14:26:32 +0000 | [diff] [blame] | 420 | |
Ted Kremenek | db4f5f2 | 2008-11-04 00:02:53 +0000 | [diff] [blame] | 421 | # Get the output format. |
| 422 | my $OutputFormat = $ENV{'CCC_ANALYZER_OUTPUT_FORMAT'}; |
Ted Kremenek | 3891a15 | 2009-02-17 05:01:10 +0000 | [diff] [blame] | 423 | if (!defined $OutputFormat) { $OutputFormat = "html"; } |
Ted Kremenek | db4f5f2 | 2008-11-04 00:02:53 +0000 | [diff] [blame] | 424 | |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 425 | # Determine the level of verbosity. |
| 426 | my $Verbose = 0; |
| 427 | if (defined $ENV{CCC_ANALYZER_VERBOSE}) { $Verbose = 1; } |
| 428 | if (defined $ENV{CCC_ANALYZER_LOG}) { $Verbose = 2; } |
| 429 | |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 430 | # Get the HTML output directory. |
| 431 | my $HtmlDir = $ENV{'CCC_ANALYZER_HTML'}; |
| 432 | |
Ted Kremenek | 8459132 | 2009-02-24 22:07:12 +0000 | [diff] [blame] | 433 | my %DisabledArchs = ('ppc' => 1, 'ppc64' => 1); |
Ted Kremenek | 27783eb | 2008-09-25 20:17:57 +0000 | [diff] [blame] | 434 | my %ArchsSeen; |
Ted Kremenek | 8459132 | 2009-02-24 22:07:12 +0000 | [diff] [blame] | 435 | my $HadArch = 0; |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 436 | |
| 437 | # Process the arguments. |
| 438 | foreach (my $i = 0; $i < scalar(@ARGV); ++$i) { |
Ted Kremenek | 89c4fcf | 2008-10-19 06:42:38 +0000 | [diff] [blame] | 439 | my $Arg = $ARGV[$i]; |
| 440 | my ($ArgKey) = split /=/,$Arg,2; |
| 441 | |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 442 | # Modes ccc-analyzer supports |
Ted Kremenek | d732a7b | 2009-08-04 00:57:12 +0000 | [diff] [blame] | 443 | if ($Arg =~ /^-(E|MM?)$/) { $Action = 'preprocess'; } |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 444 | elsif ($Arg eq '-c') { $Action = 'compile'; } |
| 445 | elsif ($Arg =~ /^-print-prog-name/) { exit 0; } |
Ted Kremenek | 27783eb | 2008-09-25 20:17:57 +0000 | [diff] [blame] | 446 | |
| 447 | # Specially handle duplicate cases of -arch |
| 448 | if ($Arg eq "-arch") { |
| 449 | my $arch = $ARGV[$i+1]; |
Ted Kremenek | 8459132 | 2009-02-24 22:07:12 +0000 | [diff] [blame] | 450 | # We don't want to process 'ppc' because of Clang's lack of support |
| 451 | # for Altivec (also some #defines won't likely be defined correctly, etc.) |
| 452 | if (!(defined $DisabledArchs{$arch})) { $ArchsSeen{$arch} = 1; } |
| 453 | $HadArch = 1; |
Ted Kremenek | 27783eb | 2008-09-25 20:17:57 +0000 | [diff] [blame] | 454 | ++$i; |
| 455 | next; |
| 456 | } |
| 457 | |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 458 | # Options with possible arguments that should pass through to compiler. |
Ted Kremenek | 89c4fcf | 2008-10-19 06:42:38 +0000 | [diff] [blame] | 459 | if (defined $CompileOptionMap{$ArgKey}) { |
| 460 | my $Cnt = $CompileOptionMap{$ArgKey}; |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 461 | push @CompileOpts,$Arg; |
| 462 | while ($Cnt > 0) { ++$i; --$Cnt; push @CompileOpts, $ARGV[$i]; } |
| 463 | next; |
| 464 | } |
| 465 | |
| 466 | # Options with possible arguments that should pass through to linker. |
Ted Kremenek | 89c4fcf | 2008-10-19 06:42:38 +0000 | [diff] [blame] | 467 | if (defined $LinkerOptionMap{$ArgKey}) { |
| 468 | my $Cnt = $LinkerOptionMap{$ArgKey}; |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 469 | push @LinkOpts,$Arg; |
| 470 | while ($Cnt > 0) { ++$i; --$Cnt; push @LinkOpts, $ARGV[$i]; } |
| 471 | next; |
| 472 | } |
| 473 | |
| 474 | # Options with possible arguments that should pass through to both compiler |
| 475 | # and the linker. |
Ted Kremenek | 89c4fcf | 2008-10-19 06:42:38 +0000 | [diff] [blame] | 476 | if (defined $CompilerLinkerOptionMap{$ArgKey}) { |
| 477 | my $Cnt = $CompilerLinkerOptionMap{$ArgKey}; |
Ted Kremenek | 47fc25f | 2008-09-29 23:06:09 +0000 | [diff] [blame] | 478 | |
Ted Kremenek | a30730e | 2008-09-29 16:15:20 +0000 | [diff] [blame] | 479 | # Check if this is an option that should have a unique value, and if so |
| 480 | # determine if the value was checked before. |
| 481 | if ($UniqueOptions{$Arg}) { |
| 482 | if (defined $Uniqued{$Arg}) { |
| 483 | $i += $Cnt; |
| 484 | next; |
| 485 | } |
| 486 | $Uniqued{$Arg} = 1; |
| 487 | } |
| 488 | |
Ted Kremenek | 47fc25f | 2008-09-29 23:06:09 +0000 | [diff] [blame] | 489 | push @CompileOpts,$Arg; |
| 490 | push @LinkOpts,$Arg; |
| 491 | |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 492 | while ($Cnt > 0) { |
| 493 | ++$i; --$Cnt; |
| 494 | push @CompileOpts, $ARGV[$i]; |
| 495 | push @LinkOpts, $ARGV[$i]; |
| 496 | } |
| 497 | next; |
| 498 | } |
Ted Kremenek | 61cd988 | 2008-05-24 15:58:54 +0000 | [diff] [blame] | 499 | |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 500 | # Ignored options. |
Ted Kremenek | 89c4fcf | 2008-10-19 06:42:38 +0000 | [diff] [blame] | 501 | if (defined $IgnoredOptionMap{$ArgKey}) { |
| 502 | my $Cnt = $IgnoredOptionMap{$ArgKey}; |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 503 | while ($Cnt > 0) { |
| 504 | ++$i; --$Cnt; |
| 505 | } |
| 506 | next; |
| 507 | } |
Ted Kremenek | 61cd988 | 2008-05-24 15:58:54 +0000 | [diff] [blame] | 508 | |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 509 | # Compile mode flags. |
| 510 | if ($Arg =~ /^-[D,I,U](.*)$/) { |
| 511 | my $Tmp = $Arg; |
| 512 | if ($1 eq '') { |
| 513 | # FIXME: Check if we are going off the end. |
| 514 | ++$i; |
| 515 | $Tmp = $Arg . $ARGV[$i]; |
| 516 | } |
| 517 | push @CompileOpts,$Tmp; |
| 518 | next; |
| 519 | } |
| 520 | |
| 521 | # Language. |
| 522 | if ($Arg eq '-x') { |
| 523 | $Lang = $ARGV[$i+1]; |
| 524 | ++$i; next; |
| 525 | } |
Ted Kremenek | 61cd988 | 2008-05-24 15:58:54 +0000 | [diff] [blame] | 526 | |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 527 | # Output file. |
| 528 | if ($Arg eq '-o') { |
| 529 | ++$i; |
| 530 | $Output = $ARGV[$i]; |
| 531 | next; |
| 532 | } |
| 533 | |
| 534 | # Get the link mode. |
| 535 | if ($Arg =~ /^-[l,L,O]/) { |
| 536 | if ($Arg eq '-O') { push @LinkOpts,'-O1'; } |
| 537 | elsif ($Arg eq '-Os') { push @LinkOpts,'-O2'; } |
| 538 | else { push @LinkOpts,$Arg; } |
| 539 | next; |
| 540 | } |
| 541 | |
| 542 | if ($Arg =~ /^-std=/) { |
| 543 | push @CompileOpts,$Arg; |
| 544 | next; |
| 545 | } |
| 546 | |
| 547 | # if ($Arg =~ /^-f/) { |
| 548 | # # FIXME: Not sure if the remaining -fxxxx options have no arguments. |
| 549 | # push @CompileOpts,$Arg; |
| 550 | # push @LinkOpts,$Arg; # FIXME: Not sure if these are link opts. |
| 551 | # } |
| 552 | |
| 553 | # Get the compiler/link mode. |
| 554 | if ($Arg =~ /^-F(.+)$/) { |
| 555 | my $Tmp = $Arg; |
| 556 | if ($1 eq '') { |
| 557 | # FIXME: Check if we are going off the end. |
| 558 | ++$i; |
| 559 | $Tmp = $Arg . $ARGV[$i]; |
| 560 | } |
| 561 | push @CompileOpts,$Tmp; |
| 562 | push @LinkOpts,$Tmp; |
| 563 | next; |
| 564 | } |
Ted Kremenek | 61cd988 | 2008-05-24 15:58:54 +0000 | [diff] [blame] | 565 | |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 566 | # Input files. |
| 567 | if ($Arg eq '-filelist') { |
| 568 | # FIXME: Make sure we aren't walking off the end. |
| 569 | open(IN, $ARGV[$i+1]); |
| 570 | while (<IN>) { s/\015?\012//; push @Files,$_; } |
| 571 | close(IN); |
Ted Kremenek | 0895937 | 2009-08-14 18:20:50 +0000 | [diff] [blame] | 572 | ++$i; |
| 573 | next; |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 574 | } |
| 575 | |
Ted Kremenek | 0895937 | 2009-08-14 18:20:50 +0000 | [diff] [blame] | 576 | # Handle -Wno-. We don't care about extra warnings, but |
| 577 | # we should suppress ones that we don't want to see. |
| 578 | if ($Arg =~ /^-Wno-/) { |
| 579 | push @CompileOpts, $Arg; |
| 580 | next; |
| 581 | } |
| 582 | |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 583 | if (!($Arg =~ /^-/)) { |
Ted Kremenek | 0895937 | 2009-08-14 18:20:50 +0000 | [diff] [blame] | 584 | push @Files, $Arg; |
| 585 | next; |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 586 | } |
| 587 | } |
Ted Kremenek | 61cd988 | 2008-05-24 15:58:54 +0000 | [diff] [blame] | 588 | |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 589 | if ($Action eq 'compile' or $Action eq 'link') { |
Ted Kremenek | 8459132 | 2009-02-24 22:07:12 +0000 | [diff] [blame] | 590 | my @Archs = keys %ArchsSeen; |
| 591 | # Skip the file if we don't support the architectures specified. |
Ted Kremenek | 0e0eb8b | 2009-02-25 00:10:37 +0000 | [diff] [blame] | 592 | exit 0 if ($HadArch && scalar(@Archs) == 0); |
Ted Kremenek | 8459132 | 2009-02-24 22:07:12 +0000 | [diff] [blame] | 593 | |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 594 | foreach my $file (@Files) { |
| 595 | # Determine the language for the file. |
| 596 | my $FileLang = $Lang; |
| 597 | |
| 598 | if (!defined($FileLang)) { |
| 599 | # Infer the language from the extension. |
| 600 | if ($file =~ /[.]([^.]+)$/) { |
| 601 | $FileLang = $LangMap{$1}; |
| 602 | } |
| 603 | } |
Ted Kremenek | 1262fc4 | 2008-05-14 20:10:33 +0000 | [diff] [blame] | 604 | |
Ted Kremenek | 1d81ed9 | 2010-02-12 00:10:34 +0000 | [diff] [blame] | 605 | # FileLang still not defined? Skip the file. |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 606 | next if (!defined $FileLang); |
Ted Kremenek | 1d81ed9 | 2010-02-12 00:10:34 +0000 | [diff] [blame] | 607 | |
| 608 | # Language not accepted? |
Ted Kremenek | efaf191 | 2009-05-11 21:08:34 +0000 | [diff] [blame] | 609 | next if (!defined $LangsAccepted{$FileLang}); |
Ted Kremenek | 1d81ed9 | 2010-02-12 00:10:34 +0000 | [diff] [blame] | 610 | |
Ted Kremenek | 9a9e0d4 | 2009-05-15 04:20:31 +0000 | [diff] [blame] | 611 | my @CmdArgs; |
| 612 | my @AnalyzeArgs; |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 613 | |
| 614 | if ($FileLang ne 'unknown') { |
Ted Kremenek | 5e48bcf | 2011-03-16 21:10:42 +0000 | [diff] [blame] | 615 | push @CmdArgs, '-x', $FileLang; |
Ted Kremenek | fbeeca8 | 2008-07-19 06:11:04 +0000 | [diff] [blame] | 616 | } |
Ted Kremenek | b098288 | 2008-03-25 22:35:32 +0000 | [diff] [blame] | 617 | |
Zhongxing Xu | 07c3767 | 2008-10-27 14:26:32 +0000 | [diff] [blame] | 618 | if (defined $StoreModel) { |
Ted Kremenek | be1fe1e | 2009-02-17 04:27:41 +0000 | [diff] [blame] | 619 | push @AnalyzeArgs, "-analyzer-store=$StoreModel"; |
Zhongxing Xu | 07c3767 | 2008-10-27 14:26:32 +0000 | [diff] [blame] | 620 | } |
Ted Kremenek | be1fe1e | 2009-02-17 04:27:41 +0000 | [diff] [blame] | 621 | |
| 622 | if (defined $ConstraintsModel) { |
| 623 | push @AnalyzeArgs, "-analyzer-constraints=$ConstraintsModel"; |
| 624 | } |
Ted Kremenek | 7fe679f | 2011-02-17 02:28:30 +0000 | [diff] [blame] | 625 | |
Anna Zaks | 71f11d6 | 2011-08-31 23:53:24 +0000 | [diff] [blame] | 626 | if (defined $Analyses) { |
| 627 | push @AnalyzeArgs, split '\s+', $Analyses; |
| 628 | } |
Ted Kremenek | be1fe1e | 2009-02-17 04:27:41 +0000 | [diff] [blame] | 629 | |
Ted Kremenek | db4f5f2 | 2008-11-04 00:02:53 +0000 | [diff] [blame] | 630 | if (defined $OutputFormat) { |
Ted Kremenek | be1fe1e | 2009-02-17 04:27:41 +0000 | [diff] [blame] | 631 | push @AnalyzeArgs, "-analyzer-output=" . $OutputFormat; |
Ted Kremenek | 7753b35 | 2009-07-27 22:10:34 +0000 | [diff] [blame] | 632 | if ($OutputFormat =~ /plist/) { |
Ted Kremenek | ddf32da | 2009-01-21 00:42:24 +0000 | [diff] [blame] | 633 | # Change "Output" to be a file. |
| 634 | my ($h, $f) = tempfile("report-XXXXXX", SUFFIX => ".plist", |
| 635 | DIR => $HtmlDir); |
| 636 | $ResultFile = $f; |
Anna Zaks | 9134294 | 2011-09-09 18:43:53 +0000 | [diff] [blame] | 637 | # If the HtmlDir is not set, we sould clean up the plist files. |
| 638 | if (!defined $HtmlDir || -z $HtmlDir) { |
| 639 | $CleanupFile = $f; |
| 640 | } |
Ted Kremenek | ddf32da | 2009-01-21 00:42:24 +0000 | [diff] [blame] | 641 | } |
Ted Kremenek | db4f5f2 | 2008-11-04 00:02:53 +0000 | [diff] [blame] | 642 | } |
Zhongxing Xu | 07c3767 | 2008-10-27 14:26:32 +0000 | [diff] [blame] | 643 | |
Ted Kremenek | 7fe679f | 2011-02-17 02:28:30 +0000 | [diff] [blame] | 644 | push @CmdArgs, @CompileOpts; |
| 645 | push @CmdArgs, $file; |
Zhongxing Xu | 07c3767 | 2008-10-27 14:26:32 +0000 | [diff] [blame] | 646 | |
Ted Kremenek | 27783eb | 2008-09-25 20:17:57 +0000 | [diff] [blame] | 647 | if (scalar @Archs) { |
| 648 | foreach my $arch (@Archs) { |
| 649 | my @NewArgs; |
Ted Kremenek | 5e48bcf | 2011-03-16 21:10:42 +0000 | [diff] [blame] | 650 | push @NewArgs, '-arch', $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 | |