| 1 | #!/usr/bin/perl |
|---|
| 2 | # ================================================================= # |
|---|
| 3 | # # |
|---|
| 4 | # File : postcompile.pl # |
|---|
| 5 | # Purpose : filter gcc shadow spam # |
|---|
| 6 | # # |
|---|
| 7 | # Coded by Ralf Westram (coder@reallysoft.de) in September 2007 # |
|---|
| 8 | # Institute of Microbiology (Technical University Munich) # |
|---|
| 9 | # http://www.arb-home.de/ # |
|---|
| 10 | # # |
|---|
| 11 | # ================================================================= # |
|---|
| 12 | |
|---|
| 13 | use strict; |
|---|
| 14 | use warnings; |
|---|
| 15 | |
|---|
| 16 | # Note: g++ must be called with -fmessage-length=0 |
|---|
| 17 | |
|---|
| 18 | my $show_suppressed_lines = 0; |
|---|
| 19 | my $show_filtered_lines = 0; |
|---|
| 20 | |
|---|
| 21 | # regexps for whole line: |
|---|
| 22 | my $reg_file = qr/^([^:]+):([0-9]+):(([0-9]+):)?\s/; # finds all messages |
|---|
| 23 | my $reg_file_noline = qr/^([^:]+):\s/; # finds all messages w/o linenumber (if not matched $reg_file) |
|---|
| 24 | my $reg_included = qr/^In\sfile\sincluded\sfrom\s(.*)[,:]/; |
|---|
| 25 | my $reg_inlined_from = qr/^\s\s+(inlined\sfrom\s.*)\sat\s(.*)[,:]/; |
|---|
| 26 | my $reg_included2 = qr/^\s+from\s(.*)[,:]/; |
|---|
| 27 | my $reg_location = qr/^[^:]+:\sIn\s(function|member\sfunction|instantiation)\s/; |
|---|
| 28 | my $reg_location2 = qr/^[^:]+:\sAt\stop\slevel:/; |
|---|
| 29 | my $reg_location3 = qr/^At\sglobal\sscope:/; |
|---|
| 30 | my $reg_clang_dirt = qr/^ANALYZE:\s/; |
|---|
| 31 | |
|---|
| 32 | # regexps for messages: |
|---|
| 33 | my $reg_is_error = qr/^error:\s/i; |
|---|
| 34 | my $reg_is_warning_or_note = qr/^(warning|note):\s/i; |
|---|
| 35 | my $reg_is_instantiated = qr/^\s\s+instantiated\sfrom\s/; |
|---|
| 36 | my $reg_is_required = qr/^\s\s+required\s(from|by)\s/; |
|---|
| 37 | my $reg_is_optimizerMsg = qr/^(missed|optimized):\s/i; |
|---|
| 38 | |
|---|
| 39 | # regexps for warning messages (for part behind 'warning: ') |
|---|
| 40 | my $reg_shadow_warning = qr/^declaration\sof\s.*\sshadows\s/; |
|---|
| 41 | my $reg_shadow_location = qr/^shadowed\s/; |
|---|
| 42 | my $reg_unknown_gcc_diagnostic = qr/^expected.*after\s'#pragma\sGCC\sdiagnostic'/; |
|---|
| 43 | |
|---|
| 44 | # filter unwanted -Weffc++ warnings |
|---|
| 45 | my $filter_Weffpp = 1; |
|---|
| 46 | my @reg_Weffpp = ( |
|---|
| 47 | qr/only\sdefines\sprivate\sconstructors\sand\shas\sno\sfriends/, # unwanted warning about singleton-class where the only instance exists as a static member of itself |
|---|
| 48 | qr/^base\sclass\s.*has\s*(a|accessible)\snon-virtual\sdestructor/, |
|---|
| 49 | qr/\sshould\sbe\sinitialized\sin\sthe\smember\sinitialization\slist/, |
|---|
| 50 | qr/boost::icl::(insert|add)_iterator<ContainerT>.*should\sreturn/, # filter boost-iterator postfix operators warnings |
|---|
| 51 | qr/^\s\sbut\sdoes\snot\s(override|declare)/, # belongs to reg_Weffpp_copyable (since gcc 10.2.0 message uses 'declare' instead of 'override') |
|---|
| 52 | qr/^\s\sor\s\'operator=/, # belongs to reg_Weffpp_copyable |
|---|
| 53 | ); |
|---|
| 54 | |
|---|
| 55 | my $filter_Weffpp_copyable = 0; # 1 = filter copy-ctor/op=-warning, 0 = check for Noncopyable and warn |
|---|
| 56 | my $reg_Weffpp_copyable = qr/'(class|struct)\s([A-Za-z_0-9:]+).*'\shas\spointer\sdata\smembers/; # occurs also if derived from 'Noncopyable' |
|---|
| 57 | |
|---|
| 58 | # regexps for files: |
|---|
| 59 | my $reg_user_include = qr/^\/usr\/include\//; |
|---|
| 60 | my $reg_HEADERLIBS_include = qr/\/HEADERLIBS\//; |
|---|
| 61 | |
|---|
| 62 | my $stop_after_first_error = 0; |
|---|
| 63 | my $hide_warnings = 0; |
|---|
| 64 | |
|---|
| 65 | my $dump_loop_optimization = 0; |
|---|
| 66 | my $check_loop_optimization = 0; |
|---|
| 67 | my $checked_file = undef; # contains name of sourcefile (if it shall be checked) |
|---|
| 68 | |
|---|
| 69 | my $REQ_check_loop_optimization = 0; # originally requested? |
|---|
| 70 | my $REQ_checked_file = 0; # originally checked file |
|---|
| 71 | |
|---|
| 72 | my $ARBHOME = $ENV{ARBHOME}; |
|---|
| 73 | my $exitcode = 0; |
|---|
| 74 | |
|---|
| 75 | # ---------------------------------------- |
|---|
| 76 | |
|---|
| 77 | sub detect_needLoopCheck($) { |
|---|
| 78 | my ($source) = @_; |
|---|
| 79 | if ($check_loop_optimization) { |
|---|
| 80 | $REQ_check_loop_optimization = 1; |
|---|
| 81 | $REQ_checked_file = $source; |
|---|
| 82 | use Cwd; |
|---|
| 83 | my $currDir = Cwd::getcwd(); |
|---|
| 84 | my $relDir = undef; |
|---|
| 85 | if ($currDir =~ /^$ARBHOME/) { $relDir = $'; } |
|---|
| 86 | if (not defined $relDir) { die "Can't detect ARBHOME-relative working directory"; } |
|---|
| 87 | $relDir =~ s/^\/*//og; |
|---|
| 88 | my $relfile = $relDir.'/'.$source; |
|---|
| 89 | my $checked_list = $ARBHOME.'/SOURCE_TOOLS/vectorized.source'; |
|---|
| 90 | |
|---|
| 91 | open(LIST,'<'.$checked_list) || die "can't read '$checked_list' (Reason: $!)"; |
|---|
| 92 | SEARCH: foreach (<LIST>) { |
|---|
| 93 | if (not /^\s*\#/) { # ignore comments |
|---|
| 94 | if (not /^\s*$/) { # ignore empty lines |
|---|
| 95 | chomp($_); |
|---|
| 96 | if ($relfile eq $_) { |
|---|
| 97 | $checked_file = $source; |
|---|
| 98 | last SEARCH; |
|---|
| 99 | } |
|---|
| 100 | } |
|---|
| 101 | } |
|---|
| 102 | } |
|---|
| 103 | close(LIST); |
|---|
| 104 | if (not defined $checked_file) { |
|---|
| 105 | $check_loop_optimization = undef; |
|---|
| 106 | } |
|---|
| 107 | elsif ($dump_loop_optimization==2) { |
|---|
| 108 | $dump_loop_optimization = 0; # do not dump candidates, if file is already checked |
|---|
| 109 | } |
|---|
| 110 | } |
|---|
| 111 | } |
|---|
| 112 | |
|---|
| 113 | sub getModtime($) { |
|---|
| 114 | my ($fileOrDir) = @_; |
|---|
| 115 | my $modtime = (stat($fileOrDir))[9]; |
|---|
| 116 | return $modtime; |
|---|
| 117 | } |
|---|
| 118 | |
|---|
| 119 | my %derived_from_NC = (); # key=classname, value=1/0 |
|---|
| 120 | my $NC_save_name = $ARBHOME.'/SOURCE_TOOLS/postcompile.sav'; |
|---|
| 121 | my $NC_loaded = 0; |
|---|
| 122 | my $NC_loaded_timestamp; |
|---|
| 123 | my $NC_need_save = 0; |
|---|
| 124 | |
|---|
| 125 | sub load_from_NC() { |
|---|
| 126 | if (-f $NC_save_name) { |
|---|
| 127 | $NC_loaded_timestamp = getModtime($NC_save_name); |
|---|
| 128 | my $age = $NC_loaded_timestamp - time; |
|---|
| 129 | if ($age<3*60) { # never load data older than 3 min |
|---|
| 130 | open(NC,'<'.$NC_save_name); |
|---|
| 131 | foreach (<NC>) { |
|---|
| 132 | chomp; |
|---|
| 133 | if (/^([01]),/o) { |
|---|
| 134 | $derived_from_NC{$'} = $1; |
|---|
| 135 | } |
|---|
| 136 | } |
|---|
| 137 | close(NC); |
|---|
| 138 | } |
|---|
| 139 | else { |
|---|
| 140 | $NC_loaded_timestamp = 0; # epoch |
|---|
| 141 | } |
|---|
| 142 | } |
|---|
| 143 | else { |
|---|
| 144 | $NC_loaded_timestamp = 0; # epoch |
|---|
| 145 | } |
|---|
| 146 | $NC_loaded = 1; |
|---|
| 147 | } |
|---|
| 148 | |
|---|
| 149 | sub save_from_NC() { |
|---|
| 150 | if ($NC_need_save==1) { |
|---|
| 151 | my $mt = 0; |
|---|
| 152 | if (-f $NC_save_name) { $mt = getModtime($NC_save_name); } |
|---|
| 153 | if ($mt>$NC_loaded_timestamp) { # changed on disk |
|---|
| 154 | load_from_NC(); # does simple merge |
|---|
| 155 | } |
|---|
| 156 | my $NC_save_name_private = $NC_save_name.'.'.$$; |
|---|
| 157 | open(NC,'>'.$NC_save_name_private); |
|---|
| 158 | foreach (sort keys %derived_from_NC) { |
|---|
| 159 | print NC $derived_from_NC{$_}.','.$_."\n"; |
|---|
| 160 | } |
|---|
| 161 | close(NC); |
|---|
| 162 | |
|---|
| 163 | rename($NC_save_name_private,$NC_save_name) || die "can't rename '$NC_save_name_private' to '$NC_save_name' (Reason: $!)"; |
|---|
| 164 | } |
|---|
| 165 | } |
|---|
| 166 | |
|---|
| 167 | sub advice_derived_from_Noncopyable($$$) { |
|---|
| 168 | # Note: you can silence the Noncopyable-warning by |
|---|
| 169 | # adding a comment containing 'Noncopyable' behind the 'class'-line |
|---|
| 170 | my ($classname,$file,$linenr) = @_; |
|---|
| 171 | |
|---|
| 172 | if ($NC_loaded==0) { load_from_NC(); } |
|---|
| 173 | my $is_a_NC = $derived_from_NC{$classname}; |
|---|
| 174 | if (defined $is_a_NC) { |
|---|
| 175 | return 0; # do not warn twice |
|---|
| 176 | } |
|---|
| 177 | |
|---|
| 178 | if (not -f $file) { |
|---|
| 179 | die "no such file '$file'"; |
|---|
| 180 | } |
|---|
| 181 | |
|---|
| 182 | my $uq_classname = $classname; |
|---|
| 183 | while ($uq_classname =~ /::/o) { $uq_classname = $'; } # skip namespace prefixes |
|---|
| 184 | |
|---|
| 185 | open(FILE,'<'.$file) || die "can't read '$file' (Reason: $!)"; |
|---|
| 186 | my $line; |
|---|
| 187 | my $line_count = 0; |
|---|
| 188 | LINE: while (defined($line=<FILE>)) { |
|---|
| 189 | $line_count++; |
|---|
| 190 | if ($line_count==$linenr) { |
|---|
| 191 | if ($line =~ /(class|struct)\s+($uq_classname|$classname)(.*)Noncopyable/) { |
|---|
| 192 | my $prefix = $3; |
|---|
| 193 | if (not $prefix =~ /\/\//) { # if we have a comment, assume it mentions that the class is derived from a Noncopyable |
|---|
| 194 | if (not $prefix =~ /virtual/) { |
|---|
| 195 | print $file.':'.$linenr.': inheritance from Noncopyable should be virtual'."\n"; |
|---|
| 196 | } |
|---|
| 197 | } |
|---|
| 198 | $is_a_NC = 1; |
|---|
| 199 | } |
|---|
| 200 | else { $is_a_NC = 0; } |
|---|
| 201 | last LINE; |
|---|
| 202 | } |
|---|
| 203 | } |
|---|
| 204 | close(FILE); |
|---|
| 205 | $derived_from_NC{$classname} = $is_a_NC; |
|---|
| 206 | $NC_need_save = 1; |
|---|
| 207 | |
|---|
| 208 | return 1-$is_a_NC; |
|---|
| 209 | } |
|---|
| 210 | |
|---|
| 211 | # results for Weffpp_warning_wanted(): |
|---|
| 212 | my $WANTED = 0; |
|---|
| 213 | my $WANTED_NO_RELATED = 1; |
|---|
| 214 | my $UNWANTED = 2; |
|---|
| 215 | |
|---|
| 216 | sub Weffpp_warning_wanted($$\$) { |
|---|
| 217 | my ($file,$line,$warning_text_r) = @_; |
|---|
| 218 | |
|---|
| 219 | if ($filter_Weffpp==1) { |
|---|
| 220 | foreach my $reg (@reg_Weffpp) { |
|---|
| 221 | return $UNWANTED if ($$warning_text_r =~ $reg); |
|---|
| 222 | } |
|---|
| 223 | if ($$warning_text_r =~ $reg_Weffpp_copyable) { |
|---|
| 224 | my $classname = $2; |
|---|
| 225 | return $UNWANTED if ($filter_Weffpp_copyable==1); |
|---|
| 226 | return $UNWANTED if (advice_derived_from_Noncopyable($classname,$file,$line)==0); |
|---|
| 227 | $$warning_text_r = $$warning_text_r.' (and is neither derived from Noncopyable nor defines copy-ctor and op=)'; |
|---|
| 228 | return $WANTED_NO_RELATED; |
|---|
| 229 | } |
|---|
| 230 | } |
|---|
| 231 | return $WANTED; |
|---|
| 232 | } |
|---|
| 233 | |
|---|
| 234 | sub warning($\@) { |
|---|
| 235 | my ($msg,$out_r) = @_; |
|---|
| 236 | push @$out_r, '[postcompile/'.$$.']: '.$msg; |
|---|
| 237 | } |
|---|
| 238 | |
|---|
| 239 | my $shadow_warning = undef; |
|---|
| 240 | |
|---|
| 241 | sub store_shadow($\@) { |
|---|
| 242 | my ($warn,$out_r) = @_; |
|---|
| 243 | if (defined $shadow_warning) { |
|---|
| 244 | warning('unprocessed shadow_warning:', @$out_r); |
|---|
| 245 | push @$out_r, $shadow_warning; |
|---|
| 246 | } |
|---|
| 247 | $shadow_warning = $warn; |
|---|
| 248 | } |
|---|
| 249 | |
|---|
| 250 | my $last_pushed_related = 0; |
|---|
| 251 | |
|---|
| 252 | sub push_loc_and_related($$\@\@) { |
|---|
| 253 | my ($location_info,$message,$related_r,$out_r) = @_; |
|---|
| 254 | if (defined $location_info) { |
|---|
| 255 | push @$out_r, $location_info; |
|---|
| 256 | } |
|---|
| 257 | push @$out_r, $message; |
|---|
| 258 | $last_pushed_related = scalar(@$related_r); |
|---|
| 259 | |
|---|
| 260 | # show related info (include-notes behind rest) |
|---|
| 261 | foreach (@$related_r) { if (not /included\sfrom/) { push @$out_r, $_; } } |
|---|
| 262 | foreach (@$related_r) { if (/included\sfrom/) { push @$out_r, $_; } } |
|---|
| 263 | } |
|---|
| 264 | |
|---|
| 265 | sub drop_last_pushed_relateds(\@) { |
|---|
| 266 | my ($out_r) = @_; |
|---|
| 267 | if ($last_pushed_related>0) { |
|---|
| 268 | my $before_related = scalar(@$out_r) - $last_pushed_related - 1; |
|---|
| 269 | $before_related>=0 || die "impossible (out_r-elements=".scalar(@$out_r)."; last_pushed_related=$last_pushed_related)"; |
|---|
| 270 | @$out_r = @$out_r[0 .. $before_related]; |
|---|
| 271 | } |
|---|
| 272 | } |
|---|
| 273 | |
|---|
| 274 | sub included_from_here($) { |
|---|
| 275 | my ($loc) = @_; |
|---|
| 276 | return $loc.': note: included from here'; |
|---|
| 277 | } |
|---|
| 278 | |
|---|
| 279 | sub suppress($\@$) { |
|---|
| 280 | my ($curr,$out_r,$as) = @_; |
|---|
| 281 | if ($show_suppressed_lines==1) { |
|---|
| 282 | warning('suppressed['.$as.']: '.$curr,@$out_r); |
|---|
| 283 | } |
|---|
| 284 | return undef; |
|---|
| 285 | } |
|---|
| 286 | |
|---|
| 287 | sub is_system_or_builtin($) { |
|---|
| 288 | my ($file) = @_; |
|---|
| 289 | return (($file =~ $reg_user_include) or ($file eq '<built-in>') or ($file =~ $reg_HEADERLIBS_include)); |
|---|
| 290 | } |
|---|
| 291 | |
|---|
| 292 | sub suppress_shadow_warning_for($) { |
|---|
| 293 | my ($file) = @_; |
|---|
| 294 | return is_system_or_builtin($file); |
|---|
| 295 | } |
|---|
| 296 | |
|---|
| 297 | sub compare_message_location($$) { |
|---|
| 298 | my ($a,$b) = @_; |
|---|
| 299 | # $a and $b are refs to array [filename location message] |
|---|
| 300 | my $cmp = $$a[0] cmp $$b[0]; # compare filenames |
|---|
| 301 | if ($cmp==0) { |
|---|
| 302 | my ($la,$lb) = (undef,undef); |
|---|
| 303 | if ($$a[1] =~ /^[0-9]+/o) { $la = $&; } |
|---|
| 304 | if ($$b[1] =~ /^[0-9]+/o) { $lb = $&; } |
|---|
| 305 | $cmp = $la <=> $lb; # compare line numbers |
|---|
| 306 | } |
|---|
| 307 | return $cmp; |
|---|
| 308 | } |
|---|
| 309 | sub compare_located_messages($$) { |
|---|
| 310 | my ($a,$b) = @_; |
|---|
| 311 | # $a and $b are refs to array [filename location message] |
|---|
| 312 | my $cmp = compare_message_location($a,$b); |
|---|
| 313 | if ($cmp==0) { $cmp = $$a[2] cmp $$b[2]; } # compare message |
|---|
| 314 | return $cmp; |
|---|
| 315 | } |
|---|
| 316 | |
|---|
| 317 | sub grep_loop_comments($\@) { |
|---|
| 318 | my ($source,$hits_r) = @_; |
|---|
| 319 | open(SRC,'<'.$source) || die "can't read '$source' (Reason: $!)"; |
|---|
| 320 | my $line; |
|---|
| 321 | my $linenr = 1; |
|---|
| 322 | while (defined($line=<SRC>)) { |
|---|
| 323 | if ($line =~ /(LOOP_VECTORIZED|IRRELEVANT_LOOP)/o) { |
|---|
| 324 | my $msg = $&.$'; |
|---|
| 325 | chomp($msg); |
|---|
| 326 | push @$hits_r, [ $source, $linenr, $msg ]; |
|---|
| 327 | } |
|---|
| 328 | $linenr++; |
|---|
| 329 | } |
|---|
| 330 | close(SRC); |
|---|
| 331 | } |
|---|
| 332 | |
|---|
| 333 | sub numericCompilerVersion($\$) { |
|---|
| 334 | my ($versionStr,$err_r) = @_; |
|---|
| 335 | my $vs = $versionStr; |
|---|
| 336 | $vs =~ s/\.//og; # remove dots |
|---|
| 337 | if ($vs =~ /[^0-9]/o) { # check for invalid characters |
|---|
| 338 | $$err_r = "version contains invalid character: '$&'"; |
|---|
| 339 | return undef; |
|---|
| 340 | } |
|---|
| 341 | |
|---|
| 342 | my $versionNum = int($vs); |
|---|
| 343 | if ($versionNum<1) { |
|---|
| 344 | $$err_r = "Invalid compiler version '$versionStr'"; |
|---|
| 345 | return undef; |
|---|
| 346 | } |
|---|
| 347 | |
|---|
| 348 | while ($versionNum<443) { # for lowest allowed version see ../Makefile@ALLOWED_gcc_VERSIONS |
|---|
| 349 | # assume shortened compiler version was specified + extend it: |
|---|
| 350 | # e.g. '6.3' -> 630 |
|---|
| 351 | # '10' -> 1000 |
|---|
| 352 | # '4' -> 4000 (this would be gcc 40.x) |
|---|
| 353 | $versionNum = $versionNum * 10; |
|---|
| 354 | } |
|---|
| 355 | |
|---|
| 356 | return $versionNum; |
|---|
| 357 | } |
|---|
| 358 | |
|---|
| 359 | my $compilerVersion = 'unknown'; # passed via CLI |
|---|
| 360 | my $compilerVersionNumber = undef; # numeric compiler version (e.g. 443 or 720 for 4.4.3 resp. 7.2.0) |
|---|
| 361 | |
|---|
| 362 | sub calcVersionNumber() { |
|---|
| 363 | # calculate version-number of used compiler (called if specified) |
|---|
| 364 | die if defined $compilerVersionNumber; |
|---|
| 365 | my $cerr = undef; |
|---|
| 366 | $compilerVersionNumber = numericCompilerVersion($compilerVersion,$cerr); |
|---|
| 367 | if (defined $cerr) { |
|---|
| 368 | die "cannot interpret compiler version-number passed via CLI (Reason: $cerr)"; |
|---|
| 369 | } |
|---|
| 370 | } |
|---|
| 371 | |
|---|
| 372 | sub compiler_allowed_by($\$) { |
|---|
| 373 | my ($exclusions,$err_r) = @_; |
|---|
| 374 | # checks if 'exclusions' allow global 'compilerVersionNumber'. |
|---|
| 375 | # return 0 if excluded, 1 if allowed. |
|---|
| 376 | # 'err_r' is set in case of errors. |
|---|
| 377 | |
|---|
| 378 | die if not defined $compilerVersionNumber; |
|---|
| 379 | |
|---|
| 380 | my @conditions = split /\s*,\s*/,$exclusions; |
|---|
| 381 | |
|---|
| 382 | my $compilerExcluded = 0; |
|---|
| 383 | CHECK: foreach my $cond (@conditions) { |
|---|
| 384 | my ($exclude,$rest); |
|---|
| 385 | if ($cond =~ /^!/o) { |
|---|
| 386 | $exclude = 1; |
|---|
| 387 | $cond = $'; |
|---|
| 388 | ($exclude,$rest) = (1,$'); |
|---|
| 389 | } |
|---|
| 390 | else { |
|---|
| 391 | ($exclude,$rest) = (0,$cond); |
|---|
| 392 | } |
|---|
| 393 | |
|---|
| 394 | $rest =~ s/\s//; |
|---|
| 395 | |
|---|
| 396 | print "cond='$cond' exclude=$exclude\n"; |
|---|
| 397 | |
|---|
| 398 | my $cond_matches = 1; |
|---|
| 399 | my $op = ''; |
|---|
| 400 | VERS: while ($rest ne '') { |
|---|
| 401 | if ($rest =~ /^([<>=]*)([^<>=])/o) { |
|---|
| 402 | ($op,$rest) = ($1,$2.$'); |
|---|
| 403 | } |
|---|
| 404 | |
|---|
| 405 | my $specVers; |
|---|
| 406 | if ($rest =~ /[<>=]/o) { |
|---|
| 407 | ($specVers,$rest) = ($`,$&.$'); |
|---|
| 408 | } |
|---|
| 409 | else { |
|---|
| 410 | ($specVers,$rest) = ($rest,''); |
|---|
| 411 | } |
|---|
| 412 | |
|---|
| 413 | my $cerr = undef; |
|---|
| 414 | my $version = numericCompilerVersion($specVers,$cerr); |
|---|
| 415 | if (defined $cerr) { |
|---|
| 416 | $$err_r = $cerr.' (in "'.$specVers.'")'; |
|---|
| 417 | return 0; |
|---|
| 418 | } |
|---|
| 419 | if (not defined $version) { die "internal error: version undefined, but no error reported"; } |
|---|
| 420 | |
|---|
| 421 | # document new operators in ./vectorize.README |
|---|
| 422 | if ($op eq '' ) { if ($compilerVersionNumber != $version) { $cond_matches = 0; } } |
|---|
| 423 | elsif ($op eq '<' ) { if ($compilerVersionNumber >= $version) { $cond_matches = 0; } } |
|---|
| 424 | elsif ($op eq '>' ) { if ($compilerVersionNumber <= $version) { $cond_matches = 0; } } |
|---|
| 425 | elsif ($op eq '<=') { if ($compilerVersionNumber > $version) { $cond_matches = 0; } } |
|---|
| 426 | elsif ($op eq '>=') { if ($compilerVersionNumber < $version) { $cond_matches = 0; } } |
|---|
| 427 | else { |
|---|
| 428 | $$err_r = "unknown exclude-operator '$op' (in '$cond')"; |
|---|
| 429 | return 0; |
|---|
| 430 | } |
|---|
| 431 | |
|---|
| 432 | print "cond_matches=$cond_matches rest='$rest'\n"; |
|---|
| 433 | } |
|---|
| 434 | |
|---|
| 435 | if ($cond_matches == $exclude) { |
|---|
| 436 | $compilerExcluded = 1; |
|---|
| 437 | last CHECK; |
|---|
| 438 | } |
|---|
| 439 | } |
|---|
| 440 | |
|---|
| 441 | print "compilerExcluded=$compilerExcluded\n"; |
|---|
| 442 | return $compilerExcluded ? 0 : 1; |
|---|
| 443 | } |
|---|
| 444 | |
|---|
| 445 | |
|---|
| 446 | sub parse_expected_vectorizations($\$) { |
|---|
| 447 | my ($str,$err_r) = @_; |
|---|
| 448 | |
|---|
| 449 | # 'str' is rest of line behind 'LOOP_VECTORIZED'. |
|---|
| 450 | # Expected syntax is described in ./vectorize.README@LOOP_VECTORIZED |
|---|
| 451 | # 'err_r' gets set in case of error (caller abort when set!) |
|---|
| 452 | # result is number of expected vectorizations (depends on global 'compilerVersionNumber') |
|---|
| 453 | |
|---|
| 454 | my $expected_vectorizations = 0; |
|---|
| 455 | my $condition_matched = 0; |
|---|
| 456 | |
|---|
| 457 | while (not $condition_matched and not defined $$err_r) { |
|---|
| 458 | my $seen_num = 1; |
|---|
| 459 | if ($str =~ /^\s*=([0-9\*\|]+)/o) { # str begins with '=<num>' or '=<num>'['|<num>']+ |
|---|
| 460 | my ($num,$rest) = ($1,$'); |
|---|
| 461 | if ($num =~ /\*/o) { |
|---|
| 462 | $$err_r = "vectorization count may not contain '*' (specify explicit numbers conditionally, e.g. '=3[!>=950]=1')"; |
|---|
| 463 | } |
|---|
| 464 | else { |
|---|
| 465 | if ($num =~ /\|/o) { |
|---|
| 466 | my @num_list = split /\|/, $num; |
|---|
| 467 | foreach my $n (@num_list) { |
|---|
| 468 | my $nn = int($n); |
|---|
| 469 | if (not $nn) { |
|---|
| 470 | if (not $n =~ /0/o) { |
|---|
| 471 | $$err_r = "invalid count '$n' in '$str'"; |
|---|
| 472 | } |
|---|
| 473 | else { |
|---|
| 474 | $$err_r = "zero vectorization count is not useful here (consider using IRRELEVANT_LOOP)"; |
|---|
| 475 | } |
|---|
| 476 | } |
|---|
| 477 | } |
|---|
| 478 | $expected_vectorizations = \@num_list; |
|---|
| 479 | } |
|---|
| 480 | else { |
|---|
| 481 | $expected_vectorizations = int($num); |
|---|
| 482 | if (not $expected_vectorizations and not $num =~ /0/o) { |
|---|
| 483 | $$err_r = "invalid count '$num' in '$str'"; |
|---|
| 484 | } |
|---|
| 485 | } |
|---|
| 486 | } |
|---|
| 487 | $str = $rest; |
|---|
| 488 | } |
|---|
| 489 | else { # no '=<num>'-prefix |
|---|
| 490 | if (not $expected_vectorizations) { # first <count> -> default to 1 |
|---|
| 491 | $expected_vectorizations = 1; |
|---|
| 492 | } |
|---|
| 493 | else { |
|---|
| 494 | $seen_num = 0; |
|---|
| 495 | } |
|---|
| 496 | } |
|---|
| 497 | |
|---|
| 498 | if ($str =~ /\s*\[([^\]]+)\]/o) { # condition follows |
|---|
| 499 | # if not 'seen_num' => accept following condition as alternative (OR-operation) |
|---|
| 500 | my ($cond, $rest) = ($1,$'); |
|---|
| 501 | if ($condition_matched) { |
|---|
| 502 | $$err_r = "unexpected condition '$cond' (did you forget a '=count'-prefix?)"; |
|---|
| 503 | } |
|---|
| 504 | else { |
|---|
| 505 | my $allowed = compiler_allowed_by($cond,$$err_r); |
|---|
| 506 | if (defined $$err_r) { |
|---|
| 507 | ; |
|---|
| 508 | } |
|---|
| 509 | else { |
|---|
| 510 | if ($allowed) { $condition_matched = 1; } |
|---|
| 511 | } |
|---|
| 512 | } |
|---|
| 513 | $str = $rest; |
|---|
| 514 | } |
|---|
| 515 | else { |
|---|
| 516 | # no condition follows -> always fulfilled |
|---|
| 517 | $condition_matched = 1; |
|---|
| 518 | if (not $seen_num) { $expected_vectorizations = 0; } # no condition after no count => expect failure for all compilers that did not match before |
|---|
| 519 | } |
|---|
| 520 | } |
|---|
| 521 | |
|---|
| 522 | return $expected_vectorizations; |
|---|
| 523 | } |
|---|
| 524 | |
|---|
| 525 | my $trace_vectorization_success_messages = 0; # set to 1 to log messages which trigger "succeeded vectorization" |
|---|
| 526 | sub is_successfulVectorizationMsg($) { |
|---|
| 527 | my ($msg) = @_; |
|---|
| 528 | if ($msg =~ /loop\svectorized/io) { |
|---|
| 529 | if ($msg =~ /not\svectorized/io) { die; return 0; } # @@@ if this never happens -> remove |
|---|
| 530 | if ($msg =~ /basic\sblock\svectorized/io) { die; return 0; } # @@@ if this never happens -> remove |
|---|
| 531 | return 1; |
|---|
| 532 | } |
|---|
| 533 | return 0; |
|---|
| 534 | } |
|---|
| 535 | |
|---|
| 536 | sub is_notWorthToVectorizeMsg($) { |
|---|
| 537 | my ($msg) = @_; |
|---|
| 538 | if ($msg =~ /cost.*worth/io) { |
|---|
| 539 | return 1; |
|---|
| 540 | } |
|---|
| 541 | return 0; |
|---|
| 542 | } |
|---|
| 543 | |
|---|
| 544 | sub is_loopNote($) { |
|---|
| 545 | my ($msg) = @_; |
|---|
| 546 | if ($msg =~ /(loop|vectorized|misalign|versioning|optab|SLP|ssa-name)/io) { return 1; } |
|---|
| 547 | |
|---|
| 548 | if ($msg =~ /bad\s(data)/io) { return 1; } |
|---|
| 549 | if ($msg =~ /basic\s(block)/io) { return 1; } |
|---|
| 550 | if ($msg =~ /not\s(supported)/io) { return 1; } |
|---|
| 551 | if ($msg =~ /step\s(unknown)/io) { return 1; } |
|---|
| 552 | if ($msg =~ /original\s(stmt)/io) { return 1; } |
|---|
| 553 | if ($msg =~ /cycle\s(pattern)/io) { return 1; } |
|---|
| 554 | if ($msg =~ /determine\s(dependence)/io) { return 1; } |
|---|
| 555 | if ($msg =~ /consecutive\s(access)/io) { return 1; } |
|---|
| 556 | if ($msg =~ /vector\s(alignment)/io) { return 1; } |
|---|
| 557 | if ($msg =~ /clobbers\s(memory)/io) { return 1; } |
|---|
| 558 | if ($msg =~ /cost.*worth/io) { return 1; } |
|---|
| 559 | if ($msg =~ /use\s(not)\s(simple)/io) { return 1; } |
|---|
| 560 | if ($msg =~ /no\s(array)\s(mode)/io) { return 1; } |
|---|
| 561 | |
|---|
| 562 | if ($msg =~ /(unsupported|unknown|unexpected)\s(pattern)/io) { return 1; } |
|---|
| 563 | |
|---|
| 564 | if ($msg =~ /interleaved.*(store)/io) { return 1; } |
|---|
| 565 | if ($msg =~ /vector.*(cost)/io) { return 1; } |
|---|
| 566 | if ($msg =~ /group.*too\s(large)/io) { return 1; } |
|---|
| 567 | if ($msg =~ /unary\/binary\/ternary/io) { return 1; } |
|---|
| 568 | |
|---|
| 569 | return 0; |
|---|
| 570 | } |
|---|
| 571 | |
|---|
| 572 | sub parse_input(\@) { |
|---|
| 573 | my ($out_r) = @_; |
|---|
| 574 | my @related = (); |
|---|
| 575 | my $location_info = undef; |
|---|
| 576 | |
|---|
| 577 | my @warnout = (); |
|---|
| 578 | my @errout = (); |
|---|
| 579 | my @loopnote = (); # contains notes about loop-optimizations (refs to array [file line msg]) |
|---|
| 580 | |
|---|
| 581 | my $did_show_previous = 0; |
|---|
| 582 | my $is_error = 0; |
|---|
| 583 | my $curr_out_r = \@warnout; |
|---|
| 584 | |
|---|
| 585 | LINE: while (defined($_=<STDIN>)) { |
|---|
| 586 | chomp; |
|---|
| 587 | my $filter_current = 0; |
|---|
| 588 | |
|---|
| 589 | next LINE if $_ eq ''; |
|---|
| 590 | |
|---|
| 591 | if ($_ =~ $reg_file) { |
|---|
| 592 | my ($file,$line,$msg) = ($1,$2,$'); |
|---|
| 593 | |
|---|
| 594 | if ($msg =~ $reg_is_warning_or_note) { |
|---|
| 595 | my $msg_type = lc($1); # 'warning' or 'note' |
|---|
| 596 | my $msg_text = $'; # rest of line |
|---|
| 597 | |
|---|
| 598 | if ($msg_text =~ $reg_shadow_location) { # shadow location does occur as warning or note (depending on gcc version) |
|---|
| 599 | if (not defined $shadow_warning) { warning('no shadow_warning seen',@warnout); } |
|---|
| 600 | else { |
|---|
| 601 | if (suppress_shadow_warning_for($file)) { |
|---|
| 602 | # don't warn about /usr/include or <built-in> shadowing |
|---|
| 603 | $_ = suppress($_,@warnout, 'shadowed'); |
|---|
| 604 | @related = (); |
|---|
| 605 | $location_info = undef; |
|---|
| 606 | } |
|---|
| 607 | else { |
|---|
| 608 | if (defined $location_info) { |
|---|
| 609 | push @warnout, $location_info; |
|---|
| 610 | $location_info = undef; |
|---|
| 611 | } |
|---|
| 612 | push @warnout, $shadow_warning; |
|---|
| 613 | } |
|---|
| 614 | $shadow_warning = undef; |
|---|
| 615 | } |
|---|
| 616 | } |
|---|
| 617 | elsif ($msg_type eq 'warning') { |
|---|
| 618 | my $warn_text = $msg_text; |
|---|
| 619 | |
|---|
| 620 | if ($warn_text =~ $reg_shadow_warning) { |
|---|
| 621 | if (not $' =~ /this/) { # don't store this warnings (no location follows) |
|---|
| 622 | store_shadow($_,@warnout); |
|---|
| 623 | $_ = suppress($_,@warnout, 'shadow-this'); |
|---|
| 624 | } |
|---|
| 625 | elsif (suppress_shadow_warning_for($file)) { |
|---|
| 626 | $_ = suppress($_,@warnout, 'shadow'); |
|---|
| 627 | # $location_info = undef; |
|---|
| 628 | } |
|---|
| 629 | } |
|---|
| 630 | elsif ($warn_text =~ $reg_unknown_gcc_diagnostic) { |
|---|
| 631 | # filter warnings about unknown "pragma GCC diagnostic push/pop" |
|---|
| 632 | die if not defined $compilerVersionNumber; |
|---|
| 633 | if ($compilerVersionNumber<=447) { |
|---|
| 634 | $filter_current = 1; # ignore this warning |
|---|
| 635 | } |
|---|
| 636 | # otherwise show (affects 4.5.x; 4.6.x accepts push/pop) |
|---|
| 637 | } |
|---|
| 638 | else { |
|---|
| 639 | my $warn_is = Weffpp_warning_wanted($file,$line,$warn_text); |
|---|
| 640 | if ($warn_is == $UNWANTED) { |
|---|
| 641 | $filter_current = 1; # ignore this warning |
|---|
| 642 | } |
|---|
| 643 | elsif ($warn_is == $WANTED_NO_RELATED) { |
|---|
| 644 | @related = (); # drop related messages |
|---|
| 645 | } |
|---|
| 646 | # rebuild warning (Weffpp_warning_wanted might modify the message) |
|---|
| 647 | $_ = $file.':'.$line.': warning: '.$warn_text; |
|---|
| 648 | } |
|---|
| 649 | $is_error = 0; |
|---|
| 650 | $curr_out_r = \@warnout; |
|---|
| 651 | } |
|---|
| 652 | elsif ($msg_type eq 'note') { |
|---|
| 653 | my $note_after = 1; # 0->message follows note; 1->note follows message |
|---|
| 654 | |
|---|
| 655 | my $note = $msg_text; |
|---|
| 656 | if (is_loopNote($note)==1) { |
|---|
| 657 | push @loopnote, [ $file, $line, $msg ]; |
|---|
| 658 | $_ = suppress($_,@warnout, 'loop-note'); |
|---|
| 659 | } |
|---|
| 660 | else { |
|---|
| 661 | if ($note_after==1) { |
|---|
| 662 | if ($did_show_previous==0) { |
|---|
| 663 | if (scalar(@loopnote)>0) { |
|---|
| 664 | push @loopnote, [ $file, $line, 'ASSUMING_LOOPNOTE [FIXME]: '.$msg ]; |
|---|
| 665 | $_ = suppress($_,@warnout, 'loop-note'); |
|---|
| 666 | } |
|---|
| 667 | else { |
|---|
| 668 | $_ = suppress($_,@warnout, 'note-of-nonshown'); |
|---|
| 669 | } |
|---|
| 670 | } |
|---|
| 671 | else { |
|---|
| 672 | if ($msg =~ /in\sexpansion\sof\smacro/o) { |
|---|
| 673 | drop_last_pushed_relateds(@$curr_out_r); |
|---|
| 674 | } |
|---|
| 675 | } |
|---|
| 676 | } |
|---|
| 677 | else { |
|---|
| 678 | # note leads message -> store in related |
|---|
| 679 | push @related, $_; |
|---|
| 680 | $_ = suppress($_,@warnout, 'note'); |
|---|
| 681 | } |
|---|
| 682 | } |
|---|
| 683 | } |
|---|
| 684 | } |
|---|
| 685 | elsif ($msg =~ $reg_is_error) { |
|---|
| 686 | $is_error = 1; |
|---|
| 687 | $curr_out_r = \@errout; |
|---|
| 688 | } |
|---|
| 689 | elsif ($msg =~ $reg_is_instantiated) { |
|---|
| 690 | push @related, $_; |
|---|
| 691 | $_ = suppress($_,@warnout, 'instanciated'); |
|---|
| 692 | } |
|---|
| 693 | elsif ($msg =~ $reg_is_required) { |
|---|
| 694 | push @related, $_; |
|---|
| 695 | $_ = suppress($_,@warnout, 'required'); |
|---|
| 696 | } |
|---|
| 697 | elsif ($msg =~ $reg_is_optimizerMsg) { # message from optimized (gcc 9.1++) |
|---|
| 698 | my $note = $'; |
|---|
| 699 | if (is_loopNote($note)==1) { |
|---|
| 700 | push @loopnote, [ $file, $line, $msg ]; |
|---|
| 701 | $_ = suppress($_,@warnout, 'loop-note'); |
|---|
| 702 | } |
|---|
| 703 | else { |
|---|
| 704 | $_ = suppress($_,@warnout, 'optimizerMsg-of-nonshown'); |
|---|
| 705 | } |
|---|
| 706 | } |
|---|
| 707 | } |
|---|
| 708 | elsif ($_ =~ $reg_location or $_ =~ $reg_location2 or $_ =~ $reg_location3) { |
|---|
| 709 | $location_info = $_; |
|---|
| 710 | $_ = suppress($_,@warnout, 'location'); |
|---|
| 711 | } |
|---|
| 712 | elsif ($_ =~ $reg_inlined_from) { |
|---|
| 713 | $_ = $2.': note: '.$1; |
|---|
| 714 | push @related, $_; |
|---|
| 715 | $_ = suppress($_,@warnout, 'inlined'); |
|---|
| 716 | } |
|---|
| 717 | elsif ($_ =~ $reg_included) { |
|---|
| 718 | push @related, included_from_here($1); |
|---|
| 719 | $_ = suppress($_,@warnout, 'included'); |
|---|
| 720 | } |
|---|
| 721 | elsif ($_ =~ $reg_clang_dirt) { |
|---|
| 722 | $_ = undef; |
|---|
| 723 | } |
|---|
| 724 | elsif ($_ =~ $reg_file_noline) { |
|---|
| 725 | if (/^(cc1plus|g\+\+|clang):.*error/o) { |
|---|
| 726 | ; # display normally |
|---|
| 727 | } |
|---|
| 728 | else { |
|---|
| 729 | # push @related, included_from_here($1); |
|---|
| 730 | push @related, $_; |
|---|
| 731 | $_ = suppress($_,@warnout, 'file-level-comment'); |
|---|
| 732 | } |
|---|
| 733 | } |
|---|
| 734 | elsif (@related) { |
|---|
| 735 | if ($_ =~ $reg_included2) { |
|---|
| 736 | push @related, included_from_here($1); |
|---|
| 737 | $_ = suppress($_,@warnout, 'included2'); |
|---|
| 738 | } |
|---|
| 739 | } |
|---|
| 740 | |
|---|
| 741 | if (defined $_) { |
|---|
| 742 | if ($filter_current==0) { |
|---|
| 743 | if ($show_suppressed_lines==1) { warning('passing: '.$_, @warnout); } |
|---|
| 744 | push_loc_and_related($location_info,$_,@related,@$curr_out_r); |
|---|
| 745 | $did_show_previous = 1; |
|---|
| 746 | |
|---|
| 747 | if (($is_error==1) and ($stop_after_first_error==1)) { |
|---|
| 748 | @warnout = (); # drop warnings |
|---|
| 749 | last LINE; |
|---|
| 750 | } |
|---|
| 751 | } |
|---|
| 752 | else { |
|---|
| 753 | die "can't filter errors (Error=$_)" if ($is_error==1); |
|---|
| 754 | if ($show_filtered_lines==1) { warning('filtered: '.$_, @$curr_out_r); } |
|---|
| 755 | $did_show_previous = 0; |
|---|
| 756 | } |
|---|
| 757 | $location_info = undef; |
|---|
| 758 | @related = (); |
|---|
| 759 | } |
|---|
| 760 | } |
|---|
| 761 | |
|---|
| 762 | @$out_r = @errout; |
|---|
| 763 | if ($hide_warnings==0) { push @$out_r, @warnout; } |
|---|
| 764 | |
|---|
| 765 | if ($dump_loop_optimization or $check_loop_optimization) { |
|---|
| 766 | # description of vectorization checks available in SOURCE_TOOLS/vectorize.README |
|---|
| 767 | |
|---|
| 768 | my @loopmsg = (); |
|---|
| 769 | foreach my $vref (@loopnote) { |
|---|
| 770 | my ($file,$line,$msg) = @$vref; |
|---|
| 771 | my $boring = 0; |
|---|
| 772 | if ($msg =~ /completely\sunrolled/o) { $boring = 1; } |
|---|
| 773 | if (not $boring) { push @loopmsg, $vref; } |
|---|
| 774 | } |
|---|
| 775 | |
|---|
| 776 | # sort messages and count + replace duplicates |
|---|
| 777 | @loopmsg = sort { compare_located_messages($a,$b); } @loopmsg; |
|---|
| 778 | { |
|---|
| 779 | my @undup_loopmsg = (); |
|---|
| 780 | my $seenDups = 0; |
|---|
| 781 | push @loopmsg, [ 'x', 0, '' ]; # append sentinel (forces proper counter for last message) |
|---|
| 782 | foreach (@loopmsg) { |
|---|
| 783 | my $prev = pop @undup_loopmsg; |
|---|
| 784 | if (defined $prev) { |
|---|
| 785 | if (compare_located_messages($prev,$_)!=0) { |
|---|
| 786 | if ($seenDups>0) { $$prev[2] = $$prev[2].' ['.($seenDups+1).'x]'; } # append counter |
|---|
| 787 | push @undup_loopmsg, $prev; |
|---|
| 788 | $seenDups = 0; |
|---|
| 789 | } |
|---|
| 790 | else { $seenDups++; } |
|---|
| 791 | } |
|---|
| 792 | push @undup_loopmsg, $_; |
|---|
| 793 | } |
|---|
| 794 | pop @undup_loopmsg; |
|---|
| 795 | @loopmsg = @undup_loopmsg; |
|---|
| 796 | } |
|---|
| 797 | |
|---|
| 798 | my %loopfiles = map { $$_[0] => 1; } @loopmsg; # list of files for which loop-messages were found |
|---|
| 799 | |
|---|
| 800 | if ($dump_loop_optimization) { |
|---|
| 801 | if (scalar(@loopmsg)) { |
|---|
| 802 | push @$out_r, "---------------------------------------- dump_loop_optimization"; |
|---|
| 803 | foreach my $vref (@loopmsg) { |
|---|
| 804 | my ($file,$line,$msg) = @$vref; |
|---|
| 805 | if ($dump_loop_optimization==1 or is_successfulVectorizationMsg($msg)==1) { |
|---|
| 806 | push @$out_r, "$file:$line: note: $msg"; |
|---|
| 807 | } |
|---|
| 808 | } |
|---|
| 809 | push @$out_r, "---------------------------------------- dump_loop_optimization [end]"; |
|---|
| 810 | if ((not $check_loop_optimization) and ($REQ_check_loop_optimization==1) and ($dump_loop_optimization != 2)) { |
|---|
| 811 | my $vref = $loopmsg[0]; |
|---|
| 812 | my $loc = $$vref[0].':'.$$vref[1]; |
|---|
| 813 | push @$out_r, "$loc: Warning: vectorization checks disabled in this file (need at least one vectorization-comment in ${REQ_checked_file})"; |
|---|
| 814 | } |
|---|
| 815 | } |
|---|
| 816 | } |
|---|
| 817 | if ($check_loop_optimization || ($dump_loop_optimization==2)) { |
|---|
| 818 | my @comments = (); |
|---|
| 819 | |
|---|
| 820 | if (defined $checked_file) { |
|---|
| 821 | grep_loop_comments($checked_file, @comments); |
|---|
| 822 | |
|---|
| 823 | # read additional comments from included files: |
|---|
| 824 | delete $loopfiles{$checked_file}; |
|---|
| 825 | foreach (keys %loopfiles) { |
|---|
| 826 | my @xtra_comments = (); |
|---|
| 827 | grep_loop_comments($_, @xtra_comments); |
|---|
| 828 | push @comments, @xtra_comments; |
|---|
| 829 | } |
|---|
| 830 | } |
|---|
| 831 | |
|---|
| 832 | my $dump_comments = 0; # dump comments for debug purposes (should be disabled) |
|---|
| 833 | if ($dump_loop_optimization and $dump_comments) { |
|---|
| 834 | if (scalar(@comments)) { |
|---|
| 835 | push @$out_r, "---------------------------------------- dump_detected_comments"; |
|---|
| 836 | foreach my $cref (@comments) { |
|---|
| 837 | my ($file,$line,$msg) = @$cref; |
|---|
| 838 | push @$out_r, "$file:$line: $msg"; |
|---|
| 839 | } |
|---|
| 840 | push @$out_r, "---------------------------------------- dump_detected_comments [end]"; |
|---|
| 841 | } |
|---|
| 842 | } |
|---|
| 843 | |
|---|
| 844 | my $errors = 0; |
|---|
| 845 | foreach my $cref (@comments) { |
|---|
| 846 | my $loc = $$cref[0].':'.$$cref[1]; |
|---|
| 847 | my $cmsg = $$cref[2]; |
|---|
| 848 | |
|---|
| 849 | my $was_vectorized = 0; |
|---|
| 850 | my $worthless_vectorization = 0; |
|---|
| 851 | foreach my $vref (@loopmsg) { |
|---|
| 852 | if (compare_message_location($cref,$vref)==0) { |
|---|
| 853 | my $vmsg = $$vref[2]; |
|---|
| 854 | if (is_successfulVectorizationMsg($vmsg)==1) { |
|---|
| 855 | if ($trace_vectorization_success_messages==1) { |
|---|
| 856 | push @$out_r, "$loc: Note: vectorized message='$vmsg'"; |
|---|
| 857 | } |
|---|
| 858 | if ($vmsg =~ /\[([0-9]+)x\]/o) { # vectorized multiple times (e.g. in template) |
|---|
| 859 | $was_vectorized = $1; |
|---|
| 860 | } |
|---|
| 861 | else { |
|---|
| 862 | $was_vectorized = 1; |
|---|
| 863 | } |
|---|
| 864 | } |
|---|
| 865 | elsif (is_notWorthToVectorizeMsg($vmsg)==1) { |
|---|
| 866 | $worthless_vectorization = 1; |
|---|
| 867 | } |
|---|
| 868 | } |
|---|
| 869 | } |
|---|
| 870 | if ($cmsg =~ /^LOOP_VECTORIZED/o) { |
|---|
| 871 | my $rest = $'; |
|---|
| 872 | my $errmsg = undef; |
|---|
| 873 | |
|---|
| 874 | # my $expected_vectorizations = compiler_allowed_by($rest,$errmsg); # check for exclusions of specific compiler versions |
|---|
| 875 | my $expected_vectorizations = parse_expected_vectorizations($rest,$errmsg); |
|---|
| 876 | |
|---|
| 877 | if (defined $errmsg) { |
|---|
| 878 | push @$out_r, "$loc: Error: in vectorize-condition: $errmsg"; |
|---|
| 879 | $errors++; |
|---|
| 880 | } |
|---|
| 881 | else { |
|---|
| 882 | my $possibilities = undef; |
|---|
| 883 | if (ref $expected_vectorizations eq 'ARRAY') { # multiple vectorization counts will be accepted |
|---|
| 884 | my $found_matching = undef; |
|---|
| 885 | foreach my $ev (@$expected_vectorizations) { |
|---|
| 886 | if ($ev==$was_vectorized) { $found_matching = $ev; } |
|---|
| 887 | } |
|---|
| 888 | $possibilities = join('|', @$expected_vectorizations); |
|---|
| 889 | if (defined $found_matching) { |
|---|
| 890 | $expected_vectorizations = $found_matching; |
|---|
| 891 | } |
|---|
| 892 | else { |
|---|
| 893 | $expected_vectorizations = 0; |
|---|
| 894 | } |
|---|
| 895 | } |
|---|
| 896 | |
|---|
| 897 | if (not $was_vectorized) { |
|---|
| 898 | if ($worthless_vectorization==1) { |
|---|
| 899 | push @$out_r, "$loc: Error: possible but worthless loop vectorization rejected -> use IRRELEVANT_LOOP (compiler version=$compilerVersion)"; |
|---|
| 900 | $errors++; |
|---|
| 901 | } |
|---|
| 902 | elsif ((defined $possibilities) or ($expected_vectorizations>0)) { |
|---|
| 903 | push @$out_r, "$loc: Error: loop vectorization failed (compiler version=$compilerVersion)"; |
|---|
| 904 | $errors++; |
|---|
| 905 | } |
|---|
| 906 | # otherwise silently handled like IRRELEVANT_LOOP (meant to handle '=0<cond>') |
|---|
| 907 | } |
|---|
| 908 | else { |
|---|
| 909 | if ($expected_vectorizations==0) { # compiler excluded, but vectorization occurred |
|---|
| 910 | push @$out_r, "$loc: Error: loop vectorization succeeded $was_vectorized"."x (but compiler version '$compilerVersion' excluded by condition)"; |
|---|
| 911 | $errors++; |
|---|
| 912 | } |
|---|
| 913 | elsif ((defined $possibilities) or ($expected_vectorizations>0)) { # check number of vectorizations matches |
|---|
| 914 | if ($expected_vectorizations!=$was_vectorized) { |
|---|
| 915 | my $specified = defined $possibilities ? $possibilities : $expected_vectorizations; |
|---|
| 916 | push @$out_r, "$loc: Error: vectorization count mismatch (specified=$specified, found=$was_vectorized)"; |
|---|
| 917 | $errors++; |
|---|
| 918 | } |
|---|
| 919 | } |
|---|
| 920 | } |
|---|
| 921 | } |
|---|
| 922 | } |
|---|
| 923 | } |
|---|
| 924 | |
|---|
| 925 | foreach my $vref (@loopmsg) { |
|---|
| 926 | my $vmsg = $$vref[2]; |
|---|
| 927 | if (is_successfulVectorizationMsg($vmsg)==1) { |
|---|
| 928 | my $loc = $$vref[0].':'.$$vref[1]; |
|---|
| 929 | if ($trace_vectorization_success_messages==1) { |
|---|
| 930 | push @$out_r, "$loc: Note: vectorized message='$vmsg'"; |
|---|
| 931 | } |
|---|
| 932 | my $has_loop_comment = undef; |
|---|
| 933 | foreach my $cref (@comments) { |
|---|
| 934 | if (compare_message_location($cref,$vref)==0) { |
|---|
| 935 | $has_loop_comment = $$cref[2]; |
|---|
| 936 | } |
|---|
| 937 | } |
|---|
| 938 | if (not defined $has_loop_comment) { |
|---|
| 939 | push @$out_r, "$loc: Warning: Unchecked optimized loop"; |
|---|
| 940 | push @$out_r, "$loc: Note: Comment with LOOP_VECTORIZED to force check"; |
|---|
| 941 | push @$out_r, "$loc: Note: Comment with IRRELEVANT_LOOP to hide this warning"; |
|---|
| 942 | } |
|---|
| 943 | } |
|---|
| 944 | } |
|---|
| 945 | if ($errors) { $exitcode = 1; } |
|---|
| 946 | } |
|---|
| 947 | } |
|---|
| 948 | } |
|---|
| 949 | |
|---|
| 950 | sub die_usage($) { |
|---|
| 951 | my ($err) = @_; |
|---|
| 952 | print "Usage: postcompile.pl [Options] sourcefile\n"; |
|---|
| 953 | print "Used as compilation output filter for C/C++\n"; |
|---|
| 954 | print "Options:\n"; |
|---|
| 955 | print " --no-warnings hide warnings (plus related messages)\n"; |
|---|
| 956 | print " --only-first-error show only first error\n"; |
|---|
| 957 | print " --original pass-through\n"; |
|---|
| 958 | print " --show-useless-Weff++ do not suppress useless -Weff++ warnings\n"; |
|---|
| 959 | print " --hide-Noncopyable-advices do not advice about using Noncopyable\n"; |
|---|
| 960 | print " --compiler=version needed for --check-loop-optimization (version e.g. '4.9.1')\n"; |
|---|
| 961 | print " --dump-loop-optimization dump (most) notes related to loop vectorization\n"; |
|---|
| 962 | print " --loop-optimization-candi show candidates for loop vectorization-check\n"; |
|---|
| 963 | print " --check-loop-optimization if sourcefile is listed in \$ARBHOME/SOURCE_TOOLS/vectorized.source,\n"; |
|---|
| 964 | print " => check commented loops have been vectorized\n"; |
|---|
| 965 | |
|---|
| 966 | if (defined $err) { |
|---|
| 967 | die "Error in postcompile.pl: $err"; |
|---|
| 968 | } |
|---|
| 969 | } |
|---|
| 970 | |
|---|
| 971 | sub set_dump_loop_optimization($) { |
|---|
| 972 | my ($val) = @_; |
|---|
| 973 | die if $val==0; |
|---|
| 974 | if ($dump_loop_optimization==0) { |
|---|
| 975 | $dump_loop_optimization = $val; |
|---|
| 976 | } |
|---|
| 977 | else { |
|---|
| 978 | die "dump_loop_optimization already set (old=$dump_loop_optimization; new=$val)"; |
|---|
| 979 | # may e.g. happen when using --dump-loop-optimization AND --loop-optimization-candi |
|---|
| 980 | } |
|---|
| 981 | } |
|---|
| 982 | |
|---|
| 983 | sub main() { |
|---|
| 984 | my $args = scalar(@ARGV); |
|---|
| 985 | my $pass_through = 0; |
|---|
| 986 | my $sourcefile = undef; |
|---|
| 987 | while ($args>0) { |
|---|
| 988 | my $arg = shift(@ARGV); |
|---|
| 989 | if ($arg eq '--no-warnings') { $hide_warnings = 1; } |
|---|
| 990 | elsif ($arg eq '--only-first-error') { $stop_after_first_error = 1; } |
|---|
| 991 | elsif ($arg eq '--original') { $pass_through = 1; } |
|---|
| 992 | elsif ($arg eq '--show-useless-Weff++') { $filter_Weffpp = 0; } |
|---|
| 993 | elsif ($arg eq '--hide-Noncopyable-advices') { $filter_Weffpp_copyable = 1; } |
|---|
| 994 | elsif ($arg eq '--dump-loop-optimization') { set_dump_loop_optimization(1); } |
|---|
| 995 | elsif ($arg eq '--loop-optimization-candi') { set_dump_loop_optimization(2); } |
|---|
| 996 | elsif ($arg eq '--check-loop-optimization') { $check_loop_optimization = 1; } |
|---|
| 997 | elsif ($arg =~ /^--compiler=/o) { $compilerVersion = $'; calcVersionNumber(); } |
|---|
| 998 | elsif (not defined $sourcefile) { $sourcefile = $arg; } |
|---|
| 999 | else { |
|---|
| 1000 | die_usage("Unknown argument '$arg'"); |
|---|
| 1001 | } |
|---|
| 1002 | $args--; |
|---|
| 1003 | } |
|---|
| 1004 | |
|---|
| 1005 | defined $sourcefile || die_usage("missing argument 'sourcefile'"); |
|---|
| 1006 | if (not -f $sourcefile) { die "Unknown sourcefile '$sourcefile'"; } |
|---|
| 1007 | |
|---|
| 1008 | eval { |
|---|
| 1009 | if ($pass_through==1) { |
|---|
| 1010 | while (defined($_=<STDIN>)) { print $_; } |
|---|
| 1011 | } |
|---|
| 1012 | else { |
|---|
| 1013 | my @out = (); |
|---|
| 1014 | detect_needLoopCheck($sourcefile); |
|---|
| 1015 | parse_input(@out); |
|---|
| 1016 | store_shadow(undef,@out); |
|---|
| 1017 | foreach (@out) { print "$_\n"; } |
|---|
| 1018 | } |
|---|
| 1019 | }; |
|---|
| 1020 | my $err = $@; |
|---|
| 1021 | save_from_NC(); |
|---|
| 1022 | if ($err) { die $err; } |
|---|
| 1023 | } |
|---|
| 1024 | main(); |
|---|
| 1025 | exit $exitcode; |
|---|