]> Pileus Git - ~andy/linux/commitdiff
checkpatch: warn when using gcc's binary constant ("0b") extension
authorJoe Perches <joe@perches.com>
Wed, 3 Jul 2013 22:05:20 +0000 (15:05 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 3 Jul 2013 23:07:44 +0000 (16:07 -0700)
The gcc extension for binary constants that start with 0b is only
supported with gcc version 4.3 or higher.

The kernel can still be compiled with earlier versions of gcc, so have
checkpatch emit a warning for these constants.

Restructure checkpatch's constant finding code a bit to support finding
these binary constants.

Signed-off-by: Joe Perches <joe@perches.com>
Suggested-by: Andrew Morton <akpm@linux-foundation.org>
Cc: Andy Whitcroft <apw@canonical.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
scripts/checkpatch.pl

index f1aad19b475ceda7a2656d55adb169b572e3a0a2..517da26d9a2d290bb798c4b4455311578beb5f53 100755 (executable)
@@ -230,11 +230,15 @@ our $Inline       = qr{inline|__always_inline|noinline};
 our $Member    = qr{->$Ident|\.$Ident|\[[^]]*\]};
 our $Lval      = qr{$Ident(?:$Member)*};
 
+our $Int_type  = qr{(?i)llu|ull|ll|lu|ul|l|u};
+our $Binary    = qr{(?i)0b[01]+$Int_type?};
+our $Hex       = qr{(?i)0x[0-9a-f]+$Int_type?};
+our $Int       = qr{[0-9]+$Int_type?};
 our $Float_hex = qr{(?i)0x[0-9a-f]+p-?[0-9]+[fl]?};
 our $Float_dec = qr{(?i)(?:[0-9]+\.[0-9]*|[0-9]*\.[0-9]+)(?:e-?[0-9]+)?[fl]?};
 our $Float_int = qr{(?i)[0-9]+e-?[0-9]+[fl]?};
 our $Float     = qr{$Float_hex|$Float_dec|$Float_int};
-our $Constant  = qr{$Float|(?i)(?:0x[0-9a-f]+|[0-9]+)[ul]*};
+our $Constant  = qr{$Float|$Binary|$Hex|$Int};
 our $Assignment        = qr{\*\=|/=|%=|\+=|-=|<<=|>>=|&=|\^=|\|=|=};
 our $Compare    = qr{<=|>=|==|!=|<|>};
 our $Operators = qr{
@@ -2934,9 +2938,17 @@ sub process {
                        }
                }
 
-#CamelCase
+#Specific variable tests
                while ($line =~ m{($Constant|$Lval)}g) {
                        my $var = $1;
+
+#gcc binary extension
+                       if ($var =~ /^$Binary$/) {
+                               WARN("GCC_BINARY_CONSTANT",
+                                    "Avoid gcc v4.3+ binary constant extension: <$var>\n" . $herecurr);
+                       }
+
+#CamelCase
                        if ($var !~ /$Constant/ &&
                            $var =~ /[A-Z][a-z]|[a-z][A-Z]/ &&
                            $var !~ /"^(?:Clear|Set|TestClear|TestSet|)Page[A-Z]/ &&