Skip to contentSkip to conversation

CHECKPATCH

PATCH In review Don Slutz 4 participants 14 messages Sep 1, 2012 – Sep 8, 2012 Checkpatch

lore
Share & tools
lore

Don Slutz

author
#0 lore raw

PATCH 1/1 CHECKPATCH

I took my best guess as to how to handle tabs and long lines in checkpatch.pl itself.

So I get:
...
total: 0 errors, 7 warnings, 131 lines checked

I also did not figure out how to run a more complete test of the change. Any pointers as to how would be helpful.

Don Slutz (1):
CHECKPATCH: Add warning for single else statement.

 scripts/checkpatch.pl |   72 ++++++++++++++++++++++++++++++++----------------
 1 files changed, 48 insertions(+), 24 deletions(-)
author
#1 lore raw

PATCH 1/1 CHECKPATCH: Add warning for single else statement.

Also add more debug options to find this issue. They were not listed in the help because the are not simple to understand the output of.

For an example:

WARNING: braces {} are necessary even for single statement blocks
+ } else
+ return env->regs[R_EAX];

total: 0 errors, 1 warnings, 41 lines checked

---
 scripts/checkpatch.pl |   72 ++++++++++++++++++++++++++++++++----------------
 1 files changed, 48 insertions(+), 24 deletions(-)
scripts/checkpatch.pl +48 -24
index b98dc6c..140a3a6 100755
@@ -97,6 +97,9 @@ my $dbg_values = 0;
 my $dbg_possible = 0;
 my $dbg_type = 0;
 my $dbg_attr = 0;
+my $dbg_adv_dcs = 0;
+my $dbg_adv_apw = 0;
+my $dbg_adv_checking = 0;
 for my $key (keys %debug) {
 	## no critic
 	eval "\${dbg_$key} = '$debug{$key}';";
@@ -2486,8 +2489,11 @@ sub process {
 		if ($line =~ /(^.*)\bif\b/ && $line !~ /\#\s*if/) {
 			my ($level, $endln, @chunks) =
 				ctx_statement_full($linenr, $realcnt, 1);
-			#print "chunks<$#chunks> linenr<$linenr> endln<$endln> level<$level>\n";
-			#print "APW: <<$chunks[1][0]>><<$chunks[1][1]>>\n";
+                        if ($dbg_adv_apw) {
+                            print "APW: chunks<$#chunks> linenr<$linenr> endln<$endln> level<$level>\n";
+                            print "APW: <<$chunks[1][0]>><<$chunks[1][1]>>\n"
+                                if $#chunks >= 1;
+                        }
 			if ($#chunks >= 0 && $level == 0) {
 				my $allowed = 0;
 				my $seen = 0;
@@ -2500,7 +2506,8 @@ sub process {
 					my ($whitespace) = ($cond =~ /^((?:\s*\n[+-])*\s*)/s);
 					my $offset = statement_rawlines($whitespace) - 1;
 
-					#print "COND<$cond> whitespace<$whitespace> offset<$offset>\n";
+                                        print "COND<$cond> whitespace<$whitespace> offset<$offset>\n"
+                                            if $dbg_adv_apw;
 
 					# We have looked at and allowed this specific line.
 					$suppress_ifbraces{$ln + $offset} = 1;
@@ -2512,18 +2519,22 @@ sub process {
 
 					$seen++ if ($block =~ /^\s*{/);
 
-					#print "cond<$cond> block<$block> allowed<$allowed>\n";
+                                        print "APW: cond<$cond> block<$block> allowed<$allowed>\n"
+                                            if $dbg_adv_apw;
 					if (statement_lines($cond) > 1) {
-						#print "APW: ALLOWED: cond<$cond>\n";
-						$allowed = 1;
+                                            print "APW: ALLOWED: cond<$cond>\n"
+                                                if $dbg_adv_apw;
+                                            $allowed = 1;
 					}
 					if ($block =~/\b(?:if|for|while)\b/) {
-						#print "APW: ALLOWED: block<$block>\n";
-						$allowed = 1;
+                                            print "APW: ALLOWED: block<$block>\n"
+                                                if $dbg_adv_apw;
+                                            $allowed = 1;
 					}
 					if (statement_block_size($block) > 1) {
-						#print "APW: ALLOWED: lines block<$block>\n";
-						$allowed = 1;
+                                            print "APW: ALLOWED: lines block<$block>\n"
+                                                if $dbg_adv_apw;
+                                            $allowed = 1;
 					}
 				}
 				if ($seen != ($#chunks + 1)) {
@@ -2537,44 +2548,57 @@ sub process {
 					$line !~ /\#\s*else/) {
 			my $allowed = 0;
 
-			# Check the pre-context.
-			if (substr($line, 0, $-[0]) =~ /(\}\s*)$/) {
-				#print "APW: ALLOWED: pre<$1>\n";
-				$allowed = 1;
-			}
+                        # Check the pre-context.
+                        if (substr($line, 0, $-[0]) =~ /(\}\s*)$/) {
+                            my $pre = $1;
+
+                            if ($line !~ /else/) {
+                                print "APW: ALLOWED: pre<$pre> line<$line>\n"
+                                    if $dbg_adv_apw;
+                                $allowed = 1;
+                            }
+                        }
 
 			my ($level, $endln, @chunks) =
 				ctx_statement_full($linenr, $realcnt, $-[0]);
 
 			# Check the condition.
 			my ($cond, $block) = @{$chunks[0]};
-			#print "CHECKING<$linenr> cond<$cond> block<$block>\n";
+                        print "CHECKING<$linenr> cond<$cond> block<$block>\n"
+                            if $dbg_adv_checking;
 			if (defined $cond) {
 				substr($block, 0, length($cond), '');
 			}
 			if (statement_lines($cond) > 1) {
-				#print "APW: ALLOWED: cond<$cond>\n";
-				$allowed = 1;
+                            print "APW: ALLOWED: cond<$cond>\n"
+                                if $dbg_adv_apw;
+                            $allowed = 1;
 			}
 			if ($block =~/\b(?:if|for|while)\b/) {
-				#print "APW: ALLOWED: block<$block>\n";
-				$allowed = 1;
+                            print "APW: ALLOWED: block<$block>\n"
+                                if $dbg_adv_apw;
+                            $allowed = 1;
 			}
 			if (statement_block_size($block) > 1) {
-				#print "APW: ALLOWED: lines block<$block>\n";
-				$allowed = 1;
+                            print "APW: ALLOWED: lines block<$block>\n"
+                                if $dbg_adv_apw;
+                            $allowed = 1;
 			}
 			# Check the post-context.
 			if (defined $chunks[1]) {
 				my ($cond, $block) = @{$chunks[1]};
+
 				if (defined $cond) {
 					substr($block, 0, length($cond), '');
 				}
 				if ($block =~ /^\s*\{/) {
-					#print "APW: ALLOWED: chunk-1 block<$block>\n";
-					$allowed = 1;
+                                    print "APW: ALLOWED: chunk-1 block<$block>\n"
+                                        if $dbg_adv_apw;
+                                    $allowed = 1;
 				}
 			}
+                        print "DCS: level=$level block<$block> allowed=$allowed\n"
+                            if $dbg_adv_dcs;
 			if ($level == 0 && $block !~ /^\s*\{/ && !$allowed) {
 				my $herectx = $here . "\n";;
 				my $cnt = statement_rawlines($block);
Signature · 1 line
1.7.1
#2 lore raw

Re: [Qemu-devel] [PATCH] CHECKPATCH: Add warning for single else statement.

Quoted 2 lines · Don Slutz

Also add more debug options to find this issue. They were not listed in the help because the are not simple to understand the output of.

These should form another patch, now it's not easy to see what was the fix for 'else'.

Quoted 157 lines

For an example:

WARNING: braces {} are necessary even for single statement blocks

(quoted diff) +2 -0
+    } else
+        return env->regs[R_EAX];

total: 0 errors, 1 warnings, 41 lines checked

---
 scripts/checkpatch.pl |   72 ++++++++++++++++++++++++++++++++----------------
 1 files changed, 48 insertions(+), 24 deletions(-)
scripts/checkpatch.pl +48 -25
index b98dc6c..140a3a6 100755
@@ -97,6 +97,9 @@ my $dbg_values = 0;
 my $dbg_possible = 0;
 my $dbg_type = 0;
 my $dbg_attr = 0;
+my $dbg_adv_dcs = 0;
+my $dbg_adv_apw = 0;
+my $dbg_adv_checking = 0;
 for my $key (keys %debug) {
        ## no critic
        eval "\${dbg_$key} = '$debug{$key}';";
@@ -2486,8 +2489,11 @@ sub process {
                if ($line =~ /(^.*)\bif\b/ && $line !~ /\#\s*if/) {
                        my ($level, $endln, @chunks) =
                                ctx_statement_full($linenr, $realcnt, 1);
-                       #print "chunks<$#chunks> linenr<$linenr> endln<$endln> level<$level>\n";
-                       #print "APW: <<$chunks[1][0]>><<$chunks[1][1]>>\n";
+                        if ($dbg_adv_apw) {
+                            print "APW: chunks<$#chunks> linenr<$linenr> endln<$endln> level<$level>\n";
+                            print "APW: <<$chunks[1][0]>><<$chunks[1][1]>>\n"
+                                if $#chunks >= 1;
+                        }
                        if ($#chunks >= 0 && $level == 0) {
                                my $allowed = 0;
                                my $seen = 0;
@@ -2500,7 +2506,8 @@ sub process {
                                        my ($whitespace) = ($cond =~ /^((?:\s*\n[+-])*\s*)/s);
                                        my $offset = statement_rawlines($whitespace) - 1;
 
-                                       #print "COND<$cond> whitespace<$whitespace> offset<$offset>\n";
+                                        print "COND<$cond> whitespace<$whitespace> offset<$offset>\n"
+                                            if $dbg_adv_apw;
 
                                        # We have looked at and allowed this specific line.
                                        $suppress_ifbraces{$ln + $offset} = 1;
@@ -2512,18 +2519,22 @@ sub process {
 
                                        $seen++ if ($block =~ /^\s*{/);
 
-                                       #print "cond<$cond> block<$block> allowed<$allowed>\n";
+                                        print "APW: cond<$cond> block<$block> allowed<$allowed>\n"
+                                            if $dbg_adv_apw;
                                        if (statement_lines($cond) > 1) {
-                                               #print "APW: ALLOWED: cond<$cond>\n";
-                                               $allowed = 1;
+                                            print "APW: ALLOWED: cond<$cond>\n"
+                                                if $dbg_adv_apw;
+                                            $allowed = 1;
                                        }
                                        if ($block =~/\b(?:if|for|while)\b/) {
-                                               #print "APW: ALLOWED: block<$block>\n";
-                                               $allowed = 1;
+                                            print "APW: ALLOWED: block<$block>\n"
+                                                if $dbg_adv_apw;
+                                            $allowed = 1;
                                        }
                                        if (statement_block_size($block) > 1) {
-                                               #print "APW: ALLOWED: lines block<$block>\n";
-                                               $allowed = 1;
+                                            print "APW: ALLOWED: lines block<$block>\n"
+                                                if $dbg_adv_apw;
+                                            $allowed = 1;
                                        }
                                }
                                if ($seen != ($#chunks + 1)) {
@@ -2537,44 +2548,57 @@ sub process {
                                        $line !~ /\#\s*else/) {
                        my $allowed = 0;
 
-                       # Check the pre-context.
-                       if (substr($line, 0, $-[0]) =~ /(\}\s*)$/) {
-                               #print "APW: ALLOWED: pre<$1>\n";
-                               $allowed = 1;
-                       }
+                        # Check the pre-context.
+                        if (substr($line, 0, $-[0]) =~ /(\}\s*)$/) {
+                            my $pre = $1;
+
+                            if ($line !~ /else/) {
+                                print "APW: ALLOWED: pre<$pre> line<$line>\n"
+                                    if $dbg_adv_apw;
+                                $allowed = 1;
+                            }
+                        }
 
                        my ($level, $endln, @chunks) =
                                ctx_statement_full($linenr, $realcnt, $-[0]);
 
                        # Check the condition.
                        my ($cond, $block) = @{$chunks[0]};
-                       #print "CHECKING<$linenr> cond<$cond> block<$block>\n";
+                        print "CHECKING<$linenr> cond<$cond> block<$block>\n"
+                            if $dbg_adv_checking;
                        if (defined $cond) {
                                substr($block, 0, length($cond), '');
                        }
                        if (statement_lines($cond) > 1) {
-                               #print "APW: ALLOWED: cond<$cond>\n";
-                               $allowed = 1;
+                            print "APW: ALLOWED: cond<$cond>\n"
+                                if $dbg_adv_apw;
+                            $allowed = 1;
                        }
                        if ($block =~/\b(?:if|for|while)\b/) {
-                               #print "APW: ALLOWED: block<$block>\n";
-                               $allowed = 1;
+                            print "APW: ALLOWED: block<$block>\n"
+                                if $dbg_adv_apw;
+                            $allowed = 1;
                        }
                        if (statement_block_size($block) > 1) {
-                               #print "APW: ALLOWED: lines block<$block>\n";
-                               $allowed = 1;
+                            print "APW: ALLOWED: lines block<$block>\n"
+                                if $dbg_adv_apw;
+                            $allowed = 1;
                        }
                        # Check the post-context.
                        if (defined $chunks[1]) {
                                my ($cond, $block) = @{$chunks[1]};
+
                                if (defined $cond) {
                                        substr($block, 0, length($cond), '');
                                }
                                if ($block =~ /^\s*\{/) {
-                                       #print "APW: ALLOWED: chunk-1 block<$block>\n";
-                                       $allowed = 1;
+                                    print "APW: ALLOWED: chunk-1 block<$block>\n"
+                                        if $dbg_adv_apw;
+                                    $allowed = 1;
                                }
                        }
+                        print "DCS: level=$level block<$block> allowed=$allowed\n"
+                            if $dbg_adv_dcs;
                        if ($level == 0 && $block !~ /^\s*\{/ && !$allowed) {
                                my $herectx = $here . "\n";;
                                my $cnt = statement_rawlines($block);
--

1.7.1

#3 lore raw
In reply to Don Slutz
Quoted 2 lines · Don Slutz

I took my best guess as to how to handle tabs and long lines in checkpatch.pl itself.

Right, it was taken from Linux without much change.

Quoted 7 lines

So I get:
...
total: 0 errors, 7 warnings, 131 lines checked

I also did not figure out how to run a more complete test of the change. Any pointers as to how would be helpful.

I've used the following snippet to check what happens with the last 100 commits:
for i in '' 1 2 3 4 5 6 7 8 9; do for j in 0 1 2 3 4 5 6 7 8 9; do echo $i$j; git show HEAD~$i$j >/tmp/a; clear;head -20 /tmp/a; ./scripts/checkpatch.pl --root=. /tmp/a; read foo; done; done

Sadly, it also shows how much stuff gets committed without checking, and on the other hand, the amount of false alarms.

Quoted 8 lines

Don Slutz (1):
CHECKPATCH: Add warning for single else statement.

 scripts/checkpatch.pl |   72 ++++++++++++++++++++++++++++++++----------------
 1 files changed, 48 insertions(+), 24 deletions(-)
#4 lore raw
Quoted 7 lines · Blue Swirl

I've used the following snippet to check what happens with the last 100 commits:
for i in '' 1 2 3 4 5 6 7 8 9; do for j in 0 1 2 3 4 5 6 7 8 9; do echo $i$j; git show HEAD~$i$j >/tmp/a; clear;head -20 /tmp/a; ./scripts/checkpatch.pl --root=. /tmp/a; read foo; done; done

Sadly, it also shows how much stuff gets committed without checking, and on the other hand, the amount of false alarms.

Maintainers should add a checkpatch invocation as a git hook (advisory only), this could reduce the amount of violations getting into the tree.

Signature · 1 line
error compiling committee.c: too many arguments to function
#5 lore raw
Quoted 11 lines · Avi Kivity
Quoted 7 lines · Blue Swirl

I've used the following snippet to check what happens with the last 100 commits:
for i in '' 1 2 3 4 5 6 7 8 9; do for j in 0 1 2 3 4 5 6 7 8 9; do echo $i$j; git show HEAD~$i$j >/tmp/a; clear;head -20 /tmp/a; ./scripts/checkpatch.pl --root=. /tmp/a; read foo; done; done

Sadly, it also shows how much stuff gets committed without checking, and on the other hand, the amount of false alarms.

Maintainers should add a checkpatch invocation as a git hook (advisory only), this could reduce the amount of violations getting into the tree.

I'd agree. But it looks like we have a few maintainers who actively oppose CODING_STYLE and HACKING and don't reject patches with violations or even inform the submitters about problems. The next level is that we have committers who commit pulls without checking, but I think the responsibility for checking patches for all possible aspects (especially since there are real, deep, technical and architectural issues to consider besides minor issues like style) should not be duplicated at every level.

Quoted 4 lines

--
error compiling committee.c: too many arguments to function

author
#6 lore raw

v2 cover CHECKPATCH: Add warning for single else statement.

In reply to Don Slutz

Also add more debug options to find this issue. They were not listed in the help because the are not simple to understand the output of.

Using:

  rm zz;
  for k in 0 1 2 3; do
   for i in 0 1 2 3 4 5 6 7 8 9; do
    for j in 0 1 2 3 4 5 6 7 8 9; do
     echo $k$i$j;
     git show HEAD~$k$i$j >/tmp/a;
     head -1 /tmp/a >>zz;
     ./scripts/checkpatch.pl --root=. /tmp/a >>zz;
    done;
   done;
  done

With both the new and old versions that the same warnigns and errors were reported.

Don Slutz (4):
CHECKPATCH: Add --debug adv_dcs
CHECKPATCH: Add --debug adv_checking
CHECKPATCH: Add --debug adv_apw
CHECKPATCH: Add warning for single else statement.

 scripts/checkpatch.pl |   68 ++++++++++++++++++++++++++++++++----------------
 1 files changed, 45 insertions(+), 23 deletions(-)
Applied
#7 lore raw

Re: [Qemu-devel] [PATCH v2 0/4] CHECKPATCH: Add warning for single else statement.

Thanks, applied all.

Quoted 28 lines · Don Slutz

Also add more debug options to find this issue. They were not listed in the help because the are not simple to understand the output of.

Using:

  rm zz;
  for k in 0 1 2 3; do
   for i in 0 1 2 3 4 5 6 7 8 9; do
    for j in 0 1 2 3 4 5 6 7 8 9; do
     echo $k$i$j;
     git show HEAD~$k$i$j >/tmp/a;
     head -1 /tmp/a >>zz;
     ./scripts/checkpatch.pl --root=. /tmp/a >>zz;
    done;
   done;
  done

With both the new and old versions that the same warnigns and errors were reported.

Don Slutz (4):
CHECKPATCH: Add --debug adv_dcs
CHECKPATCH: Add --debug adv_checking
CHECKPATCH: Add --debug adv_apw
CHECKPATCH: Add warning for single else statement.

 scripts/checkpatch.pl |   68 ++++++++++++++++++++++++++++++++----------------
 1 files changed, 45 insertions(+), 23 deletions(-)
#8 lore raw

Re: [Qemu-devel] [PATCH v2 0/4] CHECKPATCH: Add warning for single else statement.

Am 05.09.2012 21:46, schrieb Blue Swirl:

Quoted 1 line

Thanks, applied all.

Question: Are additions to checkpatch.pl supposed to be in QEMU Coding Style as done here? Do you plan to convert it consistently then? checkpatch.pl uses tabs consistently, making checkpatch.pl complain. ;) The alternative would be to stick to upstream formatting and exempt checkpatch.pl from its own checks.

Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#9 lore raw

Re: [Qemu-devel] [PATCH v2 0/4] CHECKPATCH: Add warning for single else statement.

Quoted 8 lines · Andreas Färber

Am 05.09.2012 21:46, schrieb Blue Swirl:

Quoted 1 line

Thanks, applied all.

Question: Are additions to checkpatch.pl supposed to be in QEMU Coding Style as done here? Do you plan to convert it consistently then? checkpatch.pl uses tabs consistently, making checkpatch.pl complain. ;) The alternative would be to stick to upstream formatting and exempt checkpatch.pl from its own checks.

I'd suppose checkpatch.pl can't check Perl, Python or sh syntax so we could try to limit some of the checks to C files only. For example tabs are mandatory as the initial character for Makefile rules, we could in theory demand spaces otherwise but I guess nobody cares enough to add checks for this.

Quoted 6 lines

Andreas

--
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg

author
#10 lore raw

PATCH v2 1/4 CHECKPATCH: Add --debug adv_dcs

In reply to Don Slutz

Add debug options to find this issue. They were not listed in the help because the are not simple to understand the output of.

---
 scripts/checkpatch.pl |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
scripts/checkpatch.pl +3 -0
index b98dc6c..0b0f3f3 100755
@@ -97,6 +97,7 @@ my $dbg_values = 0;
 my $dbg_possible = 0;
 my $dbg_type = 0;
 my $dbg_attr = 0;
+my $dbg_adv_dcs = 0;
 for my $key (keys %debug) {
 	## no critic
 	eval "\${dbg_$key} = '$debug{$key}';";
@@ -2575,6 +2576,8 @@ sub process {
 					$allowed = 1;
 				}
 			}
+                        print "DCS: level=$level block<$block> allowed=$allowed\n"
+                            if $dbg_adv_dcs;
 			if ($level == 0 && $block !~ /^\s*\{/ && !$allowed) {
 				my $herectx = $here . "\n";;
 				my $cnt = statement_rawlines($block);
Signature · 1 line
1.7.1
author
#11 lore raw

PATCH v2 2/4 CHECKPATCH: Add --debug adv_checking

In reply to Don Slutz

Add debug options to find this issue. They were not listed in the help because the are not simple to understand the output of.

---
 scripts/checkpatch.pl |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
scripts/checkpatch.pl +3 -1
index 0b0f3f3..8c83b56 100755
@@ -98,6 +98,7 @@ my $dbg_possible = 0;
 my $dbg_type = 0;
 my $dbg_attr = 0;
 my $dbg_adv_dcs = 0;
+my $dbg_adv_checking = 0;
 for my $key (keys %debug) {
 	## no critic
 	eval "\${dbg_$key} = '$debug{$key}';";
@@ -2549,7 +2550,8 @@ sub process {
 
 			# Check the condition.
 			my ($cond, $block) = @{$chunks[0]};
-			#print "CHECKING<$linenr> cond<$cond> block<$block>\n";
+                        print "CHECKING<$linenr> cond<$cond> block<$block>\n"
+                            if $dbg_adv_checking;
 			if (defined $cond) {
 				substr($block, 0, length($cond), '');
 			}
Signature · 1 line
1.7.1
author
#12 lore raw

PATCH v2 3/4 CHECKPATCH: Add --debug adv_apw

In reply to Don Slutz

Add debug options to find this issue. They were not listed in the help because the are not simple to understand the output of.

---
 scripts/checkpatch.pl |   51 ++++++++++++++++++++++++++++++------------------
 1 files changed, 32 insertions(+), 19 deletions(-)
scripts/checkpatch.pl +32 -19
index 8c83b56..7ec8846 100755
@@ -99,6 +99,7 @@ my $dbg_type = 0;
 my $dbg_attr = 0;
 my $dbg_adv_dcs = 0;
 my $dbg_adv_checking = 0;
+my $dbg_adv_apw = 0;
 for my $key (keys %debug) {
 	## no critic
 	eval "\${dbg_$key} = '$debug{$key}';";
@@ -2488,8 +2489,11 @@ sub process {
 		if ($line =~ /(^.*)\bif\b/ && $line !~ /\#\s*if/) {
 			my ($level, $endln, @chunks) =
 				ctx_statement_full($linenr, $realcnt, 1);
-			#print "chunks<$#chunks> linenr<$linenr> endln<$endln> level<$level>\n";
-			#print "APW: <<$chunks[1][0]>><<$chunks[1][1]>>\n";
+                        if ($dbg_adv_apw) {
+                            print "APW: chunks<$#chunks> linenr<$linenr> endln<$endln> level<$level>\n";
+                            print "APW: <<$chunks[1][0]>><<$chunks[1][1]>>\n"
+                                if $#chunks >= 1;
+                        }
 			if ($#chunks >= 0 && $level == 0) {
 				my $allowed = 0;
 				my $seen = 0;
@@ -2514,18 +2518,22 @@ sub process {
 
 					$seen++ if ($block =~ /^\s*{/);
 
-					#print "cond<$cond> block<$block> allowed<$allowed>\n";
+                                        print "APW: cond<$cond> block<$block> allowed<$allowed>\n"
+                                            if $dbg_adv_apw;
 					if (statement_lines($cond) > 1) {
-						#print "APW: ALLOWED: cond<$cond>\n";
-						$allowed = 1;
+                                            print "APW: ALLOWED: cond<$cond>\n"
+                                                if $dbg_adv_apw;
+                                            $allowed = 1;
 					}
 					if ($block =~/\b(?:if|for|while)\b/) {
-						#print "APW: ALLOWED: block<$block>\n";
-						$allowed = 1;
+                                            print "APW: ALLOWED: block<$block>\n"
+                                                if $dbg_adv_apw;
+                                            $allowed = 1;
 					}
 					if (statement_block_size($block) > 1) {
-						#print "APW: ALLOWED: lines block<$block>\n";
-						$allowed = 1;
+                                            print "APW: ALLOWED: lines block<$block>\n"
+                                                if $dbg_adv_apw;
+                                            $allowed = 1;
 					}
 				}
 				if ($seen != ($#chunks + 1)) {
@@ -2541,8 +2549,9 @@ sub process {
 
 			# Check the pre-context.
 			if (substr($line, 0, $-[0]) =~ /(\}\s*)$/) {
-				#print "APW: ALLOWED: pre<$1>\n";
-				$allowed = 1;
+                            print "APW: ALLOWED: pre<$pre> line<$line>\n"
+                                if $dbg_adv_apw;
+                            $allowed = 1;
 			}
 
 			my ($level, $endln, @chunks) =
@@ -2556,16 +2565,19 @@ sub process {
 				substr($block, 0, length($cond), '');
 			}
 			if (statement_lines($cond) > 1) {
-				#print "APW: ALLOWED: cond<$cond>\n";
-				$allowed = 1;
+                            print "APW: ALLOWED: cond<$cond>\n"
+                                if $dbg_adv_apw;
+                            $allowed = 1;
 			}
 			if ($block =~/\b(?:if|for|while)\b/) {
-				#print "APW: ALLOWED: block<$block>\n";
-				$allowed = 1;
+                            print "APW: ALLOWED: block<$block>\n"
+                                if $dbg_adv_apw;
+                            $allowed = 1;
 			}
 			if (statement_block_size($block) > 1) {
-				#print "APW: ALLOWED: lines block<$block>\n";
-				$allowed = 1;
+                            print "APW: ALLOWED: lines block<$block>\n"
+                                if $dbg_adv_apw;
+                            $allowed = 1;
 			}
 			# Check the post-context.
 			if (defined $chunks[1]) {
@@ -2574,8 +2586,9 @@ sub process {
 					substr($block, 0, length($cond), '');
 				}
 				if ($block =~ /^\s*\{/) {
-					#print "APW: ALLOWED: chunk-1 block<$block>\n";
-					$allowed = 1;
+                                    print "APW: ALLOWED: chunk-1 block<$block>\n"
+                                        if $dbg_adv_apw;
+                                    $allowed = 1;
 				}
 			}
                         print "DCS: level=$level block<$block> allowed=$allowed\n"
Signature · 1 line
1.7.1
author
#13 lore raw

PATCH v2 4/4 CHECKPATCH: Add warning for single else statement.

In reply to Don Slutz

For an example:

WARNING: braces {} are necessary even for single statement blocks
+ } else
+ return env->regs[R_EAX];

total: 0 errors, 1 warnings, 41 lines checked

---
 scripts/checkpatch.pl |   16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)
scripts/checkpatch.pl +10 -6
index 7ec8846..ec0aa4c 100755
@@ -2547,12 +2547,16 @@ sub process {
 					$line !~ /\#\s*else/) {
 			my $allowed = 0;
 
-			# Check the pre-context.
-			if (substr($line, 0, $-[0]) =~ /(\}\s*)$/) {
-                            print "APW: ALLOWED: pre<$pre> line<$line>\n"
-                                if $dbg_adv_apw;
-                            $allowed = 1;
-			}
+                        # Check the pre-context.
+                        if (substr($line, 0, $-[0]) =~ /(\}\s*)$/) {
+                            my $pre = $1;
+
+                            if ($line !~ /else/) {
+                                print "APW: ALLOWED: pre<$pre> line<$line>\n"
+                                    if $dbg_adv_apw;
+                                $allowed = 1;
+                            }
+                        }
 
 			my ($level, $endln, @chunks) =
 				ctx_statement_full($linenr, $realcnt, $-[0]);
Signature · 1 line
1.7.1