commit 294f69e662d1 ("compiler_attributes.h: Add 'fallthrough' pseudo keyword for switch/case use") added the pseudo keyword so add a test for it to checkpatch. Warn on a patch or use --strict for files.
Showing the changes to scripts/checkpatch.pl (1 of 1 file). Show all
Unified · Split
| @@ -2294,6 +2294,19 @@ sub pos_last_openparen { · 2293 unmodified lines | ||
| 2294 | 2294 | return length(expand_tabs(substr($line, 0, $last_openparen))) + 1; |
| 2295 | 2295 | } |
| 2296 | 2296 | |
| 2297 | +sub get_raw_comment { | |
| 2298 | + my ($line, $rawline) = @_; | |
| 2299 | + my $comment = ''; | |
| 2300 | + | |
| 2301 | + for my $i (0 .. (length($line) - 1)) { | |
| 2302 | + if (substr($line, $i, 1) eq "$;") { | |
| 2303 | + $comment .= substr($rawline, $i, 1); | |
| 2304 | + } | |
| 2305 | + } | |
| 2306 | + | |
| 2307 | + return $comment; | |
| 2308 | +} | |
| 2309 | + | |
| 2297 | 2310 | sub process { |
| 2298 | 2311 | my $filename = shift; |
| 2299 | 2312 | |
| @@ -2455,6 +2468,7 @@ sub process { · 155 unmodified lines | ||
| 2455 | 2468 | $sline =~ s/$;/ /g; #with comments as spaces |
| 2456 | 2469 | |
| 2457 | 2470 | my $rawline = $rawlines[$linenr - 1]; |
| 2471 | + my $raw_comment = get_raw_comment($line, $rawline); | |
| 2458 | 2472 | |
| 2459 | 2473 | # check if it's a mode change, rename or start of a patch |
| 2460 | 2474 | if (!$in_commit_log && |
| @@ -6408,6 +6422,28 @@ sub process { · 3947 unmodified lines | ||
| 6408 | 6422 | } |
| 6409 | 6423 | } |
| 6410 | 6424 | |
| 6425 | +# check for /* fallthrough */ like comment, prefer fallthrough; | |
| 6426 | + my @fallthroughs = ( | |
| 6427 | + 'fallthrough', | |
| 6428 | + '@fallthrough@', | |
| 6429 | + 'lint -fallthrough[ \t]*', | |
| 6430 | + 'intentional(?:ly)?[ \t]*fall(?:(?:s | |-)[Tt]|t)hr(?:ough|u|ew)', | |
| 6431 | + '(?:else,?\s*)?FALL(?:S | |-)?THR(?:OUGH|U|EW)[ \t.!]*(?:-[^\n\r]*)?', | |
| 6432 | + 'Fall(?:(?:s | |-)[Tt]|t)hr(?:ough|u|ew)[ \t.!]*(?:-[^\n\r]*)?', | |
| 6433 | + 'fall(?:s | |-)?thr(?:ough|u|ew)[ \t.!]*(?:-[^\n\r]*)?', | |
| 6434 | + ); | |
| 6435 | + if ($raw_comment ne '') { | |
| 6436 | + foreach my $ft (@fallthroughs) { | |
| 6437 | + if ($raw_comment =~ /$ft/) { | |
| 6438 | + my $msg_level = \&WARN; | |
| 6439 | + $msg_level = \&CHK if ($file); | |
| 6440 | + &{$msg_level}("PREFER_FALLTHROUGH", | |
| 6441 | + "Prefer 'fallthrough;' over fallthrough comment\n" . $herecurr); | |
| 6442 | + last; | |
| 6443 | + } | |
| 6444 | + } | |
| 6445 | + } | |
| 6446 | + | |
| 6411 | 6447 | # check for switch/default statements without a break; |
| 6412 | 6448 | if ($perl_version_ok && |
| 6413 | 6449 | defined $stat && |