From 5d9ee04f569232f3eadbdae214058c87225145cc Mon Sep 17 00:00:00 2001 From: Chih-Hung Hsieh Date: Tue, 1 Jun 2021 16:03:22 -0700 Subject: [PATCH] Add new Asm/C++/Java/Make warning patterns * Change some incorrectly-classified logtags warnings to C++. * Fix gpylint warnings of long lines in html_writer.py. Test: warn.py --url=http://cs/android --separator='?l=' build.log > warnings.html Test: warn.py --gencsv build.log > warnings.csv Change-Id: I98c01dadfd72b202d81ef7c94e93c42182f6065c --- tools/warn/cpp_warn_patterns.py | 34 ++++++++++++++++++++++++++++++- tools/warn/html_writer.py | 6 ++++-- tools/warn/java_warn_patterns.py | 6 ++++++ tools/warn/make_warn_patterns.py | 6 ++++++ tools/warn/other_warn_patterns.py | 31 +++++----------------------- 5 files changed, 54 insertions(+), 29 deletions(-) diff --git a/tools/warn/cpp_warn_patterns.py b/tools/warn/cpp_warn_patterns.py index 2fa9916eca..90759d9891 100644 --- a/tools/warn/cpp_warn_patterns.py +++ b/tools/warn/cpp_warn_patterns.py @@ -91,6 +91,8 @@ warn_patterns = [ [r".*: warning: incompatible redeclaration of library function .+"]), high('Null passed as non-null argument', [r".*: warning: Null passed to a callee that requires a non-null"]), + medium('Unused command line argument', + [r".*: warning: argument unused during compilation: .+"]), medium('Unused parameter', [r".*: warning: unused parameter '.*'"]), medium('Unused function, variable, label, comparison, etc.', @@ -166,6 +168,8 @@ warn_patterns = [ [r".*: warning: '.+' declared with greater visibility than the type of its field '.+'"]), medium('Shift count greater than width of type', [r".*: warning: (left|right) shift count >= width of type"]), + medium('Shift operator precedence', + [r".*: warning: operator .* has lower precedence .+Wshift-op-parentheses.+"]), medium('extern <foo> is initialized', [r".*: warning: '.+' initialized and declared 'extern'", r".*: warning: 'extern' variable has an initializer"]), @@ -239,6 +243,8 @@ warn_patterns = [ [r".*: warning: ignoring #pragma .+"]), medium('Pragma warning messages', [r".*: warning: .+W#pragma-messages"]), + medium('Pragma once in main file', + [r".*: warning: #pragma once in main file .+Wpragma-once-outside-header.*"]), medium('Variable might be clobbered by longjmp or vfork', [r".*: warning: variable '.+' might be clobbered by 'longjmp' or 'vfork'"]), medium('Argument might be clobbered by longjmp or vfork', @@ -333,7 +339,7 @@ warn_patterns = [ low('Deprecated register', [r".*: warning: 'register' storage class specifier is deprecated"]), low('Converts between pointers to integer types with different sign', - [r".*: warning: .+ converts between pointers to integer types with different sign"]), + [r".*: warning: .+ converts between pointers to integer types .+Wpointer-sign\]"]), harmless('Extra tokens after #endif', [r".*: warning: extra tokens at end of #endif directive"]), medium('Comparison between different enums', @@ -410,6 +416,32 @@ warn_patterns = [ [r".*: warning: missing .+Winvalid-pp-token"]), low('need glibc to link', [r".*: warning: .* requires at runtime .* glibc .* for linking"]), + low('Add braces to avoid dangling else', + [r".*: warning: add explicit braces to avoid dangling else"]), + low('Assigning value to self', + [r".*: warning: explicitly assigning value of .+ to itself"]), + low('Comparison of integers of different signs', + [r".*: warning: comparison of integers of different signs.+sign-compare"]), + low('Incompatible pointer types', + [r".*: warning: incompatible .*pointer types .*-Wincompatible-.*pointer-types"]), + low('Missing braces', + [r".*: warning: suggest braces around initialization of", + r".*: warning: too many braces around scalar initializer .+Wmany-braces-around-scalar-init", + r".*: warning: braces around scalar initializer"]), + low('Missing field initializers', + [r".*: warning: missing field '.+' initializer"]), + low('Typedef redefinition', + [r".*: warning: redefinition of typedef '.+' is a C11 feature"]), + low('GNU old-style field designator', + [r".*: warning: use of GNU old-style field designator extension"]), + low('Initializer overrides prior initialization', + [r".*: warning: initializer overrides prior initialization of this subobject"]), + low('GNU extension, variable sized type not at end', + [r".*: warning: field '.+' with variable sized type '.+' not at the end of a struct or class"]), + low('Comparison of constant is always false/true', + [r".*: comparison of .+ is always .+Wtautological-constant-out-of-range-compare"]), + low('Hides overloaded virtual function', + [r".*: '.+' hides overloaded virtual function"]), medium('Operator new returns NULL', [r".*: warning: 'operator new' must not return NULL unless it is declared 'throw\(\)' .+"]), medium('NULL used in arithmetic', diff --git a/tools/warn/html_writer.py b/tools/warn/html_writer.py index ac5d4b7d84..ef173bcb3f 100644 --- a/tools/warn/html_writer.py +++ b/tools/warn/html_writer.py @@ -328,7 +328,8 @@ def dump_fixed(writer, warn_patterns): cur_row_class = 1 - cur_row_class # remove last '\n' out_text = text[:-1] if text[-1] == '\n' else text - writer('' + out_text + '') + writer('' + + out_text + '') writer('') writer('') @@ -355,7 +356,8 @@ def dump_csv(csvwriter, warn_patterns): sort_warnings(warn_patterns) total = 0 for severity in Severity.levels: - total += write_severity(csvwriter, severity, severity.column_header, warn_patterns) + total += write_severity( + csvwriter, severity, severity.column_header, warn_patterns) csvwriter.writerow([total, '', 'All warnings']) diff --git a/tools/warn/java_warn_patterns.py b/tools/warn/java_warn_patterns.py index 534f48d2cd..7dfa8668b7 100644 --- a/tools/warn/java_warn_patterns.py +++ b/tools/warn/java_warn_patterns.py @@ -74,6 +74,8 @@ warn_patterns = [ [r'.*\.class\): warning: Cannot find annotation method .+ in']), java_medium('No class/method in SDK ...', [r'.*\.java:.*: warning: No such (class|method) .* for SDK']), + java_medium('Unknown enum constant', + [r'unknown_source_file: warning: unknown enum constant .+']), # Warnings generated by Error Prone java_medium('Non-ascii characters used, but ascii encoding specified', [r".*: warning: unmappable character for encoding ascii"]), @@ -207,6 +209,8 @@ warn_patterns = [ 'Logging or rethrowing exceptions should usually be preferred to catching and calling printStackTrace'), medium('CatchFail', 'Ignoring exceptions and calling fail() is unnecessary, and makes test output less useful'), + medium('ChangedAbstract', + 'Method has changed \'abstract\' qualifier'), medium('ClassCanBeStatic', 'Inner class is non-static but does not reference enclosing class'), medium('ClassNewInstance', @@ -355,6 +359,8 @@ warn_patterns = [ 'equals method doesn\'t override Object.equals'), medium('NotCloseable', 'Not closeable'), + medium('NullableCollection', + 'Method should not return a nullable collection'), medium('NullableConstructor', 'Constructors should not be annotated with @Nullable since they cannot return null'), medium('NullableDereference', diff --git a/tools/warn/make_warn_patterns.py b/tools/warn/make_warn_patterns.py index a54c502f3a..11ad5ccfd0 100644 --- a/tools/warn/make_warn_patterns.py +++ b/tools/warn/make_warn_patterns.py @@ -35,6 +35,9 @@ warn_patterns = [ {'category': 'make', 'severity': Severity.HIGH, 'description': 'System module linking to a vendor module', 'patterns': [r".*: warning: .+ \(.+\) should not link to .+ \(partition:.+\)"]}, + {'category': 'make', 'severity': Severity.HIGH, + 'description': 'make: lstat file does not exist', + 'patterns': [r".*: warning: lstat .+: file does not exist"]}, {'category': 'make', 'severity': Severity.MEDIUM, 'description': 'Invalid SDK/NDK linking', 'patterns': [r".*: warning: .+ \(.+\) should not link to .+ \(.+\)"]}, @@ -56,6 +59,9 @@ warn_patterns = [ {'category': 'make', 'severity': Severity.MEDIUM, 'description': 'make: deprecated macros', 'patterns': [r".*\.mk:.* warning:.* [A-Z_]+ (is|has been) deprecated."]}, + {'category': 'make', 'severity': Severity.MEDIUM, + 'description': 'make: other Android.mk warnings', + 'patterns': [r".*/Android.mk:.*: warning: .+"]}, ] diff --git a/tools/warn/other_warn_patterns.py b/tools/warn/other_warn_patterns.py index d05c8e90fc..dd078fb49b 100644 --- a/tools/warn/other_warn_patterns.py +++ b/tools/warn/other_warn_patterns.py @@ -75,37 +75,13 @@ warn_patterns = [ # misc warnings misc('Duplicate logtag', [r".*: warning: tag \".+\" \(.+\) duplicated in .+"]), - misc('Typedef redefinition', - [r".*: warning: redefinition of typedef '.+' is a C11 feature"]), - misc('GNU old-style field designator', - [r".*: warning: use of GNU old-style field designator extension"]), - misc('Missing field initializers', - [r".*: warning: missing field '.+' initializer"]), - misc('Missing braces', - [r".*: warning: suggest braces around initialization of", - r".*: warning: too many braces around scalar initializer .+Wmany-braces-around-scalar-init", - r".*: warning: braces around scalar initializer"]), - misc('Comparison of integers of different signs', - [r".*: warning: comparison of integers of different signs.+sign-compare"]), - misc('Add braces to avoid dangling else', - [r".*: warning: add explicit braces to avoid dangling else"]), - misc('Initializer overrides prior initialization', - [r".*: warning: initializer overrides prior initialization of this subobject"]), - misc('Assigning value to self', - [r".*: warning: explicitly assigning value of .+ to itself"]), - misc('GNU extension, variable sized type not at end', - [r".*: warning: field '.+' with variable sized type '.+' not at the end of a struct or class"]), - misc('Comparison of constant is always false/true', - [r".*: comparison of .+ is always .+Wtautological-constant-out-of-range-compare"]), - misc('Hides overloaded virtual function', - [r".*: '.+' hides overloaded virtual function"]), - misc('Incompatible pointer types', - [r".*: warning: incompatible .*pointer types .*-Wincompatible-.*pointer-types"]), # Assembler warnings asm('ASM value size does not match register size', [r".*: warning: value size does not match register size specified by the constraint and modifier"]), asm('IT instruction is deprecated', [r".*: warning: applying IT instruction .* is deprecated"]), + asm('setjmp/longjmp/vfork changed binding', + [r".*: warning: .*(setjmp|longjmp|vfork) changed binding to .*"]), # NDK warnings {'category': 'NDK', 'severity': Severity.HIGH, 'description': 'NDK: Generate guard with empty availability, obsoleted', @@ -168,6 +144,9 @@ warn_patterns = [ {'category': 'RenderScript', 'severity': Severity.LOW, 'description': 'RenderScript warnings', 'patterns': [r'.*\.rscript:.*: warning: ']}, + {'category': 'RenderScript', 'severity': Severity.HIGH, + 'description': 'RenderScript is deprecated', + 'patterns': [r'.*: warning: Renderscript is deprecated:.+']}, # Broken/partial warning messages will be skipped. {'category': 'Misc', 'severity': Severity.SKIP, 'description': 'skip, ,',