[PATCH, DOC] PR 30330: index both -Wfoo and -Wno-foo

Ralf Wildenhues Ralf.Wildenhues@gmx.de
Wed Feb 13 19:56:00 GMT 2008


* Gerald Pfeifer wrote on Sun, Feb 10, 2008 at 11:35:42PM CET:
> On Sat, 9 Feb 2008, Ralf Wildenhues wrote:
> > (My application for write access is still pending, so I guess my
> > question is: ok to install once that is through and even if tree is
> > still in stage 3?)
> 
> The various release branch rules explicitly only highlight documentation 
> as something not falling under the stringent rules, but my understanding 
> is that this is mostly a matter of pragmatism to keep the list short and
> contrib and maintainer-scripts (both of which are not used to actually
> build the compiler) do not fall under these strict rules.

Good.  So, OK to apply the patch below?

> > +  echo "$0: error: cannot read \`$invoke_texi'" >&2
> 
> Please use \' or \" for both sides; TeX-style quotes are something we
> try not to use for regular output to users these days.

Fixed.

> Note that this will also look a bit funny if if someone only invokes
> the script without any parameters, so perhaps guard for that special
> case?

Thanks, fixed as well.

> The nice thing is that the script also works with FreeBSD 6.1 /bin/sh;

Hey, writing portable shell scripts is one of my pastimes. ;-)

> just the following output puzzles me a bit:
> 
>   gcc: check_warning_flags_file63576.M: Objective-C++ compiler not 
>   installed on this system
>   valid for obj-c++ but not annotated as such: -Wno-format-zero-length
[...]
>   valid for obj-c++ but not annotated as such: -Wpointer-sign
> 
> What does this indicate?

That you did not enable the Objective-C++ language.  This version should
output better a warning in this case, and drop the bogus ones.  (Yes, it
also outputs the same message for some installation errors, but this
script isn't intended to check an installtion, only documentation.)

For good measure, I also added the @opindex test.

Cheers, and thanks for the review,
Ralf

contrib/ChangeLog:
2008-02-13  Ralf Wildenhues  <Ralf.Wildenhues@gmx.de>

	* check_warning_flags.sh: New file.

diff --git a/contrib/check_warning_flags.sh b/contrib/check_warning_flags.sh
new file mode 100755
index 0000000..95640f7
--- /dev/null
+++ b/contrib/check_warning_flags.sh
@@ -0,0 +1,136 @@
+#! /bin/sh
+#
+# Check that the warning flags documented in invoke.texi match up
+# with what the compiler accepts.
+#
+# Copyright (C) 2008 Free Software Foundation, Inc.
+# Written by Ralf Wildenhues <Ralf.Wildenhues@gmx.de>.
+#
+# This script is Free Software, and it can be copied, distributed and
+# modified as defined in the GNU General Public License.  A copy of
+# its license can be downloaded from http://www.gnu.org/copyleft/gpl.html
+#
+# Call this script as
+#    check_warning_flags.sh path/to/invoke.texi
+# with CC set to the compiler to be tested.
+# The script scribbles in the current directory.
+
+progname=`echo "$0" | sed 's,.*/,,'`
+usage ()
+{
+  echo "usage: $progname path/to/invoke.texi"
+  echo "set \$CC to the compiler to be checked"
+  exit 1
+}
+
+ret=0
+LC_ALL=C
+export LC_ALL
+: ${CC=gcc}
+test $# = 1 || usage
+invoke_texi=$1
+test -r "$invoke_texi" || {
+  echo "$progname: error: cannot read '$invoke_texi'" >&2
+  usage
+}
+filebase=check_warning_flags_file$$
+stderr=check_warning_flags_stderr$$
+
+remove_problematic_flags='
+  /-Wlarger-than-/d
+  /-W[alp],/d
+  /-Werror/d
+  /-Wpadded/d
+  /=/d'
+
+# Ensure that indexed warnings are accepted.
+set x `sed '/^@opindex W/{
+  s/^@opindex /-/
+  '"$remove_problematic_flags"'
+  /-W[alp]$/d
+  p
+}
+d' <"$invoke_texi"`
+shift
+: >$filebase.c
+$CC -c $filebase.c "$@" 2>&1 |
+  grep -v 'command line option.*is valid for.*but not for' >$stderr
+if test -s $stderr; then
+  echo "options listed in @opindex but not accepted by the compiler:" >&2
+  cat $stderr >&2
+  ret=1
+fi
+rm -f $filebase.c $stderr
+
+# Check documentation of warning options.
+for lang in c c++ objc obj-c++; do
+  case $lang in
+  c)       ext=c; langmatch='[^-]C[^+].*only' ;;
+  c++)     ext=C; langmatch='[^-]C++.*only' ;;
+  objc)    ext=m; langmatch='Objective-C[^+].*only' ;;
+  obj-c++) ext=M; langmatch='Objective-C++.*only' ;;
+  esac
+  file=$filebase.$ext
+  : >$file
+  $CC -c $file 2>$stderr
+  if grep 'not installed on this system' $stderr >/dev/null ||
+    grep 'installation problem, cannot exec' $stderr >/dev/null ||
+    grep 'error trying to exec' $stderr >/dev/null
+  then
+    echo "$progname: $CC is not configured for language $lang, skipping checks" >&2
+    rm -f $file $filebase.o $filebase.obj $stderr
+    continue
+  fi
+
+  # Verify good warning flags.
+  set x `sed '
+    t a
+    :a
+    /^@item -W/{
+      /'"$langmatch"'/b x
+      / only)/d
+      b x
+    }
+    d
+    :x
+    '"$remove_problematic_flags"'
+    s/^@item //
+    s/ .*//
+    ' <"$invoke_texi"`
+  shift
+  $CC -c $file -O "$@" 2>$stderr
+  if test -s $stderr; then
+    echo failures:  >&2
+    cat $stderr >&2
+    ret=1
+  fi
+
+  # Verify bad warning flags.
+  set x `sed '
+    t a
+    :a
+    /^@item -W/{
+      / only)/!d
+      /'"$langmatch"'/d
+      b x
+    }
+    d
+    :x
+    '"$remove_problematic_flags"'
+    s/^@item //
+    s/ .*//
+    ' <"$invoke_texi"`
+  shift
+  $CC -c $file -O "$@" 2>$stderr
+  # cat $stderr >&2
+  test $# = `grep 'command line option.*valid.*but not for' <$stderr | wc -l` || {
+    for warning
+    do
+      grep "command line option.*$warning.*valid" <$stderr >&2 ||
+	echo "valid for $lang but not annotated as such: $warning"
+    done
+    ret=1
+  }
+  rm -f $file $filebase.o $filebase.obj $stderr
+done
+exit $ret



More information about the Gcc-patches mailing list