check_warning_flags.sh 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. #! /bin/sh
  2. #
  3. # Check that the warning flags documented in invoke.texi match up
  4. # with what the compiler accepts.
  5. #
  6. # Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
  7. # Written by Ralf Wildenhues <Ralf.Wildenhues@gmx.de>.
  8. #
  9. # This script is Free Software, and it can be copied, distributed and
  10. # modified as defined in the GNU General Public License. A copy of
  11. # its license can be downloaded from http://www.gnu.org/copyleft/gpl.html
  12. #
  13. # Call this script as
  14. # check_warning_flags.sh path/to/invoke.texi
  15. # with CC set to the compiler to be tested.
  16. # The script scribbles in the current directory.
  17. progname=`echo "$0" | sed 's,.*/,,'`
  18. usage ()
  19. {
  20. echo "usage: $progname path/to/gcc/doc"
  21. echo "set \$CC to the compiler to be checked"
  22. exit 1
  23. }
  24. ret=0
  25. LC_ALL=C
  26. export LC_ALL
  27. : ${CC=gcc}
  28. test $# = 1 || usage
  29. gcc_docdir=$1
  30. invoke_texi=$gcc_docdir/invoke.texi
  31. test -r "$invoke_texi" || {
  32. echo "$progname: error: cannot read '$invoke_texi'" >&2
  33. usage
  34. }
  35. filebase=check_warning_flags_file$$
  36. stderr=check_warning_flags_stderr$$
  37. remove_problematic_flags='
  38. /-Wlarger-than-/d
  39. /-Wframe-larger-than/d
  40. /-Wdisallowed-function-list/d
  41. /-W[alp],/d
  42. /-Werror/d
  43. /-Wpadded/d
  44. /pedantic-ms-format/d
  45. /=/d'
  46. # Ensure that indexed warnings are accepted.
  47. set x `sed '/^@opindex W/{
  48. s/^@opindex /-/
  49. '"$remove_problematic_flags"'
  50. /-W[alp]$/d
  51. p
  52. }
  53. d' <"$invoke_texi"`
  54. shift
  55. : >$filebase.c
  56. $CC -c $filebase.c "$@" 2>&1 |
  57. grep -v 'command line option.*is valid for.*but not for' >$stderr
  58. if test -s $stderr; then
  59. echo "options listed in @opindex but not accepted by the compiler:" >&2
  60. cat $stderr >&2
  61. ret=1
  62. fi
  63. rm -f $filebase.c $stderr
  64. # Check documentation of warning options.
  65. for lang in c c++ objc obj-c++; do
  66. case $lang in
  67. c) ext=c; langmatch='[^-]C[^+].*only' ;;
  68. c++) ext=C; langmatch='[^-]C++.*only' ;;
  69. objc) ext=m; langmatch='Objective-C[^+].*only' ;;
  70. obj-c++) ext=M; langmatch='Objective-C++.*only' ;;
  71. esac
  72. file=$filebase.$ext
  73. : >$file
  74. $CC -c $file 2>$stderr
  75. if grep 'not installed on this system' $stderr >/dev/null ||
  76. grep 'installation problem, cannot exec' $stderr >/dev/null ||
  77. grep 'error trying to exec' $stderr >/dev/null
  78. then
  79. echo "$progname: $CC is not configured for language $lang, skipping checks" >&2
  80. rm -f $file $filebase.o $filebase.obj $stderr
  81. continue
  82. fi
  83. # Verify good warning flags.
  84. set x `sed '
  85. t a
  86. :a
  87. /^@item -W/{
  88. /'"$langmatch"'/b x
  89. / only)/d
  90. b x
  91. }
  92. d
  93. :x
  94. '"$remove_problematic_flags"'
  95. s/^@item //
  96. s/ .*//
  97. ' <"$invoke_texi"`
  98. shift
  99. $CC -c $file -O "$@" 2>$stderr
  100. if test -s $stderr; then
  101. echo failures: >&2
  102. cat $stderr >&2
  103. ret=1
  104. fi
  105. # Verify bad warning flags.
  106. set x `sed '
  107. t a
  108. :a
  109. /^@item -W/{
  110. / only)/!d
  111. /'"$langmatch"'/d
  112. b x
  113. }
  114. d
  115. :x
  116. '"$remove_problematic_flags"'
  117. s/^@item //
  118. s/ .*//
  119. ' <"$invoke_texi"`
  120. shift
  121. $CC -c $file -O "$@" 2>$stderr
  122. # cat $stderr >&2
  123. test $# = `grep 'command line option.*valid.*but not for' <$stderr | wc -l` || {
  124. for warning
  125. do
  126. grep "command line option.*$warning.*valid" <$stderr >&2 ||
  127. echo "valid for $lang but not annotated as such: $warning"
  128. done
  129. ret=1
  130. }
  131. rm -f $file $filebase.o $filebase.obj $stderr
  132. done
  133. remove_problematic_help_flags='
  134. /^W$/d
  135. /^W[alp]$/d
  136. /^Werror-implicit-function-declaration$/d
  137. /^Wsynth$/d
  138. /-$/d
  139. /=/d'
  140. help_flags=`
  141. $CC --help -v 2>/dev/null | tr ' ' '\012' |
  142. sed -n '
  143. b a
  144. :a
  145. s/^-\(W[^<,]*\).*/\1/
  146. t x
  147. d
  148. :x
  149. '"$remove_problematic_help_flags"'
  150. p' | sort -u`
  151. : >$filebase.c
  152. for flag in $help_flags; do
  153. $CC -c $filebase.c -$flag 2>/dev/null || {
  154. echo "warning -$flag not supported" >&2
  155. ret=1
  156. }
  157. grep "@item.*$flag" $gcc_docdir/../*/*.texi >/dev/null || {
  158. # For @item, we are satisfied with either -Wfoo or -Wno-foo.
  159. inverted_flag=`echo "$flag" | sed '
  160. s/^Wno-/W/
  161. t
  162. s/^W/Wno-/'`
  163. grep "@item.*$inverted_flag" $gcc_docdir/../*/*.texi >/dev/null || {
  164. echo "warning -$flag not documented in $gcc_docdir/../*/*.texi" >&2
  165. ret=1
  166. }
  167. }
  168. done
  169. rm -f $filebase.c $filebase.o
  170. exit $ret