Skip to content
Snippets Groups Projects
Commit 8c06fbdf authored by Peter Maydell's avatar Peter Maydell
Browse files

scripts/checkpatch.pl: Enforce multiline comment syntax


We now require Linux-kernel-style multiline comments:
    /*
     * line one
     * line two
     */

Enforce this in checkpatch.pl, by backporting the relevant
parts of the Linux kernel's checkpatch.pl. (The only changes
needed are that Linux's checkpatch.pl WARN() function takes
an extra argument that ours does not, and the kernel has a
special case for networking code we don't want.)"

The kernel's checkpatch does not enforce "leading /* on
a line of its own, so that part is unique to QEMU's checkpatch.

Sample warning output:

WARNING: Block comments use a leading /* on a separate line
#34: FILE: hw/intc/arm_gicv3_common.c:39:
+    /* Older versions of QEMU had a bug in the handling of state save/restore

Signed-off-by: default avatarPeter Maydell <peter.maydell@linaro.org>
Acked-by: default avatarThomas Huth <thuth@redhat.com>
Reviewed-by: default avatarMarkus Armbruster <armbru@redhat.com>
parent 0f98c994
No related branches found
No related tags found
No related merge requests found
......@@ -1569,6 +1569,54 @@ sub process {
# check we are in a valid C source file if not then ignore this hunk
next if ($realfile !~ /\.(h|c|cpp)$/);
# Block comment styles
# Block comments use /* on a line of its own
if ($rawline !~ m@^\+.*/\*.*\*/[ \t]*$@ && #inline /*...*/
$rawline =~ m@^\+.*/\*\*?[ \t]*.+[ \t]*$@) { # /* or /** non-blank
WARN("Block comments use a leading /* on a separate line\n" . $herecurr);
}
# Block comments use * on subsequent lines
if ($prevline =~ /$;[ \t]*$/ && #ends in comment
$prevrawline =~ /^\+.*?\/\*/ && #starting /*
$prevrawline !~ /\*\/[ \t]*$/ && #no trailing */
$rawline =~ /^\+/ && #line is new
$rawline !~ /^\+[ \t]*\*/) { #no leading *
WARN("Block comments use * on subsequent lines\n" . $hereprev);
}
# Block comments use */ on trailing lines
if ($rawline !~ m@^\+[ \t]*\*/[ \t]*$@ && #trailing */
$rawline !~ m@^\+.*/\*.*\*/[ \t]*$@ && #inline /*...*/
$rawline !~ m@^\+.*\*{2,}/[ \t]*$@ && #trailing **/
$rawline =~ m@^\+[ \t]*.+\*\/[ \t]*$@) { #non blank */
WARN("Block comments use a trailing */ on a separate line\n" . $herecurr);
}
# Block comment * alignment
if ($prevline =~ /$;[ \t]*$/ && #ends in comment
$line =~ /^\+[ \t]*$;/ && #leading comment
$rawline =~ /^\+[ \t]*\*/ && #leading *
(($prevrawline =~ /^\+.*?\/\*/ && #leading /*
$prevrawline !~ /\*\/[ \t]*$/) || #no trailing */
$prevrawline =~ /^\+[ \t]*\*/)) { #leading *
my $oldindent;
$prevrawline =~ m@^\+([ \t]*/?)\*@;
if (defined($1)) {
$oldindent = expand_tabs($1);
} else {
$prevrawline =~ m@^\+(.*/?)\*@;
$oldindent = expand_tabs($1);
}
$rawline =~ m@^\+([ \t]*)\*@;
my $newindent = $1;
$newindent = expand_tabs($newindent);
if (length($oldindent) ne length($newindent)) {
WARN("Block comments should align the * on each line\n" . $hereprev);
}
}
# Check for potential 'bare' types
my ($stat, $cond, $line_nr_next, $remain_next, $off_next,
$realline_next);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment