filter-clang-warnings.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/usr/bin/env python3
  2. #
  3. # Script to analyze warnings produced by clang.
  4. #
  5. # This file is part of GCC.
  6. #
  7. # GCC is free software; you can redistribute it and/or modify it under
  8. # the terms of the GNU General Public License as published by the Free
  9. # Software Foundation; either version 3, or (at your option) any later
  10. # version.
  11. #
  12. # GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  13. # WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  15. # for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with GCC; see the file COPYING3. If not see
  19. # <http://www.gnu.org/licenses/>. */
  20. #
  21. #
  22. #
  23. import argparse
  24. def skip_warning(filename, message):
  25. ignores = {
  26. '': ['-Warray-bounds', '-Wmismatched-tags',
  27. 'gcc_gfc: -Wignored-attributes', '-Wchar-subscripts',
  28. 'string literal (potentially insecure): -Wformat-security',
  29. '-Wdeprecated-register',
  30. '-Wvarargs', 'keyword is hidden by macro definition',
  31. "but the argument has type 'char *': -Wformat-pedantic",
  32. '-Wnested-anon-types',
  33. 'qualifier in explicit instantiation of',
  34. 'attribute argument not supported: asm_fprintf',
  35. 'when in C++ mode, this behavior is deprecated',
  36. '-Wignored-attributes', '-Wgnu-zero-variadic-macro-arguments',
  37. '-Wformat-security', '-Wundefined-internal',
  38. '-Wunknown-warning-option', '-Wc++20-extensions'],
  39. 'insn-modes.cc': ['-Wshift-count-overflow'],
  40. 'insn-emit.cc': ['-Wtautological-compare'],
  41. 'insn-attrtab.cc': ['-Wparentheses-equality'],
  42. 'gimple-match.cc': ['-Wunused-', '-Wtautological-compare'],
  43. 'generic-match.cc': ['-Wunused-', '-Wtautological-compare'],
  44. 'i386.md': ['-Wparentheses-equality', '-Wtautological-compare',
  45. '-Wtautological-overlap-compare'],
  46. 'sse.md': ['-Wparentheses-equality', '-Wtautological-compare',
  47. '-Wconstant-logical-operand'],
  48. 'mmx.md': ['-Wtautological-compare'],
  49. 'genautomata.cc': ['-Wstring-plus-int'],
  50. 'fold-const-call.cc': ['-Wreturn-type'],
  51. 'gfortran.texi': [''],
  52. 'libtool': ['']
  53. }
  54. for name, ignores in ignores.items():
  55. for i in ignores:
  56. if name in filename and i in message:
  57. return True
  58. return False
  59. parser = argparse.ArgumentParser()
  60. parser.add_argument('log', help='Log file with clang warnings')
  61. args = parser.parse_args()
  62. lines = [line.strip() for line in open(args.log)]
  63. total = 0
  64. messages = []
  65. for line in lines:
  66. token = ': warning: '
  67. i = line.find(token)
  68. if i != -1:
  69. location = line[:i]
  70. message = line[i + len(token):]
  71. if not skip_warning(location, message):
  72. total += 1
  73. messages.append(line)
  74. for line in sorted(messages):
  75. print(line)
  76. print('\nTotal warnings: %d' % total)