Re: [PATCH RFC v2] checkpatch: extend attributes check to handle more patterns

From: Joe Perches
Date: Fri Oct 23 2020 - 16:42:21 EST


On Sat, 2020-10-24 at 00:44 +0530, Dwaipayan Ray wrote:
> Hi,

Hi again.

> I modified the check to check the attributes from the map.
> There are two checks - one for the normal attributes and
> one for the ones with arguments, which needs just a bit more
> processing.
>
> So attributes like __packed__ as well as those like
> __aligned__(x) are handled.
>
> What do you think?
>
> ---
> +            $line =~ /__attribute__\s*\(\s*($balanced_parens)\s*\)/)
> {
> +            my $attr = trim($1);
> +            $attr =~ s/\(\s*_*(.*)\)/$1/;
> +            while($attr =~ s/(.*)_$/$1/) {}  # Remove trailing
> underscores

I think this could be a single test like:

while ($attr =~ /\s*(\w+)\s*(${balanced_parens})?/g) {
my $curr_attr = $1;
my $parens = $2;
$curr_attr = s/^_*(.*)_*$/$1/;

> +            my %attr_list = (
> +                "alias"            => "__alias",
> +                "aligned"        => "__aligned",

These might be better using tab alignment.

And you might special case format(printf/scanf here too