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